library(lattice) # allows me to use sophisticaled graphing techniques x <- seq(from=-7,to=7,by=0.001) probdistn <- dnorm(x,mean = 0, sd = 1) plot(c(-7,7),c(0,1/2),type="n",xlab="Value of X",ylab="Density",main="Demonstration of variance") # sets up empty plot with axes sufficient for coming plots lines(x,probdistn,col=1) lines(x,dnorm(x,mean = 0, sd = 2),col=2) lines(x,dnorm(x,mean = 0, sd = 3),col=3) legend("topright",legend=c("sd = 1","sd = 2","sd = 3"),col=1:3,lty=1) probs <- cbind(1:3,pnorm(-1,mean=0,sd=1:3),pnorm(-3,mean=0,sd=1:3)) colnames(probs) <- c("Standard deviation","P(X < -1)","P(X < -3)") probs ######################################### Mice diets #################################### # NP: Mice in this group ate as much as they pleased of a nonpurified, standard diet for laboratory mice. # N/N85: This group was fed normally both before and after weaning. (The slash distinguishes the two periods.) After weaning, the ration was controlled at 85 kcal/wk. This, rather than NP, serves as the control group because caloric intake is held reasonably constant. # N/R50: This group was fed a normal diet before weaning and a reduced-calorie diet of 50 kcal/wk after weaning. # R/R50: This group was fed a reduced-calorie diet of 50 kcal/wk both before and after weaning. # N/R50 lopro: This group was fed a normal diet before weaning, a restricted diet of 50 kcal/wk after weaning, and had dietary protein content decreased with advancing age. # N/R40: This group was fed normally before weaning and was given a severely reduced diet of 40 kcal/wk after weaning. # NOTE: This data comes from R. Weindruch, R.L. Walford, S. Fligiel, and D. Guthrie, "The Retardation of Aging in Mice by Dietary Restriction: Longevity, Cancer, Immunity and Lifetime Energy Intake," Journal of Nutrition 116(4) (1986): 641-54. ##################################################################################################################### Data <- read.table("C:/Documents and Settings/steeleb/My Documents//Stat 341/MiceDiets.txt",header=FALSE) names(Data) <- c("Lifetime","Diet") head(Data) y <- Data[,"Lifetime"] X <- Data[,"Diet"] dotplot(y~X,ylab="Lifetime",xlab="Diet",col="black") bwplot(y~X,ylab="Lifetime",xlab="Diet") save.boxplot <- boxplot(y~X,ylab="Lifetime",xlab="Diet") save.boxplot$stats levels(Data$Diet) diets <- levels(Data$Diet) save.stats <- matrix(0,6,3) for (i in 1:6) { print(diets[i]) #print(mean(Data$Lifetime[Data$Diet==diets[i]])) #select lifetimes for each diet, compute and print mean data.i <- Data$Lifetime[Data$Diet==diets[i]] iqr.i <- quantile(data.i,p=.75) - quantile(data.i,p=.25) stats.i <- c(mean(data.i),sd(data.i),iqr.i) print(stats.i,digits=3) save.stats[i,] <- stats.i } plot(save.stats[,2],save.stats[,3],xlab="Sample standard deviation",ylab="Sample IQR",pch=16) identify(save.stats[,2],save.stats[,3],labels=diets,pos=4) save.boxplot <- boxplot(y~X,ylab="Lifetime",xlab="Diet")