1. คำสั่งสำหรับสร้างกราฟรูปที่ 6.1 mean=0; sd=1 lb=-3; ub=3 x <- seq(-3,3,length=100)*sd + mean hx <- dnorm(x,mean,sd) plot(x, hx,type="n", ylim=c(0,0.55),xlab="Standardized score(Z)",ylab="", axes=FALSE,cex.lab=1.7,cex.axis=1.7,xaxt="n") i <- x >= lb & x <= ub lines(x, hx,lwd=2) abline(v=c(-3,-2,-1,0,1,2,3),lty=2,lwd=2,col="grey") axis(side=1,cex.axis=1.7,lwd=2,lab=F) ll <- expression(paste(mu-3,sigma), paste(mu-2,sigma), paste(mu-1,sigma), paste(mu), paste(mu+1,sigma), paste(mu+2,sigma), paste(mu+3,sigma)) mtext(side=1,ll,at=c(-3:3),line=1,cex=1.7) lines(c(-1,1),c(0.45,0.45),lwd=2) lines(c(-2,2),c(0.5,0.5),lwd=2) lines(c(-3,3),c(0.55,0.55),lwd=2) polygon(c(-0.55,0.55,0.55,-0.55), c(0.43,0.43,0.47,0.47), col="white", border="white") polygon(c(-0.55,0.55,0.55,-0.55), c(0.48,0.48,0.52,0.52), col="white", border="white") polygon(c(-0.55,0.55,0.55,-0.55), c(0.53,0.53,0.57,0.57), col="white", border="white") text(0,0.45,"68.26%",cex=1.7) text(0,0.5,"95.45%",cex=1.7) text(0,0.55,"99.73%",cex=1.7) lines(c(-1,-1),c(0.43,0.47),lwd=2) lines(c(1,1),c(0.43,0.47),lwd=2) lines(c(-2,-2),c(0.48,0.52),lwd=2) lines(c(2,2),c(0.48,0.52),lwd=2) lines(c(-3,-3),c(0.53,0.57),lwd=2) lines(c(3,3),c(0.53,0.57),lwd=2) 2. คำสั่งในการสร้างกราฟรูปที่ 6.2 mean=0; sd=1 lb=-3; ub=3 x <- seq(-3,3,length=100)*sd + mean hx <- dnorm(x,mean,sd) par(mar=c(4.5,4.5,0,1),oma=c(0,0,0,0),las=1,mgp=c(3,1,0)) plot(x, hx,type="n", ylim=c(0,0.48),xlab="Standardized score (Z)", ylab="Probability density", axes=FALSE,cex.lab=1.7, cex.axis=1.7) i <- x >= lb & x <= ub lines(x, hx,lwd=2) axis(side=1,cex.axis=1.7,lwd=2) axis(side=2,las=1,cex.axis=1.7,lwd=2) 3. คำสั่งในการสร้างกราฟในตารางที่ 6.1 3.1 กราฟรูปที่ 1 mean=0; sd=1 lb=-3; ub=0 x <- seq(-3,3,length=100)*sd + mean hx <- dnorm(x,mean,sd) par(mar=c(6,1,0,1),oma=c(0,0,0,0),las=1,mgp=c(4,2,0)) plot(x, hx, type="n", ylab="", ylim=c(0,0.48), xlab="Z", axes=FALSE, cex.lab=3, cex.axis=3) i <- x >= lb & x <= ub lines(x, hx,lwd=3) axis(side=1,cex.axis=3,line=-1.1) polygon(c(lb,x[i],ub), c(0,hx[i],0), col="grey",lwd=3) area <- pnorm(ub, mean, sd) - pnorm(lb, mean, sd) 3.2 กราฟรูปที่ 2 mean=0; sd=1 lb=-3; ub=-1.96 x <- seq(-3,3,length=100)*sd + mean hx <- dnorm(x,mean,sd) par(mar=c(6,1,0,1),oma=c(0,0,0,0),las=1,mgp=c(4,2,0)) plot(x, hx,type="n", ylab="", ylim=c(0,0.48), xlab="Z", axes=FALSE, cex.lab=3, cex.axis=3) i <- x >= lb & x <= ub lines(x, hx,lwd=3) axis(side=1,cex.axis=3,line=-1.1) polygon(c(lb,x[i],ub), c(0,hx[i],0), col="grey",lwd=3) area <- pnorm(ub, mean, sd) - pnorm(lb, mean, sd) 3.3 กราฟรูปที่ 3 mean=0; sd=1 lb=-1.96; ub=1.96 x <- seq(-3,3,length=100)*sd + mean hx <- dnorm(x,mean,sd) par(mar=c(6,1,0,1),oma=c(0,0,0,0),las=1,mgp=c(4,2,0)) plot(x, hx,type="n", ylab="", ylim=c(0,0.48), xlab="Z", axes=FALSE, cex.lab=3, cex.axis=3) i <- x >= lb & x <= ub lines(x, hx,lwd=3) axis(side=1,cex.axis=3,line=-1.1,lwd=3) polygon(c(lb,x[i],ub), c(0,hx[i],0), col="grey",lwd=3) area <- pnorm(ub, mean, sd) - pnorm(lb, mean, sd) 3.4 กราฟรูปที่ 4 mean=0; sd=1 lb=1; ub=3 x <- seq(-3,3,length=100)*sd + mean hx <- dnorm(x,mean,sd) par(mar=c(6,1,0,1),oma=c(0,0,0,0),las=1,mgp=c(4,2,0)) plot(x, hx,type="n", ylab="", ylim=c(0,0.48), xlab="Z", axes=FALSE, cex.lab=3,cex.axis=3) i <- x >= lb & x <= ub lines(x, hx,lwd=3) axis(side=1,cex.axis=3,line=-1.1,lwd=3) polygon(c(lb,x[i],ub), c(0,hx[i],0), col="grey",lwd=3) area <- pnorm(ub, mean, sd) - pnorm(lb, mean, sd) 4 คำสั่งในการสร้างกราฟรูปที่ 6.3 mean=0; sd=1 lb=-3; ub=-1.96 x <- seq(-3,3,length=100)*sd + mean hx <- dnorm(x,mean,sd) par(mar=c(6,6,0,1),oma=c(0,0,0,0),las=1,mgp=c(4.5,1,0)) plot(x, hx,type="n", ylab="Normal probability density",ylim=c(0,0.48), xlab="Z",yaxt="n",xaxt="n",cex.lab=2,cex.axis=2,frame=F,lwd=2,axes=F) i <- x >= lb & x <= ub lines(x, hx,lwd=3,ylim=c(0,0.48)) axis(side=1,cex.axis=2,ylim=c(-0.02,0.48),line=-1.1,at=c(-3,-1,0,1,2,3)) axis(side=2,las=1,cex.axis=2,lwd=2) polygon(c(lb,x[i],ub), c(0,hx[i],0), col="grey",lwd=3,ylim=c(0,0.48)) area <- pnorm(ub, mean, sd) - pnorm(lb, mean, sd) mtext(side=1,adj=0.018,"pnorm(-1.96)",line=-9,cex=2) arrows(-1.96,0.12,-1.96,0.06,lwd=2) mtext(side=1,"=0.025",cex=2,line=-7,adj=0.016) arrows(-2.8,0.09,-2.2,0.005,lwd=2) mtext(side=1,adj=0,"qnorm(0.025)",line=2.5,cex=2) arrows(-1.96,-0.1,-1.96,0.0,lwd=2) mtext(side=1,line=4.5,"= -1.96",cex=2,adj=0) lb=1.96;ub=3 i <- x >= lb & x <= ub polygon(c(lb,x[i],ub), c(0,hx[i],0), col="white",lwd=3) lines(c(-2,2),c(0,0),lwd=3) arrows(2.8,0.09,2.2,0.005,lwd=2) mtext(side=1,"0.025",cex=2,line=-7,adj=1) mtext(side=1,line=-7,"0.95",adj=0.5,cex=2) 5. คำสั่งในการสร้างกราฟรูปที่ 6.4 windows(7,6) x <- seq(-3, 3, length=100) par(oma=c(0,0,0,0),mar=c(4,6,1,1),mgp=c(4,1,0)) plot(x,dnorm(x,0,1),type="l",ylab="Probability density", xlab="", las=1, cex=2, cex.axis=2,cex.lab=2,lwd=2,frame=F,axes=F) axis(side=1,cex.axis=2,ylim=c(0,0.48),line=-1.1) axis(side=2,las=1,cex.axis=2,lwd=2) lines(c(-3,3),c(0.005,0.005),lwd=2) lines(x,dt(x,1),lty=2,lwd=2) lines(x,dt(x,3),lty=3,col="red",lwd=2) lines(x,dt(x,30),col="grey40",lwd=2) legend("topright",inset=0.005,c("normal","df=30","df=3","df=1"),lwd=2, lty=c(1,1,6,3,2),col=c("black","grey40","red"),cex=1.5) mtext(side=1,"t",adj=0.5,cex=2,line=2) x<- seq(from=-4,to=12,0.01) plot(x,dt(x,10),type="n",ylim=c(0,.5)) points(x,dt(x,10),type="l") points(x,dt(x,10,ncp=2),type="l",lty=5) points(x,dt(x,10,ncp=4),type="l",lty=3) 6. คำสั่งในการสร้างกราฟรูปที่ 6.5 lb=-3; ub=-2.228 x <- seq(-3,3,length=2000) hx <- dt(x,10) par(mar=c(6,6,0,1),oma=c(0,0,0,0),las=1,mgp=c(4.5,1,0)) plot(x, hx,type="n", ylab="t probability density",ylim=c(0,0.48), xlab="Z",yaxt="n",xaxt="n",cex.lab=2,cex.axis=2,frame=F,lwd=2,axes=F) i <- x >= lb & x <= ub lines(x, hx,lwd=3,ylim=c(0,0.48)) axis(side=1,cex.axis=2,ylim=c(0,0.48),line=-1.1,at=c(-3,-1,0,1,2,3)) axis(side=2,las=1,cex.axis=2,lwd=2) polygon(c(lb,x[i],ub), c(0,hx[i],0), col="grey",lwd=3,ylim=c(0,0.48)) area <- pt(ub, 10) - pt(lb, 10) mtext(side=1,adj=0.018,"pt(-2.23)",line=-9,cex=2) arrows(-1.8,0.12,-2.228,0.04,lwd=2) mtext(side=1,"=0.025",cex=2,line=-7,adj=0.016) arrows(-2.8,0.09,-2.4,0.005,lwd=2) mtext(side=1,adj=0,"qt(0.025)",line=2.5,cex=2) arrows(-2.228,-0.1,-2.228,0.0,lwd=2) mtext(side=1,line=4.5,"= -2.23",cex=2,adj=0) lb=2.228;ub=3 i <- x >= lb & x <= ub polygon(c(lb,x[i],ub), c(0,hx[i],0), col="white",lwd=3) lines(c(-2.3,2.3),c(0,0),lwd=3) arrows(2.8,0.09,2.4,0.005,lwd=2) mtext(side=1,"0.025",cex=2,line=-7,adj=1) mtext(side=1,line=-7,"0.95",adj=0.5,cex=2) 7. คำสั่งในการสร้างกราฟรูปที่ 6.6 set.seed(135) bn1 <- rbinom(0:30,size=30,p=0.1) bn2 <- rbinom(0:30,size=30,p=0.3) bn3 <- rbinom(0:30,size=30,p=0.5) bn4 <- rbinom(0:30,size=30,p=0.9) windows(10,2) par(mfrow=c(1,3),las=1,mar=c(2,6,2,1),oma=c(1,1,1,1),mgp=c(4,0.7,0.1)) plot(0:30,dbinom(0:30,30,0.1),type="h",xlim=c(0,30),ylim=c(0,0.25), ylab="Probability", xlab="", cex=1.7, .lab=1.7, cex.axis=1.7) mtext(side=3,line=1,"n=30, p=0.1",cex=1.2) plot(0:30,dbinom(0:30,30,0.5),type="h",xlim=c(0,30),ylim=c(0,0.25), ylab="Probability",xlab="",cex=1.7,cex.lab=1.7,cex.axis=1.7) mtext(side=3,line=1,"n=30, p=0.5",cex=1.2) plot(0:30,dbinom(0:30,30,0.9),type="h",xlim=c(0,30),ylim=c(0,0.25), ylab="Probability",xlab="",,cex=1.7,cex.lab=1.7,cex.axis=1.7) mtext(side=3,line=1,"n=30, p=0.9",cex=1.2) 8. คำสั่งในการสร้างกราฟรูปที่ 6.7 set.seed(135) ps1 <- rpois(100,lambda=1) ps2 <- rpois(100,lambda=2) ps3 <- rpois(100,lambda=3) ps4 <- rpois(100,lambda=4) windows(10,3) par(mfrow=c(1,4),las=1,mar=c(7,6,2,1),oma=c(1,1,1,1),mgp=c(3,0.7,0)) plot(0:100,dpois(0:100,1),type="h",xlim=c(0,15),ylim=c(0,0.4), ylab="Probability",xlab="lambda=1",cex=1.7,cex.lab=1.7,cex.axis=1.7) plot(0:100,dpois(0:100,2),type="h",xlim=c(0,15),ylim=c(0,0.4), ylab="Probability",xlab="lambda=2",cex=1.7,cex.lab=1.7,cex.axis=1.7) plot(0:100,dpois(0:100,3),type="h",xlim=c(0,15),ylim=c(0,0.4), ylab="Probability",xlab="lambda=3",cex=1.7,cex.lab=1.7,cex.axis=1.7) plot(0:100,dpois(0:100,4),type="h",xlim=c(0,15),ylim=c(0,0.4), ylab="Probability",xlab="lambda=4",cex=1.7,cex.lab=1.7,cex.axis=1.7)