#--------------------------------------------------------------------------------------------------------- #R Code for Chapter 10 of: # #Field, A. P., Miles, J. N. V., & Field, Z. C. (2012). Discovering Statistics Using R: and Sex and Drugs and Rock 'N' Roll. #London Sage # #(c) 2011 Andy P. Field, Jeremy N. V. Miles & Zoe C. Field #----------------------------------------------------------------------------------------------------------- ######Install packages install.packages("granova") install.packages("car") install.packages("pastecs") install.packages("multcomp") install.packages("compute.es") install.packages("WRS", repos="http://R-Forge.R-project.org") #Initiate packages library(ggplot2) library(granova) library(car) library(pastecs) library(multcomp) library(compute.es) library(WRS) #--------Self Test---------- dummyData<-read.delim("Dummy.dat", header = TRUE) dummyData$dose<-factor(dummyData$dose, levels = c(1:3), labels = c("Placebo", "Low Dose", "High Dose")) dummy.model<-lm(libido~dummy1 + dummy2, data = dummyData) summary(dummy.model) #--------Viagra data---------- id<-(1:15) libido<-c(3,2,1,1,4,5,2,4,2,3,7,4,5,3,6) #dose<-c(rep(1,5),rep(2,5), rep(3,5)) #dose<-factor(dose, levels = c(1:3), labels = c("Placebo", "Low Dose", "High Dose")) dose<-gl(3,5, labels = c("Placebo", "Low Dose", "High Dose")) viagraData<-data.frame(dose, libido) #Graph line <- ggplot(viagraData, aes(dose, libido)) line + stat_summary(fun.y = mean, geom = "line", size = 1, aes(group=1), colour = "#FF6633") + stat_summary(fun.data = mean_cl_boot, geom = "errorbar", width = 0.2, size = 0.75, colour = "#990000") + stat_summary(fun.y = mean, geom = "point", size = 4, colour = "#990000") + stat_summary(fun.y = mean, geom = "point", size = 3, colour = "#FF6633") + labs(x = "Dose of Viagra", y = "Mean Libido") #Descriptives by(viagraData$libido, viagraData$dose, stat.desc) #Levene's test leveneTest(viagraData$libido, viagraData$dose, center = median) #levene.test(viagraData$libido, viagraData$dose) #ANOVA viagraModel<-aov(libido~dose, data = viagraData) #viagraModel<-lm(libido~dose, data = viagraData) summary(viagraModel) summary.lm(viagraModel) plot(viagraModel) # Welch Test oneway.test(libido~dose, data = viagraData) #THE ABOVE WE DID ON THURSDAY Novemeber 7th... #Your assignment with the EducLifeForANOVA.csv data # is to adopt all of the above code to analyzing # and producing the output (results and graphs and plots) done above. # Educ, Life, dummy1 and dummy2 are the variables. # ---- ---- ------ ------