EXERCISE 4 HMGT 400

BYSTANDER
HMGT400-E4-Codes.R

################## # Exercise #4 ################## ################## sink("C:/UMUC/week5exercise.txt") # install.packages('dplyr') library(dplyr) # Step 2: Read your data # Pl change the location of file hosp <- read.csv("C:/UMUC/HMGT400HOSPITAL.csv", header=T, sep = ',') #Step 3: See the variables' names names (hosp) #Step 4: Generate new variables hosp$benefit <- (hosp$total_hosp_revenue-hosp$total_hosp_cost) 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 # Step 5; Mean selected variable summarize (hosp, bed=mean(hospital_beds, na.rm=T), member=mean(system_member, na.rm=T), cost=mean(total_hosp_cost, na.rm=T), revenue=mean(log_hosp_revenue, na.rm=T), benefit=mean(benefit, na.rm=T), medicare_ratio=mean(medicare_discharge_ratio, na.rm=T), medicaid_ratio=mean(medicaid_discharge_ratio, na.rm=T)) mean(hosp$hospital_beds) mean(hosp$system_member) mean(hosp$total_hosp_cost) mean(hosp$log_hosp_revenue) mean(hosp$benefit) mean(hosp$medicare_discharge_ratio) mean(hosp$medicaid_discharge_ratio) sd(hosp$hospital_beds) sd(hosp$system_member) sd(hosp$total_hosp_cost) sd(hosp$log_hosp_revenue) sd(hosp$benefit) sd(hosp$medicare_discharge_ratio) sd(hosp$medicaid_discharge_ratio) # Step 6; SD selected variable summarize (hosp, bed=sd(hospital_beds, na.rm=T), member=sd(system_member, na.rm=T), cost=sd(total_hosp_cost, na.rm=T), revenue=sd(log_hosp_revenue, na.rm=T), benefit=sd(benefit, na.rm=T), medicare_ratio=sd(medicare_discharge_ratio, na.rm=T), medicaid_ratio=sd(medicaid_discharge_ratio, na.rm=T)) # Step 7; N for categorical variable # Step 7a ## Bed Size ##1) <50 ##2) 51-150 ##3) 151-250 ##4) 251-350 ##5) 351-450 ##6) 451-550 ##7) 551-650 ##8) >651 table(hosp$bedsize_cat) # Step 7b ## Ownership ## 0) non-for-profit ## 1) for profit ## 2) Public ## 3) Other table(hosp$own) # Cost mytable <- table(hosp$total_hosp_cost) summary(mytable) # Revenue mytable <- table(hosp$total_hosp_revenue) summary(mytable) # system_member mytable <- table(hosp$system_member) summary(mytable) # benefit mytable <- table(hosp$benefit) summary(mytable) # total_hospital_medicare_discharg mytable <- table(hosp$total_hospital_medicare_discharg) summary(mytable) # total_hospital_medicaid_discharg mytable <- table(hosp$total_hospital_medicaid_discharg) summary(mytable) # Step 8: Generate new variables hosp$benefit <- (hosp$total_hosp_revenue-hosp$total_hosp_cost) hosp$medicare_discharge_ratio <- (hosp$total_hospital_medicare_discharg/hosp$total_hospital_discharges)*100 hosp$medicaid_discharge_ratio <- (hosp$medicaid_discharge_ratio/hosp$total_hospital_discharges)*100 # Step 9: Generate Factor variables own1 <- factor(hosp$own, levels = c(0, 1, 2, 3)) bed_cat1 <- factor(hosp$bedsize_cat, levels = c(1, 2, 3, 4, 5, 6, 7, 8)) # Step 10: run regression models # 1st Model: ## 0) non-for-profit ## 1) for profit ## 2) Public ## 3) Other # Model 1a: Using bed as a continuous variable Benefit=function(beds, ownership) y=B0+B1beds+B2FP+B3Pbl+B4Ot+e model1a <- lm(benefit ~ hospital_beds + own1, data=hosp) summary(model1a) # Model 1b: Using bed as a categorical variable model1b <- lm(benefit ~ bed_cat1 + own1, data=hosp) summary(model1b) # Model 2: model2 <- lm(benefit ~ hospital_beds + own1 + system_member, data=hosp) summary(model2) # Model 3: model3 <- lm(total_hosp_revenue ~ hospital_beds + own1 + system_member + medicare_discharge_ratio + medicaid_discharge_ratio , data=hosp) summary(model3) # You may like to look at the plot to have better understaning. plot(hosp$benefit , hosp$hospital_beds, pch = 1, cex =.5, col = "blue", main = "Figure 1. Hospital Revenues and Hospital Beds", cex.main =.8, xlab = "Hospital Revenue ($)", ylab = "Hospital Beds(#)") abline (hosp$benefit , hosp$hospital_beds) hosp_sub <- subset(hosp, hosp$benefit>0 & hosp$benefit<200000000) plot(hosp_sub$benefit , hosp_sub$hospital_beds, pch = 1, cex =.5, col = "blue", main = "Figure 2. Hospital Benfit and Hospital Beds", cex.main =.8, xlab = "Hospital Revenue ($)", ylab = "Hospital Beds(#)") abline (hosp_sub$benefit , hosp_sub$hospital_beds) # Thank you, # Dr. Zare sink()