1

I am trying to run glmmLasso to estimate a mixed model with the command:

glm1_final <- glmmLasso(Activity~Novelty + Valence + ROI, rnd = 
list(Subject=~1), data = KNov, lambda=lambda[opt],switch.NR=F,final.re=TRUE)

This code is basically taken from demo("glmmLasso-soccer"), but with my variables substituted in. Activity is a measure of brain activity, Novelty and Valence are categorical variables coding the type of stimulus used to elicit the response and ROI is a categorical variable coding three regions of the brain that we have sampled this activity from. Subject is an ID number for the individuals the data was sampled from (n=94). lambda[opt] is being set in a previous step, although that previous step is giving me the errors in question as well, so I don't know if it is accurate.

I keep getting two warnings:

Warning messages: 1: In split.default((1:ncol(X))[-inotpen.which], ipen) : data length is not a multiple of split variable 2: In est.glmmLasso.RE(fix = fix, rnd = rnd, data = data, lambda = lambda, : Cluster variable should be specified as a factor variable!

The first only occurs if ROI is in the model. I haven't identified any change I can make to the model to make the second go away.

I have no idea what these warnings mean, and google hasn't turned up anything on them. I do still get estimates for my parameters, I just don't know if they are accurate, since I don't know what the warnings mean.

Anyone know what these warnings mean?

UPDATE:

I have uploaded an abreviated version of my data to: Google Drive

I have confirmed I still get the second error if I run the code:

KNov <- read.table("Nov_abr.txt", header = TRUE)
KNov$Subject <- factor(KNov$Subject)
library(glmmLasso)
glmmLasso(Activity~Novelty + Valence + ROI, rnd = list(Subject=~1), data = KNov, lambda=10,switch.NR=F,final.re=TRUE)

The KNov$Subject <- factor(KNov$Subject) did clear up the other error.

The version of R I have is: R version 3.3.0 (2016-05-03), Platform: "i386-w64-mingw32"

xralphyx
  • 23
  • 6
  • Welcome to Stack Overflow! Can you please include data and/or code that will provide us with a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) ? Can we (at least) see results of `str(KNov)`? – Ben Bolker Jun 20 '16 at 12:38
  • @BenBolker I've added data, thanks for your help! – xralphyx Jun 20 '16 at 15:43

1 Answers1

4

You should use

KNov$Subject <- factor(KNov$Subject)

to get rid of the first warning, and as.factor(ROI) in your fixed-effect formula, as documented (emphasis added below):

fix: a two-sided linear formula object describing the fixed-effects part of the model, with the response on the left of a ‘~’ operator and the terms, separated by ‘+’ operators, on the right. For categorical covariables use ‘as.factor(.)’ in the formula. Note, that the corresponding dummies are treated as a group and are updated blockwise

So

glmmLasso(Activity~Novelty + Valence + as.factor(ROI),
      rnd = list(Subject=~1),
      data = KNov, lambda=10,switch.NR=F,final.re=TRUE)

seems to work (I still get a warning, but I think that's because I'm using a tiny subset of the data). (This syntax is also illustrated in the"linear mixed model with categorical covariates" example in ?glmmLasso.) Yes, it would be nice to get a more explicit warning message, but the answer is in the documentation ...

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • This does get rid of that warning. However, I would also like to test interactions with ROI. If I run `glmmLasso(Activity~Novelty + Valence + as.factor(ROI) + Novelty:as.factor(ROI) + Novelty:Valence:as.factor(ROI), rnd = list(Subject=~1), data = KNov, lambda=10,switch.NR=F,final.re=TRUE)` I get the error `Error in `[.data.frame`(data, , strsplit(fac.name, ":")[[1]][1]) : undefined columns selected` – xralphyx Jul 01 '16 at 17:37
  • my guess is that you're going to have to build your own model matrix/dummy variables; I think that `as.factor()` in formulas is treated specially, so including the interaction term will probably just it. (It would be worth trying `as.factor(Novelty:ROI)` - I doubt it'll work but if it does it would be the easiest way forward.) (I might update my answer, but technically you're asking another question ...) – Ben Bolker Jul 01 '16 at 23:53
  • Quick clarification - is the reason ROI needs the as.factor() because it has more than 2 levels (as opposed to Novelty of Valence, which are also categorical)? – xralphyx Jul 13 '16 at 15:59
  • don't know. I'm really not that familiar with this package. I would say that you might be getting away with it because the dummy variable that gets created is only one column. It would probably be safer to follow the directions and use `as.factor()` anywhere you have a categorical variable, even if it seems you can get away without it ... – Ben Bolker Jul 13 '16 at 16:03