##### Slidedeck e7 ##### Examples for ToI procedure ##### # Preamble source("https://rfs.kvasaheim.com/stat200.R") # Colors ito1 = "#E1EBEE" ito2 = "#00AAE4" ito3 = "#ffdddd" ito4 = "#990000" ito = c(ito1,ito2,ito3,ito4) ##### ##### ##### ##### ### Framing Example eyes = matrix( c(7,13, 28,52), ncol=2 ) rownames(eyes) = c("MNS Major","Not MNS Major") colnames(eyes) = c("Blue-Eyed","Not Blue-Eyed") ### mosaic plot par(bg="transparent") par(yaxs="i", xpd=NA, yaxt="n") par(family="serif",las=1) par(mar=c(0.5,0.5,1,0.5)) par(font.lab=2,cex.lab=1.1) mosaicplot(eyes, main="", col=c(ito2,ito1), cex.axis=1.5 ) # alternate par(bg="transparent") par(yaxs="i", xpd=NA, yaxt="n") par(family="serif",las=1) par(mar=c(0.5,0.5,1,0.5)) par(font.lab=2,cex.lab=1.1) mosaicplot(t(eyes), main="", col=c(ito4,ito3), cex.axis=1.5 ) # pdf graphic of chi-square df = 1 xx = seq(0,50, length=1e4) yy = dchisq(xx, df) png("e7-ex0c.png", height=ht,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.5,0,0.5)) par(font.lab=2,cex.lab=1.1) plot.new() plot.window( xlim=c(-0.01,6), ylim=c(0,0.75)) axis(1, at=0:7) title(xlab="Chi-squared", line=2.5) arrows( 3.5, 0.5, 1.3,0.2, length=0.1) text(3.5,0.5, pos=3, label="p-value") xs = c(xx,rev(xx)) ys = c(yy,rep(0,length(yy))) polygon(xs,ys, col=ito2) lines(xx,yy) ##### ##### ##### ##### ### Example 1: Hats hats = matrix( c(16,10,84,90), ncol=2 ) rownames(hats) = c("Female","Male") colnames(hats) = c("Hat","No Hat") # mosaic plot par(bg="transparent") par(yaxs="i", xpd=NA, yaxt="n") par(family="serif",las=1) par(mar=c(0.5,0.5,1,0.5)) par(font.lab=2,cex.lab=1.1) mosaicplot(hats, main="", col=c(ito2,ito1), cex.axis=1.5 ) # alternate par(bg="transparent") par(yaxs="i", xpd=NA, yaxt="n") par(family="serif",las=1) par(mar=c(0.5,0.5,1,0.5)) par(font.lab=2,cex.lab=1.1) mosaicplot(t(hats), main="", col=c(ito4,ito3), cex.axis=1.5 ) # pdf graphic df = 1 xx = seq(0,50, length=1e4) yy = dchisq(xx, df) TS = 1.5915 x2 = seq(TS,50, length=1e4) y2 = dchisq(x2, df) par(bg="transparent") par(yaxs="i", xpd=NA, yaxt="n") par(family="serif",las=1) par(mar=c(3.5,0.5,0,0.5)) par(font.lab=2,cex.lab=1.1) plot.new() plot.window( xlim=c(-0.01,6), ylim=c(0,0.75)) axis(1, at=0:7) title(xlab="Chi-squared", line=2.5) mtext(side=1, at=TS, text="TS") arrows( 3.5, 0.5, 2.3,0.1, length=0.1) text(3.5,0.5, pos=3, label="p-value") xs = c(xx,rev(xx)) ys = c(yy,rep(0,length(yy))) polygon(xs,ys, col=ito1) xs = c(x2,rev(x2)) ys = c(y2,rep(0,length(y2))) polygon(xs,ys, col=ito2) lines(xx,yy) ##### ##### ##### ##### ### Example 2: Grades grades = matrix( c(57,72,61,40,22, 49,68,55,32,20), nrow=2, byrow=TRUE ) rownames(grades) = c("Female","Male") colnames(grades) = c("A","B","C","D","F") # mosaic plot par(bg="transparent") par(yaxs="i", xpd=NA, yaxt="n") par(family="serif",las=1) par(mar=c(0.5,0.5,1,0.5)) par(font.lab=2,cex.lab=1.1) mosaicplot(grades, main="", col=c("green4","green2","yellow","red2","red4"), cex.axis=1.5 ) # alternate par(bg="transparent") par(yaxs="i", xpd=NA, yaxt="n") par(family="serif",las=1) par(mar=c(0.5,0.5,1,0.5)) par(font.lab=2,cex.lab=1.1) mosaicplot(t(grades), main="", col=c(ito4,ito3), cex.axis=1.5 ) # pdf graphic df = 4 xx = seq(0,50, length=1e4) yy = dchisq(xx, df) TS = 0.36674 x2 = seq(TS,50, length=1e4) y2 = dchisq(x2, df) par(bg="transparent") par(yaxs="i", xpd=NA, yaxt="n") par(family="serif",las=1) par(mar=c(3.5,0.5,0,0.5)) par(font.lab=2,cex.lab=1.1) plot.new() plot.window( xlim=c(-0.01,12), ylim=c(0,0.2)) axis(1, at=seq(0,12,2) ) title(xlab="Chi-squared", line=2.5) mtext(side=1, at=TS, text="TS") arrows( 6.5, 0.15, 5.3,0.1, length=0.1) text(6.5,0.15, pos=3, label="p-value") xs = c(xx,rev(xx)) ys = c(yy,rep(0,length(yy))) polygon(xs,ys, col=ito1) xs = c(x2,rev(x2)) ys = c(y2,rep(0,length(y2))) polygon(xs,ys, col=ito2) lines(xx,yy) ##### ##### ##### ##### ### Example 3: Fuffers of the World dt = read.csv("https://rfs.kvasaheim.com/data/fuf.csv") summary(dt) attach(dt) dataTable = table(govtType, fuffer) colnames(dataTable) = c("Not First User", "First User") # Adjust columns and rows dataTable = dataTable[c(3,1,2),2:1] # the hypothesis test chisq.test(dataTable) # mosaic plot par(bg="transparent") par(yaxs="i", xpd=NA, yaxt="n") par(family="serif",las=1) par(mar=c(0.5,0.5,1,0.5)) par(font.lab=2,cex.lab=1.1) mosaicplot(dataTable, main="", col=c("green4","red1"), cex.axis=1.5 ) # pdf graphic df = 3 xx = seq(0,500, length=1e4) yy = dchisq(xx, df) TS = 64.976 x2 = seq(TS,500, length=1e4) y2 = dchisq(x2, df) par(bg="transparent") par(yaxs="i", xpd=NA, yaxt="n") par(family="serif",las=1) par(mar=c(3.5,0.5,0,0.5)) par(font.lab=2,cex.lab=1.1) plot.new() plot.window( xlim=c(-0.01,12), ylim=c(0,0.25)) axis(1, at=seq(0,12,2) ) title(xlab="Chi-squared", line=2.5) mtext(side=1, at=TS, text="TS") arrows( 6.5, 0.15, 12.3,0.13, length=0.1) text(6.5,0.15, pos=3, label="p-value") xs = c(xx,rev(xx)) ys = c(yy,rep(0,length(yy))) polygon(xs,ys, col=ito1) xs = c(x2,rev(x2)) ys = c(y2,rep(0,length(y2))) polygon(xs,ys, col=ito2) lines(xx,yy) ### End of File