################################################### ### chunk number 1: ################################################### options(show.signif.stars=FALSE) options(SweaveHooks=list(fig=function(){par( mar=c(5.1,4.1,2.6,2.1), mgp=c(2.25,0.5,0), tck=-0.02)})) ################################################### ### chunk number 2: ex3 ################################################### for(i in 1:4)print(sample(1:7)) ## Store results in the columns of a matrix ## The following is mildly cryptic sapply(1:4, function(x)sample(1:7)) ################################################### ### chunk number 3: ex4a ################################################### av <- numeric(25) sdev <- numeric(25) ################################################### ### chunk number 4: ex4b ################################################### for(i in 1:25){ y <- rnorm(100) av[i] <- mean(y) sdev[i] <- sd(y) } sd(av) ################################################### ### chunk number 5: ex4c ################################################### avfun <- function(m=50, n=25){ for(i in 1:25){ y <- rnorm(50) av[i] <- mean(y) } sd(av) } ################################################### ### chunk number 6: ex8 ################################################### pexp(21, .05) ################################################### ### chunk number 7: ex9 eval=FALSE ################################################### ## z <- rexp(100, .2) ## plot(density(z, from=0), main="") ################################################### ### chunk number 8: ex9-do ################################################### z <- rexp(100, .2) plot(density(z, from=0), main="") ################################################### ### chunk number 9: ex9-code eval=FALSE ################################################### ## ## Code ## z <- rexp(100, .2) ## plot(density(z, from=0), main="") ################################################### ### chunk number 10: ex11 ################################################### y <- c(87, 53, 72, 90, 78, 85, 83) c(mean=mean(y), variance=var(y)) ################################################### ### chunk number 11: ################################################### x <- rpois(7, 78.3) c(mean=mean(x), variance=var(x)) ################################################### ### chunk number 12: ex12 eval=FALSE ################################################### ## P <- matrix(c(1, rep(0,5), rep(c(.5,0,.5, rep(0,4)),4), 0,1), ## byrow=TRUE,nrow=6) ## Markov(15, 2, P)