library(foreign) library(psych) library(ggplot2) library(plyr) library(forestplot) summarySE <- function(data=NULL, measurevar, groupvars=NULL, na.rm=FALSE, conf.interval=.95) { library(doBy) # New version of length which can handle NA's: if na.rm==T, don't count them length2 <- function (x, na.rm=FALSE) { if (na.rm) sum(!is.na(x)) else length(x) } # Collapse the data formula <- as.formula(paste(measurevar, paste(groupvars, collapse=" + "), sep=" ~ ")) datac <- summaryBy(formula, data=data, FUN=c(length2,mean,sd), na.rm=na.rm) # Rename columns names(datac)[ names(datac) == paste(measurevar, ".mean", sep="") ] <- measurevar names(datac)[ names(datac) == paste(measurevar, ".sd", sep="") ] <- "sd" names(datac)[ names(datac) == paste(measurevar, ".length2", sep="") ] <- "N" datac$se <- datac$sd / sqrt(datac$N) # Calculate standard error of the mean # Confidence interval multiplier for standard error # Calculate t-statistic for confidence interval: # e.g., if conf.interval is .95, use .975 (above/below), and use df=N-1 ciMult <- qt(conf.interval/2 + .5, datac$N-1) datac$ci <- datac$se * ciMult return(datac) } ## CARATIVE FACTORS vpr2 <- read.spss("questionnaire part 2a.sav.sav", to.data.frame=TRUE, use.value.labels = T) newTab <- data.frame(Location = vpr2[,2]) vpr2 <- read.spss("questionnaire part 2a.sav.sav", to.data.frame=TRUE, use.value.labels = F) vpr2 <- vpr2[,4:73] sets2 <- list(c(1:6), c(7:13), c(14:19), c(20:26), c(27:32), c(33:38), c(39:47), c(48:54), c(55:64), c(65:70)) for(s in sets2) newTab <- cbind(newTab,(apply(vpr2[,s], 1, mean))) # Add cumulative Caring component newTab <- cbind(newTab,(apply(newTab[,2:11], 1, mean))) nameStrs <- c("Humanism", "Hope", "Sensibility", "HelpingRelationship", "ExpresionOfEmotions", "ProblemSolving", "Teaching", "Environment", "Needs", "Spirituality", "Caring") names(newTab)[2:12] <- nameStrs # Linear transformation to [0..4] interval #newTab[,2:12] <- newTab[,2:12]-1 newTab$Location <- as.character(newTab$Location) ## ANOVA analysis pVals <- c() for(i in 2:12) { res <- summary(aov(newTab[,i]~newTab[,1], data=newTab)) p.val <- res[[1]][5][1,1] pVals <- c(pVals,p.val) } ## Summary res <- summarySE(data = newTab, measurevar = nameStrs[1], groupvars = "Location", na.rm = T) resTab <- data.frame(Location = res[,1], N = res[,2], Humanism = res[,3]) resTabLow <- data.frame(Location = res[,1], N = res[,2], Humanism = res[,3]-res[,6]) resTabHigh <- data.frame(Location = res[,1], N = res[,2], Humanism = res[,3]+res[,6]) for(name in nameStrs[2:11]) { res <- summarySE(data = newTab, measurevar = name, groupvars = "Location", na.rm = T) resTab <- cbind(resTab, res[,3]) resTabLow <- cbind(resTabLow, res[,3]-res[,6]) resTabHigh <- cbind(resTabHigh, res[,3]+res[,6]) } names(resTab)[3:13]<-names(resTabLow)[3:13]<-names(resTabHigh)[3:13]<-nameStrs resTab <- resTab[1:5,] resTabLow <- resTabLow[1:5,] resTabHigh <- resTabHigh[1:5,] resTab ## PATIENT SATISFACTION SURVEY vpr3 <- read.spss("Vprasalnik_pacienti.sav", to.data.frame=TRUE, use.value.labels = T) newTab2 <- data.frame(Location = vpr3[,2]) vpr3 <- read.spss("Vprasalnik_pacienti.sav", to.data.frame=TRUE, use.value.labels = F) newTab2$CareFromNurses <- apply(vpr3[,4:6], 1, mean, na.rm=TRUE) newTab2$CareFromDoctor <- apply(vpr3[,8:10], 1, mean, na.rm=TRUE) newTab2$HospitalEnvironment <- apply(vpr3[,11:12], 1, mean, na.rm=TRUE) newTab2$HospitalRating <- vpr3$V21 # Linear transformation to [0..4] interval newTab2[,2:4] <- ((newTab2[,2:4]-1)/3)*4 newTab2[,5] <- ((newTab2[,5]-1)/9)*4+1 newTab2$Location <- as.character(newTab2$Location) nameStrs2 <- c("CareFromNurses", "CareFromDoctor", "HospitalEnvironment", "HospitalRating") ## ANOVA res <- summary(aov(newTab2[,2]~newTab2[,1], data=newTab2)) p.val <- res[[1]][5][1,1] pVals <- c(p.val, pVals) names(pVals) <- c("Care From Nurses", nameStrs[1:11]) ## Summary res <- summarySE(data = newTab2, measurevar = nameStrs2[1], groupvars = "Location", na.rm = T) resTab2 <- data.frame(Location = res[,1], N2 = res[,2], CareFromNurses = res[,3]) resTab2Low <- data.frame(Location = res[,1], N2 = res[,2], CareFromNurses = res[,3]-res[,6]) resTab2High <- data.frame(Location = res[,1], N2 = res[,2], CareFromNurses = res[,3]+res[,6]) for(name in nameStrs2[2:4]) { res <- summarySE(data = newTab2, measurevar = name, groupvars = "Location", na.rm = T) resTab2 <- cbind(resTab2, res[,3]) resTab2Low <- cbind(resTab2Low, res[,3]-res[,6]) resTab2High <- cbind(resTab2High, res[,3]+res[,6]) } names(resTab2)[3:6]<-names(resTab2Low)[3:6]<-names(resTab2High)[3:6]<-nameStrs2 resTab2 resTab$Location <- as.character(resTab$Location) resTab2$Location <- as.character(resTab2$Location) resTabLow$Location <- as.character(resTabLow$Location) resTab2Low$Location <- as.character(resTab2Low$Location) resTabHigh$Location <- as.character(resTabHigh$Location) resTab2High$Location <- as.character(resTab2High$Location) tabNew <- merge(resTab2, resTab) tabNewLow <- merge(resTab2Low, resTabLow) tabNewHigh <- merge(resTab2High, resTabHigh) write.table(rbind(tabNew, tabNewLow, tabNewHigh), "Paper3_means.csv") names(tabNew) pdf("plotsPaper3_Nurses.pdf", width = 6, height = 3) seq <- c(18, 8:17) for (i in seq) { plot.new() idxs <- c(3,i) forestplot(as.character(tabNew$Location), #legend_args = fpLegend(pos = list(x=.10, y=0.90), gp=gpar(col="#CCCCCC", fill="#F9F9F9")), legend = c(names(tabNew)[idxs[1]], names(tabNew)[idxs[2]]), fn.ci_norm = c(fpDrawNormalCI, fpDrawCircleCI), boxsize = .10, # We set the box size to better visualize the type mean = tabNew[,c(idxs[1],idxs[2])], lower = tabNewLow[,c(idxs[1],idxs[2])], upper = tabNewHigh[,c(idxs[1],idxs[2])], col=fpColors(box=c("blue", "darkred")), zero = 3, clip =c(3, 5), xticks = c(3, 3.5, 4, 4.5, 5), xlab="Transformed Score") } dev.off() pdf("plotsPaper3_OverallPatientSatisfaction.pdf", width = 6, height = 3) seq <- c(18, 8:17) for (i in seq) { idxs <- c(6,i) plot.new() forestplot(as.character(tabNew$Location), #legend_args = fpLegend(pos = list(x=.10, y=0.90), gp=gpar(col="#CCCCCC", fill="#F9F9F9")), fn.ci_norm = c(fpDrawNormalCI, fpDrawCircleCI), boxsize = .10, # We set the box size to better visualize the type mean = tabNew[,c(idxs[1],idxs[2])], lower = tabNewLow[,c(idxs[1],idxs[2])], upper = tabNewHigh[,c(idxs[1],idxs[2])], col=fpColors(box=c("blue", "darkred")), zero = 3, legend = c(names(tabNew)[idxs[1]], names(tabNew)[idxs[2]]), clip =c(3, 5), xticks = c(3, 3.5, 4, 4.5, 5), xlab="Transformed Score") } dev.off() pdf("plotsPaper3_CareFromDoctors.pdf", width = 6, height = 3) seq <- c(18, 8:17) for (i in seq) { plot.new() idxs <- c(4,i) forestplot(as.character(tabNew$Location), #legend_args = fpLegend(pos = list(x=.10, y=0.90), gp=gpar(col="#CCCCCC", fill="#F9F9F9")), legend = c(names(tabNew)[idxs[1]], names(tabNew)[idxs[2]]), fn.ci_norm = c(fpDrawNormalCI, fpDrawCircleCI), boxsize = .10, # We set the box size to better visualize the type mean = tabNew[,c(idxs[1],idxs[2])], lower = tabNewLow[,c(idxs[1],idxs[2])], upper = tabNewHigh[,c(idxs[1],idxs[2])], col=fpColors(box=c("blue", "darkred")), zero = 3, clip =c(3, 5), xticks = c(3, 3.5, 4, 4.5, 5), xlab="Transformed Score") } dev.off() pdf("plotsPaper3_HospitalEnv.pdf", width = 6, height = 3) seq <- c(18, 8:17) for (i in seq) { plot.new() idxs <- c(5,i) forestplot(as.character(tabNew$Location), #legend_args = fpLegend(pos = list(x=.10, y=0.90), gp=gpar(col="#CCCCCC", fill="#F9F9F9")), legend = c(names(tabNew)[idxs[1]], names(tabNew)[idxs[2]]), fn.ci_norm = c(fpDrawNormalCI, fpDrawCircleCI), boxsize = .10, # We set the box size to better visualize the type mean = tabNew[,c(idxs[1],idxs[2])], lower = tabNewLow[,c(idxs[1],idxs[2])], upper = tabNewHigh[,c(idxs[1],idxs[2])], col=fpColors(box=c("blue", "darkred")), zero = 3, clip =c(3, 5), xticks = c(3, 3.5, 4, 4.5, 5), xlab="Transformed Score") } dev.off()