################################################### ### chunk number 1: ################################################### options(SweaveHooks=list(fig=function(){par(cex.main=1.1, mar=c(4.1,4.1,2.6,2.1), pty="s", mgp=c(2.25,0.5,0), tck=-0.02)})) ################################################### ### chunk number 2: density-cdf ################################################### curve(dnorm(x, mean=2.5, sd=1.5), from = 2.5-3*1.5, to = 2.5+3*1.5) curve(pnorm(x, mean=2.5, sd=1.5), from = 2.5-3*1.5, to = 2.5+3*1.5) ################################################### ### chunk number 3: area ################################################### pnorm(4, mean=2.5, sd=1.5) - pnorm(0.5, mean=2.5, sd=1.5) ################################################### ### chunk number 4: density-cdf ################################################### curve(dnorm(x, mean=2.5, sd=1.5), from = 2.5-3*1.5, to = 2.5+3*1.5) curve(pnorm(x, mean=2.5, sd=1.5), from = 2.5-3*1.5, to = 2.5+3*1.5) ################################################### ### chunk number 5: rnorm-hist ################################################### par(mfrow=c(1,3), pty="s") x <- rnorm(50) hist(x, probability=TRUE) lines(density(x)) xval <- pretty(c(-3,3), 50) lines(xval, dnorm(xval), col="red") ################################################### ### chunk number 6: hist-body eval=FALSE ################################################### ## library(MASS) ## plot(density(Animals$body)) ## logbody <- log(Animals$body) ## plot(density(logbody)) ## av <- mean(logbody) ## sdev <- sd(logbody) ## xval <- pretty(c(av-3*sdev, av+3*sdev), 50) ## lines(xval, dnorm(xval, mean=av, sd=sdev)) ################################################### ### chunk number 7: rnorm-density ################################################### plot(density(rnorm(50)), type="l") ################################################### ### chunk number 8: ex-bw ################################################### plot(density(rnorm(500)), type="l") ################################################### ### chunk number 9: ex-bw ################################################### plot(density(rnorm(50), bw=0.2), type="l") plot(density(rnorm(50), bw=0.6), type="l") ################################################### ### chunk number 10: sample-with-replacement eval=FALSE ################################################### ## sample(1:5, replace=TRUE) # With replacement sample, size 5 ## for(i in 1:10)print(sample(1:5, replace=TRUE)) # 10 such samples ## plot(density(log10(Animals$body))) ## lines(density(sample(log10(Animals$body), replace=TRUE)), col="red") ################################################### ### chunk number 11: rnorm-qq ################################################### qqnorm(rnorm(10)) qqnorm(rnorm(50)) qqnorm(rnorm(200)) ################################################### ### chunk number 12: qref ################################################### library(DAAG) qreference(m=10) qreference(m=50) qreference(m=200) ################################################### ### chunk number 13: qreference-ex ################################################### qreference(possum$totlngth)