1

I'm running Windows XP, and I recently upgraded to R 3.1.1 and updated all the packages. Oddly, I can't run a lmer on my own data any more. My code worked when I was using R 2.15. I also tried using the sleepstudy dataset in the lme4 package, and things worked fine.

I'm looking at the change in seedling count in 16 plots (8 in the high diversity treatment, 8 in the low diversity treatment) across 6 dates. Here's the data frame's structure:

>str (Dataset)
'data.frame':   96 obs. of  5 variables:
   Plot   : Factor w/ 16 levels "10B","12A","13B",..: 12 13 14 15 16 1 2 3 4 5 ...
   Trt    : Factor w/ 2 levels "high","low": 2 1 1 2 1 2 1 2 2 1 ...
   Date   : Factor w/ 6 levels "Apr-12","Apr-13",..: 1 1 1 1 1 1 1 1 1 1 ...
   Seed   : int  0 0 2 7 1 0 8 0 2 5 ...

I tried to run the full model with Date and Treatment as the fixed factors and Plot as the random factor:

> seeds <- lmer(Seed~Trt*Date+(1|Plot), Dataset)

But I keep on getting this error:

Error in get(ctr, mode = "function", envir = parent.frame()) : 
object 'contr.Treatment' of mode 'function' was not found

I've tried running a simplified model with just treatment and plot or just date and plot, and I still get the same error. Did I do something funky when importing the data into R? Any ideas what I'm doing wrong?

-- UPDATE 9/29/2014 --
So I've tried running aov on some fake data, and even that doesn't work. Here's my code:

> thing = c(4, 5, 4, 3, 2, 4, 3, 4, 4, 6, 8, 4, 5, 4, 6, 5, 8, 6, 6, 7, 6, 6, 7, 5, 6, 5, 5)
> treatment = c(rep("A",9), rep("B",9), rep("C",9))
> Dataset = data.frame(thing,treatment)
> results = aov(thing ~ treatment, data=Dataset)  

And I get the same error:

Error in get(ctr, mode = "function", envir = parent.frame()) : 
object 'contr.Treatment' of mode 'function' was not found
Thomas
  • 43,637
  • 12
  • 109
  • 140
Novem
  • 11
  • 3
  • It looks to me that, somewhere, there is code that expects to find a `contr.Treatment` function, which most likely should be the `contr.treatment` function. Not sure exactly where this is occurring or why without being able to parse the rest of the code. You might be able to fix it simply by creating that function from the correctly spelled `contr.treatment` – Ellis Valentiner Aug 22 '14 at 16:54
  • The only portion of my code that I ran when I got the error message is pretty much just the read.table statement to import my data followed by the lmer statement. I don't know why read.table or lmer would need a contr.Treatment function unless lmer has changed a lot since R 2.15.1. I looked through the documentation for the lme4 package (http://cran.r-project.org/web/packages/lme4/lme4.pdf) and couldn't find anything about "contr.treatment" either. – Novem Aug 25 '14 at 21:16
  • Can you replicate/simulate some data that have the same problem and edit the question so we can check? http://stackoverflow.com/help/mcve – Steve Sep 19 '14 at 11:43

2 Answers2

3

I was receiving the same error message when I was trying to run the dredge function (from "MuMin") on an lmer object and have been looking for people with similar issues.

I didn't find a solution to the problem online but after reading this question I looked for contr.Treatment and found it in the "car" package.
"car" was turned off, turning it on removed the error for me. It seems like "car" should have loaded as a dependency but it didn't for whatever reason.

BlueSword
  • 1,290
  • 12
  • 25
James
  • 31
  • 2
0

Same with me I was running package pscl, same error. turn car on library(car), solved it.

  • 1
    Welcome to Stack Overflow. This *might* be a useful answer, but could you please add some more details? Is there a [mcve] that shows the code you were running when you got the error? I [didn't find contr.Treatment when searching the code base of pscl](https://github.com/search?q=repo%3Aatahk%2Fpscl%20contr.Treatment&type=code) ... – Ben Bolker Jun 05 '23 at 15:57