################################################### ### chunk number 1: preliminaries ################################################### library(lattice) lattice.options(default.theme = standard.theme(color = FALSE)) ################################################### ### chunk number 2: simold eval=FALSE ################################################### ## ## n is the sample size in the regression model ## ## S is the number of simulations of the model fits ## ## ## Generate the covariates ## dat <- data.frame(X1 = rnorm(n, 3, 2), X2 = rexp(n, 1), X3 = rgamma(n, 2, 3)) ## ## Assign the true coefficient vector ## betaTrue <- c(beta0 = 2, beta1 = 1.2, beta2 = -1.4, beta3 = -0.5) ## ## Calculate the true mean response ## muTrue <- as.vector(model.matrix(~ X1 + X2 + X3, dat) %*% betaTrue) ################################################### ### chunk number 3: eval=FALSE ################################################### ## SigmaSq <- runif(n, 0.5, 3) ## sigma <- sqrt(SigmaSq) ################################################### ### chunk number 4: eval=FALSE ################################################### ## yy <- muTrue + sigma * rnorm(n) ################################################### ### chunk number 5: eval=FALSE ################################################### ## YY <- muTrue + sigma * matrix(rnorm(n * S), nrow=n, ncol=S) ################################################### ### chunk number 6: antsread ################################################### DataURL <- "http://www.stat.wisc.edu/~st849-1/data/" ants <- read.table(paste(DataURL, "thatch_ant_c5del.txt", sep=''), header=TRUE) str(ants) ################################################### ### chunk number 7: iplot ################################################### ants <-within(ants, {Colony <- factor(Colony); DistF <- ordered(Distance)}) print(dotplot(reorder(Colony, Headwidth) ~ Headwidth, ants, type="a", groups = DistF, xlim=c(36,43), auto.key=list(space="right", title="Distance", points=FALSE, lines=TRUE), xlab = "Mean Headwidth by Colony and Distance", ylab = "Colony")) ################################################### ### chunk number 8: Kadata ################################################### dir <- "http://arep.med.harvard.edu/Bulyk/NAR2002supplementary/" str(Ka <- read.delim(paste(dir, "REDV_Ka_all9replicates.txt", sep = ''))) Ka <- subset(Ka, select= -c(X.1, X.2)) # drop the extra columns names(Ka) <- c("trimer", paste("r", 1:9, sep=""), "avg", "sd") ################################################### ### chunk number 9: longKa ################################################### library(reshape) str(lKa <- melt(Ka[, 1:10], id = 1)) ################################################### ### chunk number 10: longKaSup ################################################### lKa <- within(lKa, { p3 <- factor(substring(trimer, 3, 3)) p2 <- factor(substring(trimer, 2, 2)) p1 <- factor(substring(trimer, 1, 1)) }) names(lKa) <- c("trimer", "rep", "binding", "p1", "p2", "p3") head(lKa) ################################################### ### chunk number 11: eval=FALSE ################################################### ## library(ggplot2) ## qplot(binding, trimer, data=lKa, log="x") ## qplot(trimer, binding, data=lKa, log="y", geom="boxplot") + coord_flip() ################################################### ### chunk number 12: assessedStr ################################################### assessed <- read.table(paste(DataURL, "assessedval.txt", sep=''), header=FALSE) names(assessed) <- c("Selling", "Assessed", "Corner") str(assessed <- within(assessed, Corner <- factor(Corner, labels=c("N","Y"))))