I realized this text is very dense and hard to read so I separated
things out better. Here's a link to the script I made:
http://dl.dropbox.com/u/1852742/fakeemrdata.R
Thanks to Dennis Murphy for some tips on cleaning up the data creation
in the beginning. The changes are reflected here.
And here it is pasted:
#I created some fake EMR data with a function that generates random
data that
#is in roughly a normal distribution. I can set the approx. mean and
sd
#as well. The final data frame is called "recordsdata". I ran tests
and made
#plots and tables that will be useful. Note that if you were typing
these
#commands in R itself you don't have to use the print command.
#create emr records data
emr=data.frame(records=factor(rep('emr',50)),
cost=rnorm(50,mean=250,sd=30),
numlabs=rnorm(50,mean=3,sd=1))
#create paper records data
paper=data.frame(records=factor(rep('paper',50)),
cost=rnorm(50,mean=325,sd=30),
numlabs=rnorm(50,mean=6,sd=1))
#create mixed data
mixed=data.frame(records=factor(rep('mixed',50)),
cost=rnorm(50,mean=290,sd=15),
numlabs=rnorm(50,mean=4.6,sd=.5))
#combine the three into one data frame and round the labs to integers
recordsdata=rbind(emr,paper)
recordsdata=rbind(recordsdata,mixed)
recordsdata$numlabs=round(recordsdata$numlabs)
print(recordsdata)
#write the data frame to csv
#write.csv(recordsdata,file='foobar.csv')
#show summary by type of records
print(tapply(recordsdata$cost,recordsdata$records,summary))
print(tapply(recordsdata$cost,recordsdata$records,sd))
#two-way table of records means
recordstable=table(recordsdata$records,recordsdata
$cost>mean(recordsdata$cost))
print(recordstable)
#summary of table including chi-square
print(summary(recordstable))
#linear model of records data
lmfit=lm(formula=recordsdata$cost~recordsdata$records)
print(summary(lmfit))
#anova of lmfit
print(anova(lmfit))
#pair-wise t test of records data
print(pairwise.t.test(recordsdata$cost,recordsdata
$records,
pool.sd=FALSE))
#some useful plots
boxplot(recordsdata$cost~recordsdata$records,ylab='Cost (Dollars)')
qqnorm(emr$cost)
hist(emr$cost)
#pretty ggplot plots
library(ggplot2)
qplot(recordsdata$cost)
#another
ggplot(recordsdata,aes(cost,fill=records))+geom_density(alpha=0.2)+
scale_x_continuous('Cost (Dollars)',limits=c(150,425))
#another
ggplot(recordsdata,aes(cost,fill=records))+geom_histogram()
#plots for the linear model
plot(lmfit)