Dear Kasper,
Thank you very much for your assistance. May I ask one last question?
I am dealing with two random effect vectors which means Laplace approximation should be done two times for each individual.
In the example C++ code you attached, I am wondering how the below part of the code should be changed to allow two random effect vectors.
For example, if I want to add another random effect vector called "u2", would it be sufficient to just add another vector and state its distribution? My change to the code is shown in bold.
// See 'spa_gauss.cpp'
typedef TMBad::ad_aug ad;
struct model {
ad x; // Data
vector<ad> sigma; // Parameters
// joint nll as function of random effects
ad operator()(vector<ad> u) (vector<ad> u2) {
ad nll = -dnorm(u,ad(0),ad(1),true).sum();
ad nll = -dnorm(u2,ad(0),ad(1),true).sum();
nll -= dnorm(x,sum(u),sigma(0),true);
return nll;