Hi Ben:
I went ahead an programmed the laplace approx. using Newton-Raphson.
While this approx. is useful in a more general context, let's focus on logistic mixed effects model with normal random effects. I want to weight the GLMM likelihood by 'nrep', so I am using laplace approx. as a method to marginalize out the random effects. After some effort, I could do this in Stan.
However, I still have a few questions:
- Why is a GLMM with 30 observations so slow? [I checked and found that Newton-Raphson iterations are pretty fast, so laplace approx is pretty fast]
- This approx also fails sometimes with the sampler complaining that it is unable to find a good move (probably this is what Ben was referring to?)
- Am I expecting too much from stan?
- Or may be I am missing something obvious ...
I have attached the stan script. You can use the following command and script data
simList = structure(list(nobs = 30L, nfixef = 3L, nranef = 2L, ngroup = 4L,
nrep = 1, xmat = structure(c(-1, -1, -1, 1, 1, -1, -1, 1,
1, -1, -1, 1, -1, 1, -1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1,
1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1,
1, 1, 1, 1, -1, -1, 1, 1, 1, -1, -1, -1, 1, 1, 1, -1, 1,
1, -1, -1, 1, -1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, 1, 1, -1,
1, 1, 1, 1, -1, -1, 1, 1, 1, -1, -1, 1, 1), .Dim = c(30L,
3L), .Dimnames = list(c("3", "13", "16", "17", "24", "1",
"2", "5", "6", "10", "14", "19", "20", "26", "29", "30",
"8", "9", "11", "12", "18", "23", "4", "7", "15", "21", "22",
"25", "27", "28"), NULL)), zmat = structure(c(-1, 1, 1, 1,
1, 1, -1, 1, 1, 1, -1, -1, 1, 1, -1, -1, 1, -1, 1, -1, -1,
1, 1, -1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1, -1, 1, -1, 1,
-1, 1, 1, 1, 1, 1, 1, -1, -1, -1, 1, 1, -1, -1, -1, 1, -1,
-1, 1, 1, -1, -1), .Dim = c(30L, 2L), .Dimnames = list(c("3",
"13", "16", "17", "24", "1", "2", "5", "6", "10", "14", "19",
"20", "26", "29", "30", "8", "9", "11", "12", "18", "23",
"4", "7", "15", "21", "22", "25", "27", "28"), NULL)), group = c(1L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L),
yvec = c(1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1,
1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1), pos1 = c(1, 6,
17, 23), pos2 = c(5L, 16L, 22L, 30L)), .Names = c("nobs",
"nfixef", "nranef", "ngroup", "nrep", "xmat", "zmat", "group",
"yvec", "pos1", "pos2"))
stanCode <- readChar("mod_lik.stan",
file.info("mod_lik.stan")$size)
mdl <- stan(model_code = stanCode, data = simList, iter = 2000, warmup = 1000, chains = 1, thin = 5)