4
$\begingroup$

I have the following model, how do I add a random intercept(no random effects included yet):

  modelid3 <- nlme(y ~ TPMRM0(M, v0, v1, v2, v3, v4, v5, v6, v7, v8, b, b, b, b, b, b, b, b),
             fixed  =list(v0 + v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 ~ 1,
                          b ~ act + 0),
             random =  -----, 
             groups = ~ id,
             data   = dat,
             weights     = varIdent(form = ~ 1 | visit),
             correlation = corSymm(value = covmmrmvec, form = ~ as.numeric(visit) | id),
             start  = init, 
             method = "ML",
             control=nlmeControl(maxIter=1000, msMaxIter = 1000, returnObject = TRUE),
             verbose = TRUE)

given that:

TPMRM0 <- function(t, v0, v1, v2, v3, v4, v5, v6, v7, v8, b1, b2, b3, b4, b5, b6, b7, b8) {
months <- seq(0,24,3)
b <- cbind(0, b1, b2, b3, b4, b5, b6, b7, b8) 
  t_out <- (1 - b[cbind(1:length(t), match(t, months))]) * t
  
  spline(x = months,
         y = c(v0[1], v1[1], v2[1], v3[1], v4[1], v5[1], v6[1], v7[1], v8[1]),
         method = 'natural',
         xout = t_out)$y
}

Tried random = 1 ~id. Still getting the same error. Here is some of the data if that helps:

id visit  M        y trt act mod_trt act_vis
1  1     1  0 109.3006 pbo   0     pbo   pbo.0
2  1     2  3 111.0854 pbo   0     pbo   pbo.3
3  1     3  6 102.1718 pbo   0     pbo   pbo.6
4  1     4  9 106.1363 pbo   0     pbo   pbo.9
.
.
.
8997 1000     6 15 92.61685 act   1     act  act.15
8998 1000     7 18 86.69760 act   1     act  act.18
8999 1000     8 21 87.87717 act   1     act  act.21
9000 1000     9 24 94.08110 act   1     act  act.24

Would this give the wanted random intercept, without interfering with the rest of the model?

  nlme(y ~ TPMRM0(M, v0, v1, v2, v3, v4, v5, v6, v7, v8, b, b, b, b, b, b, b, b) + b0,
             fixed  =list(v0 + v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 ~ 1,
                          b ~ act + 0),
             random =  list(b0 ~ 1), 
             groups = ~ id,
             data   = dat,
             weights     = varIdent(form = ~ 1 | visit),
             correlation = corSymm(value = covmmrmvec, form = ~ as.numeric(visit) | id),
             start  = init, 
             method = "ML",
             control=nlmeControl(maxIter=1000, msMaxIter = 1000, returnObject = TRUE),
             verbose = TRUE)
$\endgroup$

1 Answer 1

2
$\begingroup$

That's a very interesting model ! I'm curious about what kind of data you are dealing with, and your research questions?

Anyway in nlme you can usually just specify random interecepts for your grouping variable id:

random = ~ 1 | id
$\endgroup$
4
  • 1
    $\begingroup$ Currently working on my masters thesis, looking into some of the work described in onlinelibrary.wiley.com/doi/full/10.1002/sim.9581 . That was also my initial guess, however I get the error: Error in nlme.formula(y ~ TPMRM0(M, v0, v1, v2, v3, v4, v5, v6, v7, v8, : 'random' must be a formula or list of formulae $\endgroup$ Commented Feb 19 at 13:54
  • 1
    $\begingroup$ Very interesting. I will take a look at that paper when I get chance, In the meantime, try this instead: random = list(~1 | id), Without access to your data it is a bit hard to help, but I hope we can get there in the end ! On another note, you might want to consider using the mmrm package which is specificallyt designed for Mixed Models with Repeated Measures $\endgroup$ Commented Feb 19 at 21:28
  • $\begingroup$ Answered below to give you a snippet of the data $\endgroup$ Commented Feb 21 at 8:21
  • $\begingroup$ "Usually random effects and correlated errors are mutually exclusive." See my answer at stackoverflow.com/questions/36643713 on lme. The compound-symmetry correlation structure already specifies certain individual-specific patterns. $\endgroup$
    – DrJerryTAO
    Commented Feb 21 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.