##Load Packages and Data library(Deducer) library(psych) library(catspec) library(gdata) library(Hmisc) library(xtable) library(psych) x <- read.csv(file = "/Users/erinschneider/Desktop/IDFDataFiles/China/CHINA_MEDS_DATA.csv", sep = ",") splice3 <- function (x, y, w, colnames.splice = NULL, pc = TRUE) { z <- data.frame(matrix(rbind(x, y, w), nrow(x))) rownames(z) <- rownames(x) if (ncol(z) / 2 == length(colnames.splice)) colnames.splice <- rep(colnames.splice, 2) colnames(z) <- colnames.splice z } splice <- function (x, y, colnames.splice=NULL, pc=TRUE) { z<-data.frame(matrix(rbind(x,y),nrow(x))) rownames(z)<-rownames(x) if (pc) colnames.splice <- matrix(rbind(colnames(x), rep("%", ncol(x))), nrow=1) if (is.null(colnames.splice)) { colnames.splice <- matrix(rbind(paste(deparse(substitute(x)), ".", colnames(x), sep=""), paste(deparse(substitute(y)), ".", colnames(y), sep="")), nrow=1) } colnames(z) <- colnames.splice z } ci <- function(x){ mean <- mean(x, na.rm=TRUE) s <- sd(x, na.rm=TRUE) n <- length(na.omit(x)) error <- qnorm(0.975)*s/sqrt(n) left <- mean-error right <- mean+error conf <- c(left, right) conf } yesno <- function (x) { if (is.na(x)) { y <- NA } else { if (x == "Yes") { y <- 1 } else { y <- 0 } y } } y <- x[x$case == "Diabetes" | x$case == "No Diabetes",] y$case <- factor(y$case, levels = c("Diabetes", "No Diabetes")) dm <- y[y$case == "Diabetes",] nd <- y[y$case == "No Diabetes",] ##Mean Meds Costs by Med Type ##Met c <- y[y$cost.yr.use & y$case == "Diabetes" & y$public == "Yes",] met1 <- c$cost.yr.use aggregate.table(met1, c$met, c$location, FUN=mean, na.rm=TRUE) d <- y[y$cost.yr.use & y$case == "Diabetes" & y$private == "Yes",] met1 <- d$cost.yr.use aggregate.table(met1, d$met, d$location, FUN=mean, na.rm=TRUE) ##SU c <- y[y$cost.yr.use & y$case == "Diabetes" & y$public == "Yes",] price <- c$cost.yr.use aggregate.table(price, c$su, c$location, FUN=mean, na.rm=TRUE) d <- y[y$cost.yr.use & y$case == "Diabetes" & y$private == "Yes",] price <- d$cost.yr.use aggregate.table(price, d$su, d$location, FUN=mean, na.rm=TRUE) ##Acar c <- y[y$cost.yr.use & y$case == "Diabetes" & y$public == "Yes",] price <- c$cost.yr.use aggregate.table(price, c$acar, c$location, FUN=mean, na.rm=TRUE) d <- y[y$cost.yr.use & y$case == "Diabetes" & y$private == "Yes",] price <- d$cost.yr.use aggregate.table(price, d$acar, d$location, FUN=mean, na.rm=TRUE) ##Insulin c <- y[y$cost.yr.use & y$case == "Diabetes" & y$public == "Yes",] price <- c$cost.yr.use aggregate.table(price, c$ins, c$location, FUN=mean, na.rm=TRUE) d <- y[y$cost.yr.use & y$case == "Diabetes" & y$private == "Yes",] price <- d$cost.yr.use aggregate.table(price, d$ins, d$location, FUN=mean, na.rm=TRUE) ##Gllow c <- y[y$cost.yr.use & y$case == "Diabetes" & y$public == "Yes",] price <- c$cost.yr.use aggregate.table(price, c$other.gllow, c$location, FUN=mean, na.rm=TRUE) d <- y[y$cost.yr.use & y$case == "Diabetes" & y$private == "Yes",] price <- d$cost.yr.use aggregate.table(price, d$other.gllow, d$location, FUN=mean, na.rm=TRUE) ##Lipid a <- y[y$cost.yr.use & y$case == "No Diabetes" & y$public == "Yes",] price <- a$cost.yr.use aggregate.table(price, a$lipid, a$location, FUN=mean, na.rm=TRUE) b <- y[y$cost.yr.use & y$case == "No Diabetes" & y$private == "Yes",] price <- b$cost.yr.use aggregate.table(price, b$lipid, b$location, FUN=mean, na.rm=TRUE) c <- y[y$cost.yr.use & y$case == "Diabetes" & y$public == "Yes",] price <- c$cost.yr.use aggregate.table(price, c$lipid, c$location, FUN=mean, na.rm=TRUE) d <- y[y$cost.yr.use & y$case == "Diabetes" & y$private == "Yes",] price <- d$cost.yr.use aggregate.table(price, d$lipid, d$location, FUN=mean, na.rm=TRUE) ##BP a <- y[y$cost.yr.use & y$case == "No Diabetes" & y$public == "Yes",] price <- a$cost.yr.use aggregate.table(price, a$bp, a$location, FUN=mean, na.rm=TRUE) b <- y[y$cost.yr.use & y$case == "No Diabetes" & y$private == "Yes",] price <- b$cost.yr.use aggregate.table(price, b$bp, b$location, FUN=mean, na.rm=TRUE) c <- y[y$cost.yr.use & y$case == "Diabetes" & y$public == "Yes",] price <- c$cost.yr.use aggregate.table(price, c$bp, c$location, FUN=mean, na.rm=TRUE) d <- y[y$cost.yr.use & y$case == "Diabetes" & y$private == "Yes",] price <- d$cost.yr.use aggregate.table(price, d$bp, d$location, FUN=mean, na.rm=TRUE) ##Anticoags a <- y[y$cost.yr.use & y$case == "No Diabetes" & y$public == "Yes",] price <- a$cost.yr.use aggregate.table(price, a$anticoag, a$location, FUN=mean, na.rm=TRUE) b <- y[y$cost.yr.use & y$case == "No Diabetes" & y$private == "Yes",] price <- b$cost.yr.use aggregate.table(price, b$anticoag, b$location, FUN=mean, na.rm=TRUE) c <- y[y$cost.yr.use & y$case == "Diabetes" & y$public == "Yes",] price <- c$cost.yr.use aggregate.table(price, c$anticoag, c$location, FUN=mean, na.rm=TRUE) d <- y[y$cost.yr.use & y$case == "Diabetes" & y$private == "Yes",] price <- d$cost.yr.use aggregate.table(price, d$anticoag, d$location, FUN=mean, na.rm=TRUE) ##NonDM a <- y[y$cost.yr.use & y$case == "No Diabetes" & y$public == "Yes",] price <- a$cost.yr.use aggregate.table(price, a$nondm, a$location, FUN=mean, na.rm=TRUE) b <- y[y$cost.yr.use & y$case == "No Diabetes" & y$private == "Yes",] price <- b$cost.yr.use aggregate.table(price, b$nondm, b$location, FUN=mean, na.rm=TRUE) c <- y[y$cost.yr.use & y$case == "Diabetes" & y$public == "Yes",] price <- c$cost.yr.use aggregate.table(price, c$nondm, c$location, FUN=mean, na.rm=TRUE) d <- y[y$cost.yr.use & y$case == "Diabetes" & y$private == "Yes",] price <- d$cost.yr.use aggregate.table(price, d$nondm, d$location, FUN=mean, na.rm=TRUE)