Search code examples
rmatrix-multiplicationmixed-modelslogits

glmmLasso error "requires numeric/complex matrix/vector arguments"


I am trying to learn the mechanics of the glmmLasso package for lasso estimation with a logistic link function with fixed effects but I cannot get a dummy example to work without error.

library(glmmLasso)
y=rbinom(n = 21,size = 1,prob = .5)
x=rnorm(21)
year=rep(1:3, times=7)
ID=rep(1:7, each=3)
df=as.data.frame(cbind(y,x,ID,year))
library(glmmLasso)
lasso_fe=glmmLasso(y~x+as.factor(ID)+as.factor(year), family=binomial(link = logit), lambda=10, data = df)

The error is from the last command: "Error in n %*% s : requires numeric/complex matrix/vector arguments". I understand the error itself, but I do not understand it in this context since the data.frame itself is all numeric and the glmmLasso package requires factoring the grouping variables for fixed effects. The error also seems to occur for all subsets of variables in the equation (even removing the factor variables) and upon removing or changing the other options.


Solution

  • It appears, that by default, glmmLasso function specifies the random effects with the same formula from the fixed effects (i.e. glmmLasso(fix=formula, rnd=formula, ...).

    To run it without random effect estimation, use rnd=NULL:

    > lasso_fe <- glmmLasso(
       y~x+as.factor(ID)+as.factor(year),
       rnd = NULL, # <- no r.e.
       family=binomial(link = logit), lambda=10, data = df)
    
    > lasso_fe
    Call:
    glmmLasso(fix = y ~ x + as.factor(ID) + as.factor(year), rnd = NULL, 
        data = df, lambda = 10, family = binomial(link = logit))
    
    Fixed Effects:
    
    Coefficients:
         (Intercept)                x   as.factor(ID)2   as.factor(ID)3 
         -0.09531017       0.00000000       0.00000000       0.00000000 
      as.factor(ID)4   as.factor(ID)5   as.factor(ID)6   as.factor(ID)7 
          0.00000000       0.00000000       0.00000000       0.00000000 
    as.factor(year)2 as.factor(year)3 
          0.00000000       0.00000000 
    
    No random effects included!
    

    The error happens, because the package assumes random effects to be normally distributed. Factor variables do not fit to such specification, since they are not numeric.