hmgt 400 F
sink("C:/UMUC/FinalExam.txt") ################## ################## # Q#1 ################## ################## # 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/HMGTFINALEXAM1.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 hosp$PerCapBed <- hosp$hospital_beds/hosp$total_population hosp$benefit <- (hosp$total_hosp_revenue-hosp$total_hosp_cost) year_cat <- group_by(hosp, year) # Adding a new variable names (hosp) # 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), intres=mean(interns_and_residents, na.rm=T), system=mean(system_member, na.rm=T), cost=mean(total_hosp_cost, na.rm=T), revenue=mean(total_hosp_revenue, na.rm=T), benf=mean(benefit, 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), percap=mean(PerCapBed, na.rm=T), poppvt=mean(pct_poverty, na.rm=T), malepvt=mean(pct_male_under_poverty, na.rm=T), femalepvt=mean(pct_female_under_poverty, na.rm=T), hhinc=mean(median_hh_income, 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), intres=sd(interns_and_residents, na.rm=T), system=sd(system_member, na.rm=T), cost=sd(total_hosp_cost, na.rm=T), revenue=sd(total_hosp_revenue, na.rm=T), benf=sd(benefit, 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), percap=sd(PerCapBed, na.rm=T), poppvt=sd(pct_poverty, na.rm=T), malepvt=sd(pct_male_under_poverty, na.rm=T), femalepvt=sd(pct_female_under_poverty, na.rm=T), hhinc=sd(median_hh_income, na.rm=T)) # write.table(q1m, file = "C:/UMUC/q1m.csv", sep = ",", quote = FALSE, row.names = F) # write.table(q1s, file = "C:/UMUC/q1s.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$interns_and_residents, hosp_12$interns_and_residents, paired = F) # 9-5 t.test(hosp_11$system_member, hosp_12$system_member, paired = F) # 9-6 t.test(hosp_11$total_hosp_cost, hosp_12$total_hosp_cost, paired = F) # 9-7 t.test(hosp_11$total_hosp_revenue, hosp_12$total_hosp_revenue, paired = F) # 9-8 t.test(hosp_11$benefit, hosp_12$benefit, paired = F) # 9-9 t.test(hosp_11$total_hospital_medicare_days, hosp_12$total_hospital_medicare_days, paired = F) # 9-10 t.test(hosp_11$total_hospital_medicaid_days, hosp_12$total_hospital_medicaid_days, paired = F) # 9-11 t.test(hosp_11$total_hospital_discharges, hosp_12$total_hospital_discharges, paired = F) # 9-12 t.test(hosp_11$total_hospital_medicare_discharg, hosp_12$total_hospital_medicare_discharg, paired = F) # 9-13 t.test(hosp_11$total_hospital_medicaid_discharg, hosp_12$total_hospital_medicaid_discharg, paired = F) # 9-14 t.test(hosp_11$PerCapBed, hosp_12$PerCapBed, paired = F) # 9-15 t.test(hosp_11$pct_poverty, hosp_12$pct_poverty, paired = F) # 9-16 t.test(hosp_11$pct_male_under_poverty, hosp_12$pct_male_under_poverty, paired = F) # 9-17 t.test(hosp_11$pct_female_under_poverty, hosp_12$pct_female_under_poverty, paired = F) # 9-18 t.test(hosp_11$median_hh_income, hosp_12$median_hh_income, paired = F) # Step 10: See N for 2011 and 2012 # 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$interns_and_residents) summary(mytable) # 10-5 mytable <- table(hosp_11$system_member) summary(mytable) # 10-6 mytable <- table(hosp_11$total_hosp_cost) summary(mytable) # 10-7 mytable <- table(hosp_11$total_hosp_revenue) summary(mytable) # 10-8 mytable <- table(hosp_11$benefit) summary(mytable) # 10-9 mytable <- table(hosp_11$total_hospital_medicare_days) summary(mytable) # 10-10 mytable <- table(hosp_11$total_hospital_medicaid_days) summary(mytable) # 10-11 mytable <- table(hosp_11$total_hospital_discharges) summary(mytable) # 10-12 mytable <- table(hosp_11$total_hospital_medicare_discharg) summary(mytable) # 10-13 mytable <- table(hosp_11$total_hospital_medicaid_discharg) summary(mytable) # 10-14 mytable <- table(hosp_11$PerCapBed) summary(mytable) # 10-15 mytable <- table(hosp_11$pct_poverty) summary(mytable) # 10-16 mytable <- table(hosp_11$pct_male_under_poverty) summary(mytable) # 10-17 mytable <- table(hosp_11$pct_female_under_poverty) summary(mytable) # 10-18 mytable <- table(hosp_11$median_hh_income) 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$interns_and_residents) summary(mytable) # 10-5 mytable <- table(hosp_12$system_member) summary(mytable) # 10-6 mytable <- table(hosp_12$total_hosp_cost) summary(mytable) # 10-7 mytable <- table(hosp_12$total_hosp_revenue) summary(mytable) # 10-8 mytable <- table(hosp_12$benefit) summary(mytable) # 10-9 mytable <- table(hosp_12$total_hospital_medicare_days) summary(mytable) # 10-10 mytable <- table(hosp_12$total_hospital_medicaid_days) summary(mytable) # 10-11 mytable <- table(hosp_12$total_hospital_discharges) summary(mytable) # 10-12 mytable <- table(hosp_12$total_hospital_medicare_discharg) summary(mytable) # 10-13 mytable <- table(hosp_12$total_hospital_medicaid_discharg) summary(mytable) # 10-14 mytable <- table(hosp_12$PerCapBed) summary(mytable) # 10-15 mytable <- table(hosp_12$pct_poverty) summary(mytable) # 10-16 mytable <- table(hosp_12$pct_male_under_poverty) summary(mytable) # 10-17 mytable <- table(hosp_12$pct_female_under_poverty) summary(mytable) # 10-18 mytable <- table(hosp_12$median_hh_income) summary(mytable) ################ # Q2 ################ # Step 7b ## Ownership ## 0) non-for-profit ## 1) for profit ## 2) Public ## 3) Other table(hosp$own) own1 <- group_by(hosp, own) fp <- subset(hosp, hosp$own==1) nfp <- subset(hosp, hosp$own==0) summarize (own1, 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), intres=mean(interns_and_residents, na.rm=T), system=mean(system_member, na.rm=T), cost=mean(total_hosp_cost, na.rm=T), revenue=mean(total_hosp_revenue, na.rm=T), benf=mean(benefit, 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), percap=mean(PerCapBed, na.rm=T), poppvt=mean(pct_poverty, na.rm=T), malepvt=mean(pct_male_under_poverty, na.rm=T), femalepvt=mean(pct_female_under_poverty, na.rm=T), hhinc=mean(median_hh_income, na.rm=T)) # Step 7: See the SD summarize (own1, 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), intres=sd(interns_and_residents, na.rm=T), system=sd(system_member, na.rm=T), cost=sd(total_hosp_cost, na.rm=T), revenue=sd(total_hosp_revenue, na.rm=T), benf=sd(benefit, 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), percap=sd(PerCapBed, na.rm=T), poppvt=sd(pct_poverty, na.rm=T), malepvt=sd(pct_male_under_poverty, na.rm=T), femalepvt=sd(pct_female_under_poverty, na.rm=T), hhinc=sd(median_hh_income, na.rm=T)) # ttest # 8-1 t.test(fp$hospital_beds, nfp$hospital_beds, paired = F) # 8-2 t.test(fp$total_hospital_employees_on_payr, nfp$total_hospital_employees_on_payr, paired = F) # 8-3 t.test(fp$total_hospital_non_paid_workers, nfp$total_hospital_non_paid_workers, paired = F) # 8-4 t.test(fp$interns_and_residents, nfp$interns_and_residents, paired = F) # 8-5 t.test(fp$system_member, nfp$system_member, paired = F) # 8-6 t.test(fp$total_hosp_cost, nfp$total_hosp_cost, paired = F) # 8-7 t.test(fp$total_hosp_revenue, nfp$total_hosp_revenue, paired = F) # 8-8 t.test(fp$benefit, nfp$benefit, paired = F) # 8-9 t.test(fp$total_hospital_medicare_days, nfp$total_hospital_medicare_days, paired = F) # 8-10 t.test(fp$total_hospital_medicaid_days, nfp$total_hospital_medicaid_days, paired = F) # 8-11 t.test(fp$total_hospital_discharges, nfp$total_hospital_discharges, paired = F) # 8-12 t.test(fp$total_hospital_medicare_discharg, nfp$total_hospital_medicare_discharg, paired = F) # 8-13 t.test(fp$total_hospital_medicaid_discharg, nfp$total_hospital_medicaid_discharg, paired = F) # 8-14 t.test(fp$PerCapBed, nfp$PerCapBed, paired = F) # 8-15 t.test(fp$pct_poverty, nfp$pct_poverty, paired = F) # 8-16 t.test(fp$pct_male_under_poverty, nfp$pct_male_under_poverty, paired = F) # 8-17 t.test(fp$pct_female_under_poverty, nfp$pct_female_under_poverty, paired = F) # 8-18 t.test(fp$median_hh_income, nfp$median_hh_income, paired = F) # FP # 10-1 mytable <- table(fp$hospital_beds) summary(mytable) # 10-2 mytable <- table(fp$total_hospital_employees_on_payr) summary(mytable) # 10-3 mytable <- table(fp$total_hospital_non_paid_workers) summary(mytable) # 10-4 mytable <- table(fp$interns_and_residents) summary(mytable) # 10-5 mytable <- table(fp$system_member) summary(mytable) # 10-6 mytable <- table(fp$total_hosp_cost) summary(mytable) # 10-7 mytable <- table(fp$total_hosp_revenue) summary(mytable) # 10-8 mytable <- table(fp$benefit) summary(mytable) # 10-9 mytable <- table(fp$total_hospital_medicare_days) summary(mytable) # 10-10 mytable <- table(fp$total_hospital_medicaid_days) summary(mytable) # 10-11 mytable <- table(fp$total_hospital_discharges) summary(mytable) # 10-12 mytable <- table(fp$total_hospital_medicare_discharg) summary(mytable) # 10-13 mytable <- table(fp$total_hospital_medicaid_discharg) summary(mytable) # 10-14 mytable <- table(fp$PerCapBed) summary(mytable) # 10-15 mytable <- table(fp$pct_poverty) summary(mytable) # 10-16 mytable <- table(fp$pct_male_under_poverty) summary(mytable) # 10-17 mytable <- table(fp$pct_female_under_poverty) summary(mytable) # 10-18 mytable <- table(fp$median_hh_income) summary(mytable) # NFP # 10-1 mytable <- table(nfp$hospital_beds) summary(mytable) # 10-2 mytable <- table(nfp$total_hospital_employees_on_payr) summary(mytable) # 10-3 mytable <- table(nfp$total_hospital_non_paid_workers) summary(mytable) # 10-4 mytable <- table(nfp$interns_and_residents) summary(mytable) # 10-5 mytable <- table(nfp$system_member) summary(mytable) # 10-6 mytable <- table(nfp$total_hosp_cost) summary(mytable) # 10-7 mytable <- table(nfp$total_hosp_revenue) summary(mytable) # 10-8 mytable <- table(nfp$benefit) summary(mytable) # 10-9 mytable <- table(nfp$total_hospital_medicare_days) summary(mytable) # 10-10 mytable <- table(nfp$total_hospital_medicaid_days) summary(mytable) # 10-11 mytable <- table(nfp$total_hospital_discharges) summary(mytable) # 10-12 mytable <- table(nfp$total_hospital_medicare_discharg) summary(mytable) # 10-13 mytable <- table(nfp$total_hospital_medicaid_discharg) summary(mytable) # 10-14 mytable <- table(nfp$PerCapBed) summary(mytable) # 10-15 mytable <- table(nfp$pct_poverty) summary(mytable) # 10-16 mytable <- table(nfp$pct_male_under_poverty) summary(mytable) # 10-17 mytable <- table(nfp$pct_female_under_poverty) summary(mytable) # 10-18 mytable <- table(nfp$median_hh_income) summary(mytable) # 3) Use a box-plot and compare Hospital net benefit between for-profit and non-for-profit hospitals. boxplot (fp$benefit, nfp$benefit, unequal=T, main="Figure 1. Comparing number of beds in in FP and NFP hospitals",cex.main=1, xlab="Profit Status", ylab="# of Beds") # COST plot(fp$total_hosp_cost, unequal=T~ nfp$total_hosp_cost, unequal=T, pch = 1, cex =.5, col = "blue", main = "Figure 2. Hospital Benfit and Hospital Beds", cex.main =.8, xlab = "Cost-FP", ylab = "COst-NFP") # REVENUE plot(fp$total_hosp_revenue, unequal=T~ nfp$total_hosp_revenue, unequal=T, pch = 1, cex =.5, col = "blue", main = "Figure 3. Hospital Benfit and Hospital Beds", cex.main =.8, xlab = "Revenue-FP", ylab = "Revenue-NFP") plot (fp$total_hosp_cost, unequal=T~ nfp$total_hosp_cost, unequal=T, main="Figure 4. Comparing number of beds in in FP and NFP hospitals",cex.main=1, xlab="Profit Status", ylab="# of Beds") ################ # Question 3 : ############### hosp$medicare_discharge_ratio <- (hosp$total_hospital_medicare_discharg/hosp$total_hospital_discharges)*100 hosp$medicaid_discharge_ratio <- (hosp$total_hospital_medicaid_discharg/hosp$total_hospital_discharges)*100 # Note: In the video I explaind you need to use the herf_ins (for hospital herf index), so the codes already here # No need for any cahnges herf_ins1 <- group_by(hosp, herf_ins) # Note: 0=High Competevie # 1=Moderate Competevie # 2=low Competevie summarize (herf_ins1, 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), intres=mean(interns_and_residents, na.rm=T), system=mean(system_member, na.rm=T), cost=mean(total_hosp_cost, na.rm=T), revenue=mean(total_hosp_revenue, na.rm=T), benf=mean(benefit, 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(medicare_discharge_ratio, na.rm=T), mediciaddis=mean(medicaid_discharge_ratio, na.rm=T), percap=mean(PerCapBed, na.rm=T), hhinc=mean(median_hh_income, na.rm=T)) # Step 7: See the SD summarize (herf_ins1, 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), intres=sd(interns_and_residents, na.rm=T), system=sd(system_member, na.rm=T), cost=sd(total_hosp_cost, na.rm=T), revenue=sd(total_hosp_revenue, na.rm=T), benf=sd(benefit, 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(medicare_discharge_ratio, na.rm=T), mediciaddis=sd(medicaid_discharge_ratio, na.rm=T), percap=sd(PerCapBed, na.rm=T), hhinc=sd(median_hh_income, na.rm=T)) # write.table(q3m, file = "C:/UMUC/q3m.csv", sep = ",", quote = FALSE, row.names = F) # write.table(q3s, file = "C:/UMUC/q3s.csv", sep = ",", quote = FALSE, row.names = F) # To find the N use following commands # Step 8: Generate 3 dataset for a ttest. high_compt <- subset(hosp, hosp$herf_ins==0) moderate_compt <- subset(hosp, hosp$herf_ins==1) low_compt <- subset(hosp, hosp$herf_ins==2) # Step 9 # N for high_compt ############ # 9-1 mytable <- table(high_compt$hospital_beds) summary(mytable) # 9-2 mytable <- table(high_compt$total_hospital_employees_on_payr) summary(mytable) # 9-3 mytable <- table(high_compt$total_hospital_non_paid_workers) summary(mytable) # 9-4 mytable <- table(high_compt$interns_and_residents) summary(mytable) # 9-5 mytable <- table(high_compt$system_member) summary(mytable) # 9-6 mytable <- table(high_compt$total_hosp_cost) summary(mytable) # 9-7 mytable <- table(high_compt$total_hosp_revenue) summary(mytable) # 9-8 mytable <- table(high_compt$benefit) summary(mytable) # 9-9 mytable <- table(high_compt$total_hospital_medicare_days) summary(mytable) # 9-10 mytable <- table(high_compt$total_hospital_medicaid_days) summary(mytable) # 9-11 mytable <- table(high_compt$total_hospital_discharges) summary(mytable) # 9-12 mytable <- table(high_compt$medicare_discharge_ratio) summary(mytable) # 9-13 mytable <- table(high_compt$medicaid_discharge_ratio) summary(mytable) # 9-14 mytable <- table(high_compt$PerCapBed) summary(mytable) # 9-15 mytable <- table(high_compt$median_hh_income) summary(mytable) # N for Moderate Competetive # 10-1 mytable <- table(moderate_compt$hospital_beds) summary(mytable) # 10-2 mytable <- table(moderate_compt$total_hospital_employees_on_payr) summary(mytable) # 10-3 mytable <- table(moderate_compt$total_hospital_non_paid_workers) summary(mytable) # 10-4 mytable <- table(moderate_compt$interns_and_residents) summary(mytable) # 10-5 mytable <- table(moderate_compt$system_member) summary(mytable) # 10-6 mytable <- table(moderate_compt$total_hosp_cost) summary(mytable) # 10-7 mytable <- table(moderate_compt$total_hosp_revenue) summary(mytable) # 10-8 mytable <- table(moderate_compt$benefit) summary(mytable) # 10-9 mytable <- table(moderate_compt$total_hospital_medicare_days) summary(mytable) # 10-9 mytable <- table(moderate_compt$total_hospital_medicaid_days) summary(mytable) # 10-11 mytable <- table(moderate_compt$total_hospital_discharges) summary(mytable) # 10-12 mytable <- table(moderate_compt $medicare_discharge_ratio) summary(mytable) # 10-13 mytable <- table(moderate_compt $medicaid_discharge_ratio) summary(mytable) # 10-14 mytable <- table(moderate_compt $PerCapBed) summary(mytable) # 10-15 mytable <- table(moderate_compt $median_hh_income) summary(mytable) # N for Low compatetive # 11-1 mytable <- table(low_compt$hospital_beds) summary(mytable) # 11-2 mytable <- table(low_compt$total_hospital_employees_on_payr) summary(mytable) # 11-3 mytable <- table(low_compt$total_hospital_non_paid_workers) summary(mytable) # 11-4 mytable <- table(low_compt$interns_and_residents) summary(mytable) # 11-5 mytable <- table(low_compt$system_member) summary(mytable) # 11-6 mytable <- table(low_compt$total_hosp_cost) summary(mytable) # 11-7 mytable <- table(low_compt$total_hosp_revenue) summary(mytable) # 11-8 mytable <- table(low_compt$benefit) summary(mytable) # 11-9 mytable <- table(low_compt$total_hospital_medicare_days) summary(mytable) # 11-9 mytable <- table(low_compt$total_hospital_medicaid_days) summary(mytable) # 11-11 mytable <- table(low_compt$total_hospital_discharges) summary(mytable) # 11-12 mytable <- table(low_compt$medicare_discharge_ratio) summary(mytable) # 11-13 mytable <- table(low_compt$medicaid_discharge_ratio) summary(mytable) # 11-14 mytable <- table(low_compt$PerCapBed) summary(mytable) # 11-15 mytable <- table(low_compt$median_hh_income) summary(mytable) herf_ins1 <- factor(hosp$herf_ins, levels = c(0, 1, 2)) # 12-1 t1 =lm(hospital_beds ~ herf_ins1, data=hosp) anova(t1) # 12-2 t2 =lm(total_hospital_employees_on_payr ~ herf_ins1, data=hosp) anova(t2) # 12-3 t3 =lm(total_hospital_non_paid_workers ~ herf_ins1, data=hosp) anova(t3) # 12-4 t4 =lm(interns_and_residents ~ herf_ins1, data=hosp) anova(t4) # 12-5 t5 =lm(system_member ~ herf_ins1, data=hosp) anova(t5) # 12-6 t6 =lm(total_hosp_cost ~ herf_ins1, data=hosp) anova(t6) # 12-7 t7 =lm(total_hosp_revenue ~ herf_ins1, data=hosp) anova(t7) # 12-8 t8 =lm(benefit ~ herf_ins1, data=hosp) anova(t8) # 12-9 t9 =lm(total_hospital_medicare_days ~ herf_ins1, data=hosp) anova(t9) # 12-10 t10 =lm(total_hospital_medicaid_days ~ herf_ins1, data=hosp) anova(t10) # 12-11 t11 =lm(total_hospital_discharges ~ herf_ins1, data=hosp) anova(t11) # 12-12 t12 =lm(medicare_discharge_ratio ~ herf_ins1, data=hosp) anova(t12) # 12-13 t13 =lm(medicaid_discharge_ratio ~ herf_ins1, data=hosp) anova(t13) # 12-14 t14 =lm(PerCapBed~ herf_ins1, data=hosp) anova(t14) # 12-15 t15 =lm(median_hh_income ~ herf_ins1, data=hosp) anova(t15) high_compt <- subset(hosp, hosp$herf_ins==0) moderate_compt <- subset(hosp, hosp$herf_ins==1) low_compt <- subset(hosp, hosp$herf_ins==2) boxplot (high_compt$total_hosp_cost, moderate_compt$total_hosp_cost, unequal=T, main="Figure 5a. Comparing Hospitals Costs in High vs. Moderat Competetive Markets",cex.main=1, xlab="Profit Status", ylab="Total hosp cost") boxplot (moderate_compt$total_hosp_cost, low_compt$total_hosp_cost, unequal=T, main="Figure 5b. Comparing Hospitals Costs in Moderate vs. Low Competetive Markets",cex.main=1, xlab="Profit Status", ylab="Total hosp cost") boxplot (high_compt$total_hosp_revenue, moderate_compt$total_hosp_revenue, unequal=T, main="Figure 5c. Comparing Hospitals Revenues in High vs. Moderat Competetive Markets",cex.main=1, xlab="Profit Status", ylab="Total hosp revenues") boxplot (moderate_compt$total_hosp_revenue, low_compt$total_hosp_revenue, unequal=T, main="Figure 5d. Comparing Hospitals Revenues in in Moderate vs. Low Competetive Markets",cex.main=1, xlab="Profit Status", ylab="Total hosp revenues") # Question 3: 2.4. q3 <- lm(benefit ~ hospital_beds + herf_index + total_hospital_medicare_discharg + total_hospital_medicaid_discharg + system_member + interns_and_residents, data=hosp) summary(q3) ############# # Question 4 ############# own1 <- factor(hosp$own, levels = c(0, 1, 2, 3)) ## 0) non-for-profit ## 1) for profit ## 2) Public ## 3) Other # M1 model1 <- lm(benefit ~ hospital_beds + own1, data=hosp) summary(model1) # M2 model2 <- lm(benefit ~ hospital_beds + own1 + system_member, data=hosp) summary(model2) # M3 model3 <- lm(total_hosp_revenue ~ hospital_beds + own1 + system_member + medicare_discharge_ratio + medicaid_discharge_ratio, data=hosp) summary(model3) ############# # Question 5 ############# # Model 1 model1 <- glm(system_member ~ own1 + hospital_beds,family=binomial(link='logit'),data=hosp) summary(model1) # Model 2 model2 <- glm(system_member ~ own1 + hospital_beds + total_hosp_revenue,family=binomial(link='logit'),data=hosp) summary(model2) # Model 3 model3 <- glm(system_member ~ own1 + hospital_beds + total_hosp_revenue + medicare_discharge_ratio + medicaid_discharge_ratio,family=binomial(link='logit'),data=hosp) summary(model3) sink() # Thank you, Dr. Zare, FinalExamHMGT400-2-28-2020 # updated: 2/27/2021