## Plotting commands: Hospital<- read.table("c:/413/APPENC01.txt",header=F) Hospital<-edit(Hospital) summary(Hospital$V2) mean(Hospital$V2) sd(Hospital$V2) par(mfrow=c(1,2)) hist(Hospital$V2,breaks=seq(4,20,by=4),xlim=c(0,25),ylim=c(0,90),xlab="Length of Stay",main="SENIC Project") hist(Hospital$V4,xlab="Infection Risk", main="SENIC Project") par(new=T) plot(density(Hospital$V2), type="l", xlim=c(0,25),ylim=c(0,0.25),xlab="",ylab="",main="") dev.off() #note: V2=Length of Stay, V4=Infection Risk attach(Hospital) plot(V4,V2,ylab="Length of Stay", xlab="Infection Risk", main="SENIC Project") detach(Hospital) plot(V2~V4, data=Hospital,type="b") par(mfcol=c(1,2), pch=16) library() library(MASS) attach(Animals) plot(body,brain) plot(log(body),brain^0.1) detach(Animals) # Looking for correlations among variables # Often, it helps to look at it first. bears<-read.table("c:/413/beardata.txt",header=T) attach(bears) names(bears) pairs(bears, main="Scatterplot matrix of bear data") cor(bears) cor(AGE,LENGTH) #can do them separately... ## regression stuff #simple linear regression Bear <- lm(AGE~WEIGHT) summary(Bear) plot(WEIGHT,AGE,main="Regression of WEIGHT on AGE") abline(Bear) anova(Bear) detach(bears)