################## long format mydataframe <- read.delim ("http://www.robin-beaumont.co.uk/virtualclassroom/book2data/ttest_2independent_long1.txt", header=TRUE) ### local copy ignore: # mydataframe <- read.delim("D:\\web_sites_mine\\HIcourseweb # new\\book2data\\ttest_2independent_long1.txt", header=TRUE) ### names(mydataframe) length(mydataframe) t.test (values ~ ind, var.equal=TRUE, data=mydataframe, conf.level=.95) #from R Commander: numSummary(mydataframe[,"values"], groups=mydataframe$ind, statistics=c("mean", "sd", "IQR", "quantiles"), quantiles=c(0,.25,.5,.75,1)) plotMeans(mydataframe$values, mydataframe$ind, error.bars="conf.int", level=0.95) # above manually anotated to cnage y axis scale to match boxplot; plotMeans(mydataframe$values, mydataframe$ind, error.bars="conf.int", level=0.95, ylim=c(0,600)) # R Commander uses the Boxplot function in the car package # this provides the id.method option. Boxplot(values~ind, data=mydataframe, id.method="y") # Manual changes: Boxplot(values~ind, data=mydataframe, id.method="y")# show extremes + case numbers Boxplot(values~ind, data=mydataframe, id.method="n")# show extremes NO case numbers Boxplot(values~ind, data=mydataframe, id.method="identify") #interactive identification ################## wide format mydataframe <- read.delim ("http://www.robin-beaumont.co.uk/virtualclassroom/book2data/ttest_2independent_wide1.txt", header=TRUE) ### local copy ignore: # mydataframe <- read.delim("D:\\web_sites_mine\\HIcourseweb # new\\book2data\\ttest_2independent_wide1.txt", header=TRUE) #### names(mydataframe) t.test (mydataframe$treatment, mydataframe$control, var.equal=TRUE, conf.level=.95) # effect size effectsize <- (mean(mydataframe$treatment) - mean(mydataframe$control))/sapply(stack(mydataframe), sd) effectsize ################ long again mydataframe2 <- read.delim("http://www.robin-beaumont.co.uk/virtualclassroom/book2data/ttest_2independent_long1.txt", header=TRUE) ### local copy ignore # mydataframe2 <- read.delim("D:\\web_sites_mine\\HIcourseweb # new\\book2data\\ttest_2independent_long1.txt", header=TRUE) ### names(mydataframe2) t.test (values ~ ind, var.equal=TRUE, data=mydataframe2) # Base package functions: # stack and unstack # stack wide -> long # can't cope with factors # unstack long -> wide # can't cope with factors mydataframe2 <- read.delim("D:\\web_sites_mine\\HIcourseweb new\\book2data\\ttest_2independent_long1.txt", header=TRUE) unstacked_data <- unstack(mydataframe2) # works str(unstacked_data) unstacked_data # wide format stacked_data <- stack(unstacked_data) # wide format str(stacked_data) stacked_data # long format str(mydataframe) mydataframe_fixed <- data.frame(value=mydataframe[,1], ind=as.numeric(mydataframe[,2])) str(mydataframe_fixed) stacked_data <- stack(mydataframe_fixed) # works str(stacked_data) # effect size - wide data effectsize <- (mean(mydataframe$treatment) - mean(mydataframe$control))/ sapply(stack(mydataframe), sd) # using this stops error message when # trying to produce sd for factor effectsize # effect size - long data str(mydataframe2) #'data.frame': 200 obs. of 2 variables: # $ values: num 453 400 445 424 119 ... # $ ind : Factor w/ 2 levels "control","treatment": 2 2 2 2 2 2 2 2 2 2 ... effectsize <- (mean(mydataframe2$values[mydataframe2$"ind" =="treatment"]) - mean(mydataframe2$values[mydataframe2$"ind" =="control"]))/sd(mydataframe2$values) effectsize