############################## # # Script: assignment01x.R # Graphics for the # answers to the first # homework assignment # ############################## # Read in the data ht <- read.csv("http://courses.kvasaheim.com/pols6123/data/studentHeight.csv") names(ht) summary(ht) attach(ht) ##### # Problem 1 png("boxplot.png", width=4,height=3,units="in",res=600) par(mar=c(4,4,1,1)+0.1) par(cex=0.8,cex.lab=0.8,cex.axis=0.8) boxplot(height~sex, las=1, xlab="Gender\n", ylab="Height (in)", col=c("#ffaaaa","#aaaaff")) dev.off() t.test(height~sex, alternative="greater") ##### # Problem 2 # Check assumption of Normality using boxplots boxplot(height~sex, las=1, xlab="Gender", ylab="Height (in)") # or using histograms png("histograms.png", width=4,height=3,units="in",res=600) par(cex=0.8,cex.lab=0.8,cex.axis=0.8) par(mar=c(0,4,1,1)+0.1) par(fig=c(0,1,0.55,1)) hist(height[sex=="Male"], main="",xlab="",xlim=c(120,220),xaxt="n", las=1, ylim=c(0,4),col="#aaaaff") text(130,3,"Males", cex=0.8) par(mar=c(4,4,0,1)+0.1) par(fig=c(0,1,0,0.55),new=TRUE) hist(height[sex=="Female"], main="",xlab="Height (in)\n",xlim=c(120,220), las=1, ylim=c(0,4),col="#ffaaaa") text(130,3,"Females", cex=0.8) dev.off() # or using the Shapiro-Wilk test shapiro.test(height[sex=="Male"]) shapiro.test(height[sex=="Female"]) # in each of these, Normality seems reasonable t.test(height~sex, alternative="greater")