HMGT 400 6382 Research and Data Analysis in Healthcare (2222)

profiletech88
HMGT400-E1-Codes.R

################## ################## # Exercise #1 ################## ################## # This week you can work with the DPLYR packages this package help you to get your results with only a few lines codes sink("C:/UMUC/week1exercise.txt") # Step 1: Install package dplyr & read it # install.packages('dplyr') library(dplyr) # Step 2: Read your data # Pl change the location of file, please see the following video to learn about the location of file in your computer. hosp <- read.csv("C:/UMUC/HMGT400HOSPITAL.csv", header=T, sep = ',') # if you are working with MAC the above line should be: hosp <- read.csv("~/DOCUMNETS/UMUC/HMGT400HOSPITAL.csv", header=T, sep = ',') #Step 3: See the variables' names names (hosp) #You need to make sure you have the following variable in the dataset ##1 hospital_beds; Hospital beds ##2 total_hospital_employees_on_payr;Number of paid Employee ##3 total_hospital_non_paid_workers; Number of non-paid Employee ##4 total_hosp_cost; Total hospital cost ##5 log_hosp_revenue; Total hospital revenues ##6 total_hospital_medicare_days; Available Medicare days ##7 total_hospital_medicaid_days; Available Medicaid days ##8 total_hospital_discharges; Total Hospital Discharge ##9 total_hospital_medicare_discharg; Medicare discharge ##10 total_hospital_medicaid_discharg; Medicaid discharge # step 4: see number of obs. for teaching and non-teaching hospitals # This command shows that how many observations are available for 2011 and 2012 table(hosp$year) # Step 5: group the variable YEAR by using the group_by command year_cat <- group_by(hosp, year) # Step 6: See the means summarize (year_cat, bed=mean(hospital_beds, na.rm=T), payer=mean(total_hospital_employees_on_payr, na.rm=T), nopayer=mean(total_hospital_non_paid_workers, na.rm=T), cost=mean(total_hosp_cost, na.rm=T), revenue=mean(total_hosp_revenue, na.rm=T), medicare=mean(total_hospital_medicare_days, na.rm=T), mediciad=mean(total_hospital_medicaid_days, na.rm=T), totdis=mean(total_hospital_discharges, na.rm=T), mediciaredis=mean(total_hospital_medicare_discharg, na.rm=T), mediciaddis=mean(total_hospital_medicaid_discharg, na.rm=T)) # Step 7: See the SD summarize (year_cat, bed=sd(hospital_beds, na.rm=T), payer=sd(total_hospital_employees_on_payr, na.rm=T), nopayer=sd(total_hospital_non_paid_workers, na.rm=T), cost=sd(total_hosp_cost, na.rm=T), revenue=sd(total_hosp_revenue, na.rm=T), medicare=sd(total_hospital_medicare_days, na.rm=T), mediciad=sd(total_hospital_medicaid_days, na.rm=T), totdis=sd(total_hospital_discharges, na.rm=T), mediciaredis=sd(total_hospital_medicare_discharg, na.rm=T), mediciaddis=sd(total_hospital_medicaid_discharg, na.rm=T)) # write.table(tme1, file = "C:/UMUC/t1me1.csv", sep = ",", quote = FALSE, row.names = F) # write.table(tse1, file = "C:/UMUC/t2se2.csv", sep = ",", quote = FALSE, row.names = F) # Step 8: Generate 2 dataset for a ttest. hosp_11 <- subset(hosp, hosp$year==2011) hosp_12 <- subset(hosp, hosp$year==2012) # Step 9: See the results of ttest # 9-1 t.test(hosp_11$hospital_beds, hosp_12$hospital_beds, paired = F) # 9-2 t.test(hosp_11$total_hospital_employees_on_payr, hosp_12$total_hospital_employees_on_payr, paired = F) # 9-3 t.test(hosp_11$total_hospital_non_paid_workers, hosp_12$total_hospital_non_paid_workers, paired = F) # 9-4 t.test(hosp_11$total_hosp_cost, hosp_12$total_hosp_cost, paired = F) # 9-5 t.test(hosp_11$total_hosp_revenue, hosp_12$total_hosp_revenue, paired = F) # 9-6 t.test(hosp_11$total_hospital_medicare_days, hosp_12$total_hospital_medicare_days, paired = F) # 9-7 t.test(hosp_11$total_hospital_medicaid_days, hosp_12$total_hospital_medicaid_days, paired = F) # 9-8 t.test(hosp_11$total_hospital_discharges, hosp_12$total_hospital_discharges, paired = F) # 9-9 t.test(hosp_11$total_hospital_medicare_discharg, hosp_12$total_hospital_medicare_discharg, paired = F) # 9-10 t.test(hosp_11$total_hospital_medicaid_discharg, hosp_12$total_hospital_medicaid_discharg, paired = F) # Step 10: Generate 2 dataset for a ttest. # N for 2011 ############ # 10-1 mytable <- table(hosp_11$hospital_beds) summary(mytable) # 10-2 mytable <- table(hosp_11$total_hospital_employees_on_payr) summary(mytable) # 10-3 mytable <- table(hosp_11$total_hospital_non_paid_workers) summary(mytable) # 10-4 mytable <- table(hosp_11$total_hosp_cost) summary(mytable) # 10-5 mytable <- table(hosp_11$total_hosp_revenue) summary(mytable) # 10-6 mytable <- table(hosp_11$total_hospital_medicare_days) summary(mytable) # 10-7 mytable <- table(hosp_11$total_hospital_medicaid_days) summary(mytable) # 10-8 mytable <- table(hosp_11$total_hospital_discharges) summary(mytable) # 10-9 mytable <- table(hosp_11$total_hospital_medicare_discharg) summary(mytable) # 10-10 mytable <- table(hosp_11$total_hospital_medicaid_discharg) summary(mytable) # N for 2012 ############ # 10-1 mytable <- table(hosp_12$hospital_beds) summary(mytable) # 10-2 mytable <- table(hosp_12$total_hospital_employees_on_payr) summary(mytable) # 10-3 mytable <- table(hosp_12$total_hospital_non_paid_workers) summary(mytable) # 10-4 mytable <- table(hosp_12$total_hosp_cost) summary(mytable) # 10-5 mytable <- table(hosp_12$total_hosp_revenue) summary(mytable) # 10-6 mytable <- table(hosp_12$total_hospital_medicare_days) summary(mytable) # 10-7 mytable <- table(hosp_12$total_hospital_medicaid_days) summary(mytable) # 10-8 mytable <- table(hosp_12$total_hospital_discharges) summary(mytable) # 10-9 mytable <- table(hosp_12$total_hospital_medicare_discharg) summary(mytable) # 10-10 mytable <- table(hosp_12$total_hospital_medicaid_discharg) summary(mytable) #11 To see the boc plot you can use the codes from week 1 boxplot (hosp$hospital_beds~hosp$year, main="Figure 1. Comparing number of beds in in teaching & non-teaching hospitals",cex.main=1, xlab="Year", ylab="# of Beds") #12 Remove outliers and see the plot hosppic <- subset(hosp, hosp$hospital_beds<2000) boxplot (hosppic$hospital_beds~hosppic$year, main="Figure 2. Comparing number of beds in in teaching & non-teaching hospitals, if hospital bed<2000", cex.main=1, xlab="Year", ylab="# of Beds") sink() # Thank you # Dr. Zare HMGT400