##### Script for Slides b3 ##### ### Preamble source("http://rfs.kvasaheim.com/stat200.R") # Data speed = c(92.22, 94.14, 94.25, 94.10, 94.45, 94.48, 93.24) speed2 = c(speed, 1e11 ) ### Measures of Center mean( speed ) median( speed ) modal( speed ) mean( speed2 ) median( speed2 ) modal( speed2 ) ### Measures of Position mean( speed ) quantile(speed, 0.25) quantile(speed, 0.90) quantile(speed, c (0.0 , 0.2 , 0.4 , 0.6 , 0.8 , 1.0) ) quantile(speed, 0.75) - quantile (speed ,0.25) mean( speed2 ) quantile(speed2, 0.25) quantile(speed2, 0.90) quantile(speed2, c (0.0 , 0.2 , 0.4 , 0.6 , 0.8 , 1.0) ) quantile(speed2, 0.75) - quantile (speed2 ,0.25) ### The z-transform dt = read.csv("http://rfs.kvasaheim.com/data/crime.csv") attach(dt) ## Analysis # Absolute unemployment rates unemp1990[ state =="Oregon"] unemp2000[ state =="Oregon"] # Relative unemployment rates zscore( unemp1990 )[ state =="Oregon"] zscore( unemp2000 )[ state =="Oregon"] ##### Graphics # Set the size of the graphics for consistency ht = 300 wt = 900 ### Load Geography data file dt = read.csv("http://rfs.kvasaheim.com/data/geography.csv") quantile(dt$Score) ### Graphics # The Histogram png("b3-boxplot1.png", height=ht*1.4, width=wt) par(cex=1.2) par(bg="transparent") par(yaxs="i", xpd=NA, yaxt="n") par(family="serif",las=1) par(mar=c(3.5,0,0,0.5)) par(font.lab=2,cex.lab=1.1) boxplot(dt$Score, horizontal=TRUE, col="#eeeeff", frame=FALSE, xaxt="n", pars = list(boxwex = 1.25), ylim=c(0,6) ) title(xlab="Score on the Geography Quiz", line=2.0) mtext(side=1, at=0:6, text=0:6) segs = c(0,0,2,4,5) segments(segs,0.5, segs,0.6, lty=3) dev.off() ### Correlation work iq = c(106,100,86,101,99,103,97,113,112,110) tv = c(7,27,2,50,8,29,20,12,6,17) cor(iq,tv, method="pearson") cor(iq,tv, method="spearman") cor(iq,tv, method="kendall") png( "b3-iqtv.png", height=ht*1.4, width=wt) par(cex=1.2) par(bg="transparent") par( las=1, family="serif") par(cex.lab=1.2,font.lab=2,cex.axis=0.9) par( xaxs="i",yaxs="i") plot.new() plot.window( xlim=c(0,60), ylim=c(80,120)) axis(1); axis(2) title(xlab="Weekly Hours of TV Watching") title(ylab="Reported IQ Value") points(tv,iq, pch=21, bg="lightblue") dev.off() ### End of Script