Search code examples
mixed-modelsrandom-effectsglmmtmb

How to fit a random effect only model using glmmTMB in R?


I want to fit a random effect model using the glmmTMB function in R. I specified the model to be as model = glmmTMB(Y ~ (1+x1+x2|group)). The estimation results still contain a universal intercept stored in obj$env$last.par.best[1] as beta, even though I did not put a 1 as a universal intercept outside of the random part. Anyone knows how to fit a random effect only model using glmmTMB? Thanks!

The reason I want a random effect only model is because I have a panel data with many groups, and each group has a very different relationship between y and the x's. So basically I just want one model for each group. I thought glmmTMB is able to help me achieve that.


Solution

  • I don't understand the motivation, but it's straightforward to implement this in any of the common packages using -1 in the formula to remove the constant from the fixed effects design matrix. Here is an example using the data from lme4::sleepstudy

    library('glmmTMB')
    df <- lme4::sleepstudy
    names(df) <- tolower(names(df))
    
    m1 <- glmmTMB(formula = reaction ~ -1 + (days|subject), data = df)
    summary(m1)
    # Family: gaussian  ( identity )
    # Formula:          reaction ~ -1 + (days | subject)
    # Data: df
    # 
    # AIC      BIC   logLik deviance df.resid 
    # 1840.8   1853.6   -916.4   1832.8      176 
    # 
    # Random effects:
    #   
    #   Conditional model:
    #   Groups   Name        Variance Std.Dev. Corr 
    # subject  (Intercept) 63770.1  252.53        
    # days          142.2   11.93   0.88 
    # Residual               654.9   25.59        
    # Number of obs: 180, groups:  subject, 18
    # 
    # Dispersion estimate for gaussian family (sigma^2):  655