# R code for chapter 36 Graphical summaries of data: Aggregation # Book details: # http://www.amazon.co.uk/Health-Science-Statistics-using-Commander/dp/190790431X # load(url("http://www.robin-beaumont.co.uk/virtualclassroom/book2data/healthwagedata.rda")) # or # http://www.robin-beaumont.co.uk/virtualclassroom/book2data/healthwagedata.sav ls() # shows the rda file has a mydataframe dataframe summary(mydataframe) # now for summary for each level of eployment time: # R commander generated: library(abind, pos=14) library(e1071, pos=15) numSummary(mydataframe[,"hourwage"], groups=mydataframe$yrsscale, statistics=c("mean", "sd", "IQR", "quantiles"), quantiles=c(0,.25,.5,.75,1)) # end r commander generated # boxplots # show outlier case numbers Boxplot(hourwage~yrsscale, data=mydataframe, id.method="y") # do NOT show outlier case numbers Boxplot(hourwage~yrsscale, data=mydataframe, id.method="none") # plot of means, and standard errors: with(mydataframe, plotMeans(hourwage, yrsscale, error.bars="se")) ############ # if we have used txt input would needed to have re-odered factor levels ############ # instead of above strategy can aggregate data# first need to remove any NA'sav ## if you use the R commander menu option: ## Data->Active data set->Remove cases with missing data test1 <- na.omit(cleandataframe) cleandataframe <- na.omit(mydataframe) cleandataframe <- na.omit(mydataframe[,c("hourwage","yrsscale")]) ## if you remove the 'include all variables' tick box you only get the selected columns: cleandataframe <- na.omit(mydataframe[,c("hourwage","yrsscale")]) ########### now aggregate meanhourly_time <- aggregate(cleandataframe[,c("hourwage"), drop=FALSE], by=list(yrsscale=cleandataframe$yrsscale), FUN=mean) #### # now interactively change values for the categories from factor level labels to numbers ## not shown # now produce scatterplot scatterplot(yrsscale~hourwage, reg.line=FALSE, smooth=FALSE, spread=FALSE, id.method='mahal', id.n = 2, boxplots=FALSE, span=0.5, data=AggregatedData) #### end