## ----setup, include=FALSE----------------------------------------------------- library(knitr) opts_chunk$set(fig.path='figure/beamer-',fig.align='center',fig.show='hold',size='footnotesize' ) ## ----fig.show='hide', label=quiz---------------------------------------------- a='https://people.math.umass.edu/~lavine/Book/book.data/quizscores' scores=read.table(a) dim(scores) colnames(scores) <- paste("Q",1:24,sep="") boxplot(scores) ## ----fig.show='hide', label=quiz2--------------------------------------------- scores[is.na(scores)] <- 0 # replace missing scores temp= apply ( scores, 1, sort ) # sort dim(temp) temp= temp[5:24,] scores.ave =apply ( temp, 2, mean ) # find the average length(scores.ave) hist(scores.ave,prob=TRUE) rug(scores.ave,col=2) ## ----fig.show='hide', label=quiz3--------------------------------------------- x=sort(scores.ave)[5:58] mu=seq ( 6.8, 7.7, length=60 ) sig=seq ( .7, 1.3, length=60 ) lik=matrix ( NA, 60, 60 ) for ( i in 1:60 ){for ( j in 1:60 ){ lik[i,j]=prod ( dnorm ( x, mu[i], sig[j] ) ) }} lik=lik/max(lik) persp(mu,sig,lik) ## ----fig.show='hide', label=quiz4--------------------------------------------- contour( mu, sig, lik) abline(v=mean(x)) abline(h=sqrt(var(x)*(length(x)-1)/length(x))) ## ----fig.show='hide', label=thetalambda--------------------------------------- lam <- seq ( 0, 5, by=.1 ) th <-seq(0,1,by=.02) lik <- matrix ( NA, length(lam), length(th) ) for ( i in seq(along=lam) ){ for ( j in seq(along=th) ){lik[i,j] <- exp ( -lam[i]*th[j])}} contour(lam,th,lik/max(lik)) ## ----fig.show='hide', label=mle1---------------------------------------------- theta <- seq ( 0, .2, length=100 ) lik <- dbinom ( 8, 145, theta ) lik <- lik / max(lik) plot ( theta, lik,xlim=c(0,1)) abline(v=8/145)