Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
-------------- next part --------------
artSim <- function(){
#
# Function to simulate "artificial" data which is at least superficially
# similar to some real data.
#
require(MASS)
link <- "cloglog"
B <- binomial(link=link)
linkfun <- B$linkfun
linkinv <- B$linkinv
# Construct (artificial) treatment factor, covariate, and
# (random) replicate factor.
x <- seq(0,28,by=2)
Trt <- LETTERS[1:24]
Rep <- 1:3 # Three reps per treatment.
Xdat <- expand.grid(x=x,Trt=Trt,Rep=Rep)
uRep <- with(Xdat,factor(paste0(Rep,Trt)))
Xdat$Rep <- with(Xdat,factor(as.numeric(uRep)))
beta0 <- seq(-3,0.45,by=0.15)
beta1 <- rep(seq(0.05,0.3,by=0.05),4)
names(beta0) <- Trt
names(beta1) <- Trt
Sigma <- matrix(c(0.06,-0.001,-0.001,0.0001),nrow=2)
lb0 <- beta0[match(Xdat$Trt,names(beta0))]
lb1 <- beta1[match(Xdat$Trt,names(beta1))]
nrep <- 72
imat <- match(Xdat$Rep,1:nrep)
Z <- mvrnorm(nrep,c(0,0),Sigma)[imat,]
linpr <- lb0 + Z[,1] + (lb1 + Z[,2])*Xdat$x
p <- linkinv(linpr)
nsize <- 25
Dead <- rbinom(nrow(Xdat),nsize,p)
Alive <- nsize - Dead
x0 <- (linkfun(0.99) - beta0)/beta1
Xdat$Dead <- Dead
Xdat$Alive <- Alive
attr(Xdat,"trueLD99") <- x0
return(Xdat)
}
-------------- next part --------------
#
# Script scr.brmsDemo
#
set.seed(42)
X <- artSim()
library(brms)
fit <- brm(Dead|trials(Dead+Alive) ~ (0+Trt)/x + (x | Rep),
family=binomial(link="cloglog"),data=X,
prior=set_prior("normal(0,10)"))