0

I'm trying to create a mixed effects model with lmer. The SubPlot should be nested with Plot ja Treatment should be nested with Subplot. So there's 3 to 7 Treatment in SubPlots ja always 3 SubPlot in a Plot. I created a following model:

model <- lmer(Depth ~ Mass + (1|Plot:SubPlot:Treatment), data=mydata)

But this gives me an error: Error: number of levels of each grouping factor must be < number of observations (problems: Plot:SubPlot:Treatment)

'data.frame': 147 obs. of 6 variables:
$ Plot : int 1 1 1 1 1 1 1 1 1 1 ...
$ SubPlot : int 1 1 1 1 1 1 1 2 2 2 ...
$ Treatment : int 1 2 3 4 5 6 7 1 2 3 ...
$ Depth : num 0 4 4.5 5.5 6 6 6 3 4.5 6.5 ...
$ Mass : int 21 50 78 103 128 147 172 21 49 77 ...

Here's some data:

Plot SubPlot Treatment Depth Mass
1   1   1   0   21
1   1   2   4   50
1   1   3   4.5 78
1   1   4   5.5 103
1   1   5   6   128
1   1   6   6   147
1   1   7   6   172
1   2   1   3   21
1   2   2   4.5 49
1   2   3   6.5 77
1   2   4   7   102
1   2   5   8   127
1   2   6   9   146
1   2   7   10.5    171
1   3   1   3   21
1   3   2   1.5 49
1   3   3   1.5 77
1   3   4   1.5 102
1   3   5   1.5 127
1   3   6   1.5 146
1   3   7   1.5 171
2   1   1   3   21
2   1   2   5   50
2   1   3   5   78
2   1   4   7   103
2   1   5   9   128
2   1   6   9.5 146
2   1   7   10  171
2   2   1   1.5 21
2   2   2   4   50
2   2   3   5   78
2   2   4   9   103
2   2   5   10  128
2   2   6   10.5    146
2   2   7   10.5    171
2   3   1   0   21
2   3   2   0   50
2   3   3   0   78
2   3   4   0   103
2   3   5   0   128
2   3   6   0   146
2   3   7   0   171

Any ideas how to proceed?

jhtsom
  • 1
  • 1
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Nov 05 '20 at 18:58
  • I added some data. Does it help? – jhtsom Nov 06 '20 at 07:13
  • `Treatment` is missing in your data. Your error message says that there aren't enough observations in each group. Indeed the `Plot:Subplot:Treatment` structure ends up with only 1 observation in each group. The model runs (but doesn't necessarily converge) if you use only 2 levels of grouping variables rather than 3. – meriops Nov 06 '20 at 10:19
  • Treatment column was incorrectly named, now it's correct. – jhtsom Nov 06 '20 at 11:46

0 Answers0