#Read the Body Temperature data BodyTemp<-scan('https://www.math.mcgill.ca/dstephens/203/Data/BodyTemp.txt') BodyTemp #First histogram plot par(mar=c(4,4,2,1)) hist(BodyTemp,xlab='Temperature (C)',main='Histogram of Body Temperatures') box() #Second histogram plot par(mar=c(4,4,2,1)) hist(BodyTemp,xlab='Temperature (C)',main='Histogram of Body Temperatures') box() #Second histogram plot par(mar=c(4,4,2,1)) hist(BodyTemp,breaks=seq(35,39,by=0.5), xlab='Temperature (C)',main='Histogram of Body Temperatures') box() ########################################################################## #Second example: n=40 data points x<-c(0.4,2.8,0.8,1.4,6.4,1.3,1.8,0.1,0.0,1.6,1.2,1.4,0.4,1.5,3.9,2.0, 0.3,3.8,0.1,0.6,0.4,0.3,0.7,0.5,0.1,1.2,0.1,0.7,1.3,1.3,0.6,0.3, 0.2,1.6,1.6,1.1,0.6,2.1,0.4,0.0) y<-sort(x) y x.S<-min(x) x.L<-max(x) k<-8 l<-(x.L-x.S)/k l #Without a plot xv<-seq(x.S,x.L,by=l) table(cut(x,xv,right=FALSE,include.lowest=TRUE)) hist(x,breaks=xv,right=FALSE,include.lowest=TRUE,plot=FALSE)$counts hist(x,breaks=xv,plot=FALSE)$counts #Trying other options k<-8 l<-(x.L-x.S)/k xv<-seq(x.S,x.L,by=l);par(mar=c(4,3,1,0)) hist(x,breaks=xv,right=FALSE,include.lowest=TRUE,main='');box() k<-3 l<-(x.L-x.S)/k xv<-seq(x.S,x.L,by=l);par(mar=c(4,3,1,0)) hist(x,breaks=xv,right=FALSE,include.lowest=TRUE,main='');box() k<-30 l<-(x.L-x.S)/k xv<-seq(x.S,x.L,by=l);par(mar=c(4,4,1,0)) hist(x,breaks=xv,right=FALSE,include.lowest=TRUE,main='');box() #Relatve frequency k<-8;l<-(x.L-x.S)/k xv<-seq(x.S,x.L,by=l);par(mar=c(4,4,2,0)) lattice::histogram(x,breaks=xv, right=FALSE,include.lowest=TRUE, main='Relative Freq. (%)', col='gray') #Density k<-8;l<-(x.L-x.S)/k xv<-seq(x.S,x.L,by=l);par(mar=c(4,4,1,0)) hist(x,breaks=xv,right=FALSE,include.lowest=TRUE,main='',freq=FALSE);box() h1<-hist(x,breaks=xv,right=FALSE,include.lowest=TRUE,plot=FALSE) h1$density h1$counts/(l*sum(h1$counts))