0

I'm currently running a mixed-effect model using lmer() (lmerTest, specifically so I get p-values), in which I have 'Diet' and 'Time' as fixed effects, and 'ID1' and 'ID2' as random effects. Both Diet and Time are categorical variables, and I would like to compare the 3 diets together at various time points.

Here is my code so far:

    library(lme4)
    test1=lmerTest::lmer(Myovidiae~Diet+Time+(1|ID1)+(1|ID2), data=virallme4

I'm able to subset out the different time points if I do it this way:

 Test1T0=lmerTest::lmer(Myoviridae~Diet+(subset=virallme4$Time=="0")+(1|ID1)+(1|ID2),data=virallme4)

But, when I try to run the lsmeansLT() function that comes with lmerTest, it doesn't like the way I've subset.

I know that I need to contrast my groups somehow and I know there is an argument in lmer() for me to do that. But I have absolutely know idea how to write that code.

Any help would be greatly appreciated!

Edit: this is the lsmeans code I was using, along with the error

    > lstestT0=lmerTest::lsmeansLT(Test1T0, test.effs = "Diet")
    Error in mat %*% rho$fixEffs : non-conformable arguments
    In addition: Warning message:
    In model.matrix.default(mt, mf, contrasts) :
     variable 'subset = virallme4$Time == "0"' is absent, its contrast will be ignored
Haley
  • 119
  • 1
  • 3
  • 16
  • What do you mean "it doesn't like the way you've subset"? Is there a particular error you are getting? It's easier to help you if you include a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with the code that's actually causing the problem, ie how exactly are you trying to run `lsmeansLT()`? – MrFlick Sep 05 '17 at 21:30
  • with the subset argument, i dont think you need the `data$` part so try `subset=Time=="0" `. Also it is an argument rather than part of the formula, so try `lmer(Myoviridae ~ Diet + (1|ID1) + (1|ID2), data=virallme4, subset=Time=="0")` – user20650 Sep 06 '17 at 15:29
  • I have updated the question with the code and the error that I received above. I will try running it in that way! – Haley Sep 06 '17 at 15:40
  • When I added the subset argument at the end, it gave me this error: Error in time == "0" : comparison (1) is possible only for atomic and list types – Haley Sep 06 '17 at 15:43

0 Answers0