##### RUN LINES 5-21 TO GENERATE ONE SIMULATED DATA SET FOR EXERCISE 5 ##### ##### (Based on Kery 2010) ################################################# n.groups <- 3 n.sample <- 100 n <- n.groups * n.sample x <- rep(1:n.groups, rep(n.sample, n.groups)) pop <- factor(x, labels = c("U","Z","G")) hours <- runif(n,4.5,7.0) mm <- mean(hours) hours <- hours-mm Xmat <- model.matrix(~pop*hours) beta.vec <- c(-2,1,2,5,-2,-7) lin.pred <- Xmat[,]%*%beta.vec lambda <- exp(lin.pred) C <- rpois(n=n, lambda=lambda) ticks <- as.data.frame(cbind(hours,pop,C)) ticks$pop <- factor(ticks$pop) levels(ticks$pop) <- c("U","Z","G") ticks