[R] Problems using lmer {lme4}

Patrick Coulombe patrick.coulombe at gmail.com
Fri May 17 20:15:23 CEST 2013


Hi Andrea,

I'm not exactly sure what you're trying to do, but you've included a
random effect for a "site" coefficient that's not even in your list of
fixed effects... you're basically allowing the coefficient for site to
vary across routes, but you're never including the coefficient in the
first place. Given the appropriate nested structure (I haven't looked
at your data), a model that should run would be:

m2 <- lmer(cbind(punto6,5) ~ sp + site + (site|route) ,family=binomial,data = d)

The problem here is I'm not sure this is what you mean to do... If you
could way simplify your example (for example, by including a small
number of mock observations with only the relevant variables, in a
table instead of in R syntax), that would be helpful.

Patrick

2013/5/17 Andrea Goijman <agoijman at cnia.inta.gov.ar>:
> Dear R list,
>
> I'm attaching a sample of my data which consists on the presence/absence
> ("punto6", binomial n=5 occasions)
> of different species ("sp"), on different sites ("site") within routes
> ('route").
>
> First, I want to be able to find if there is autocorrelation of the
> response variable between
> the sites within each route. For this I start testing 2 models, but when I
> try to run the second model,
> to test for the random effects of sites within routes R stops working!
>
> I'm not being able to find out why r is crashing... and whay am I doing
> wrong.
>
> Thanks!
>
> Andrea
>
> #######################################################
> #dput(d)
>
> d<-structure(list(site = structure(c(55L, 56L, 57L, 58L, 59L, 60L,
> 55L, 56L, 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 55L,
> 56L, 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 55L, 56L,
> 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 229L, 230L,
> 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L, 234L, 229L,
> 230L, 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L, 234L,
> 229L, 230L, 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L,
> 234L, 229L, 230L, 231L, 232L, 233L, 234L, 331L, 332L, 333L, 334L,
> 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L, 332L, 333L,
> 334L, 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L, 332L,
> 333L, 334L, 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L,
> 332L, 333L, 334L, 335L, 336L, 389L, 390L, 391L, 392L, 393L, 394L,
> 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L, 392L, 393L,
> 394L, 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L, 392L,
> 393L, 394L, 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L,
> 392L, 393L, 394L, 205L, 206L, 207L, 208L, 209L, 210L, 205L, 206L,
> 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L, 210L, 205L,
> 206L, 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L, 210L,
> 205L, 206L, 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L,
> 210L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L, 165L, 166L,
> 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L, 165L,
> 166L, 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L,
> 165L, 166L, 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 247L,
> 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L, 251L, 252L,
> 247L, 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L, 251L,
> 252L, 247L, 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L,
> 251L, 252L, 247L, 248L, 249L, 250L, 251L, 252L), .Label = c("102-1",
> "102-2", "102-3", "102-4", "102-5", "102-6", "1023-1", "1023-2",
> "1023-3", "1023-4", "1023-5", "1023-6", "1027-1", "1027-2", "1027-3",
> "1027-4", "1027-5", "1027-6", "1028-1", "1028-2", "1028-3", "1028-4",
> "1028-5", "1028-6", "1032-1", "1032-2", "1032-3", "1032-4", "1032-5",
> "1032-6", "1034-1", "1034-2", "1034-3", "1034-4", "1034-5", "1034-6",
> "1036-1", "1036-2", "1036-3", "1036-4", "1036-5", "1036-6", "1041-1",
> "1041-2", "1041-3", "1041-4", "1041-5", "1041-6", "1046-1", "1046-2",
> "1046-3", "1046-4", "1046-5", "1046-6", "105-1", "105-2", "105-3",
> "105-4", "105-5", "105-6", "107-1", "107-2", "107-3", "107-4",
> "107-5", "107-6", "108-1", "108-2", "108-3", "108-4", "108-5",
> "108-6", "1101-1", "1101-2", "1101-3", "1101-4", "1101-5", "1101-6",
> "1104-1", "1104-2", "1104-3", "1104-4", "1104-5", "1104-6", "1108-1",
> "1108-2", "1108-3", "1108-4", "1108-5", "1108-6", "111-1", "111-2",
> "111-3", "111-4", "111-5", "111-6", "1113-1", "1113-2", "1113-3",
> "1113-4", "1113-5", "1113-6", "1116-1", "1116-2", "1116-3", "1116-4",
> "1116-5", "1116-6", "1121-1", "1121-2", "1121-3", "1121-4", "1121-5",
> "1121-6", "1204-1", "1204-2", "1204-3", "1204-4", "1204-5", "1204-6",
> "1205-1", "1205-2", "1205-3", "1205-4", "1205-5", "1205-6", "1207-1",
> "1207-2", "1207-3", "1207-4", "1207-5", "1207-6", "1212-1", "1212-2",
> "1212-3", "1212-4", "1212-5", "1212-6", "202-1", "202-2", "202-3",
> "202-4", "202-5", "202-6", "205-1", "205-2", "205-3", "205-4",
> "205-5", "205-6", "207-1", "207-2", "207-3", "207-4", "207-5",
> "207-6", "208-1", "208-2", "208-3", "208-4", "208-5", "208-6",
> "211-1", "211-2", "211-3", "211-4", "211-5", "211-6", "213-1",
> "213-2", "213-3", "213-4", "213-5", "213-6", "214-1", "214-2",
> "214-3", "214-4", "214-5", "214-6", "217-1", "217-2", "217-3",
> "217-4", "217-5", "217-6", "218-1", "218-2", "218-3", "218-4",
> "218-5", "218-6", "219-1", "219-2", "219-3", "219-4", "219-5",
> "219-6", "223-1", "223-2", "223-3", "223-4", "223-5", "223-6",
> "302-1", "302-2", "302-3", "302-4", "302-5", "302-6", "305-1",
> "305-2", "305-3", "305-4", "305-5", "305-6", "308-1", "308-2",
> "308-3", "308-4", "308-5", "308-6", "311-1", "311-2", "311-3",
> "311-4", "311-5", "311-6", "401-1", "401-2", "401-3", "401-4",
> "401-5", "401-6", "402-1", "402-2", "402-3", "402-4", "402-5",
> "402-6", "405-1", "405-2", "405-3", "405-4", "405-5", "405-6",
> "407-1", "407-2", "407-3", "407-4", "407-5", "407-6", "408-1",
> "408-2", "408-3", "408-4", "408-5", "408-6", "410-1", "410-2",
> "410-3", "410-4", "410-5", "410-6", "411-1", "411-2", "411-3",
> "411-4", "411-5", "411-6", "414-1", "414-2", "414-3", "414-4",
> "414-5", "414-6", "416-1", "416-2", "416-3", "416-4", "416-5",
> "416-6", "417-1", "417-2", "417-3", "417-4", "417-5", "417-6",
> "420-1", "420-2", "420-3", "420-4", "420-5", "420-6", "423-1",
> "423-2", "423-3", "423-4", "423-5", "423-6", "501-1", "501-2",
> "501-3", "501-4", "501-5", "501-6", "502-1", "502-2", "502-3",
> "502-4", "502-5", "502-6", "504-1", "504-2", "504-3", "504-4",
> "504-5", "504-6", "505-1", "505-2", "505-3", "505-4", "505-5",
> "505-6", "507-1", "507-2", "507-3", "507-4", "507-5", "507-6",
> "508-1", "508-2", "508-3", "508-4", "508-5", "508-6", "511-1",
> "511-2", "511-3", "511-4", "511-5", "511-6", "602-1", "602-2",
> "602-3", "602-4", "602-5", "602-6", "604-1", "604-2", "604-3",
> "604-4", "604-5", "604-6", "605-1", "605-2", "605-3", "605-4",
> "605-5", "605-6", "608-1", "608-2", "608-3", "608-4", "608-5",
> "608-6", "611-1", "611-2", "611-3", "611-4", "611-5", "611-6",
> "613-1", "613-2", "613-3", "613-4", "613-5", "613-6", "614-1",
> "614-2", "614-3", "614-4", "617-1", "617-2", "617-3", "617-4",
> "617-5", "617-6", "620-1", "620-2", "620-3", "620-4", "620-5",
> "620-6", "623-1", "623-2", "623-3", "623-4", "623-5", "623-6",
> "702-1", "702-2", "702-3", "702-4", "702-5", "702-6", "705-1",
> "705-2", "705-3", "705-4", "705-5", "705-6", "708-1", "708-2",
> "708-3", "708-4", "708-5", "708-6", "712-1", "712-2", "712-3",
> "712-4", "712-5", "712-6", "713-1", "713-2", "713-3", "713-4",
> "713-5", "713-6", "715-1", "715-2", "715-3", "715-4", "715-5",
> "715-6", "717-1", "717-2", "717-3", "717-4", "717-5", "717-6",
> "718-1", "718-2", "718-3", "718-4", "718-5", "718-6", "803-1",
> "803-2", "803-3", "803-4", "803-5", "803-6", "807-1", "807-2",
> "807-3", "807-4", "807-5", "807-6", "809-1", "809-2", "809-3",
> "809-4", "809-5", "809-6", "812-1", "812-2", "812-3", "812-4",
> "812-5", "812-6", "814-1", "814-2", "814-3", "814-4", "814-5",
> "814-6", "818-1", "818-2", "818-3", "818-4", "818-5", "818-6",
> "820-1", "820-2", "820-3", "820-4", "820-5", "820-6", "823-1",
> "823-2", "823-3", "823-4", "823-5", "823-6", "825-1", "825-2",
> "825-3", "825-4", "825-5", "825-6", "903-1", "903-2", "903-3",
> "903-4", "903-5", "903-6", "907-1", "907-2", "907-3", "907-4",
> "907-5", "907-6", "909-1", "909-2", "909-3", "909-4", "909-5",
> "909-6", "913-1", "913-2", "913-3", "913-4", "913-5", "913-6",
> "915-1", "915-2", "915-3", "915-4", "915-5", "915-6", "920-1",
> "920-2", "920-3", "920-4", "920-5", "920-6", "925-1", "925-2",
> "925-3", "925-4", "925-5", "925-6", "926-1", "926-2", "926-3",
> "926-4", "926-5", "926-6"), class = "factor"), sp = structure(c(4L,
> 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
> 2L, 3L, 3L, 3L, 3L, 3L, 3L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L,
> 7L, 7L, 7L, 5L, 5L, 5L, 5L, 5L, 5L, 4L, 4L, 4L, 4L, 4L, 4L, 1L,
> 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L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", "105", "105", "105", "105", "105", "105", "105",
> "105", "105", "105", "105", "105", "105", "105", "105", "105",
> "105", "105", "105", "105", "105", "105", "105", "105", "105",
> "105", "105", "105", "105", "105", "105", "105", "105", "105",
> "105", "105", "105", "105", "105", "401", "401", "401", "401",
> "401", "401", "401", "401", "401", "401", "401", "401", "401",
> "401", "401", "401", "401", "401", "401", "401", "401", "401",
> "401", "401", "401", "401", "401", "401", "401", "401", "401",
> "401", "401", "401", "401", "401", "401", "401", "401", "401",
> "401", "401", "508", "508", "508", "508", "508", "508", "508",
> "508", "508", "508", "508", "508", "508", "508", "508", "508",
> "508", "508", "508", "508", "508", "508", "508", "508", "508",
> "508", "508", "508", "508", "508", "508", "508", "508", "508",
> "508", "508", "508", "508", "508", "508", "508", "508", "620",
> "620", "620", "620", "620", "620", "620", "620", "620", "620",
> "620", "620", "620", "620", "620", "620", "620", "620", "620",
> "620", "620", "620", "620", "620", "620", "620", "620", "620",
> "620", "620", "620", "620", "620", "620", "620", "620", "620",
> "620", "620", "620", "620", "620", "302", "302", "302", "302",
> "302", "302", "302", "302", "302", "302", "302", "302", "302",
> "302", "302", "302", "302", "302", "302", "302", "302", "302",
> "302", "302", "302", "302", "302", "302", "302", "302", "302",
> "302", "302", "302", "302", "302", "302", "302", "302", "302",
> "302", "302", "211", "211", "211", "211", "211", "211", "211",
> "211", "211", "211", "211", "211", "211", "211", "211", "211",
> "211", "211", "211", "211", "211", "211", "211", "211", "211",
> "211", "211", "211", "211", "211", "211", "211", "211", "211",
> "211", "211", "211", "211", "211", "211", "211", "211", "407",
> "407", "407", "407", "407", "407", "407", "407", "407", "407",
> "407", "407", "407", "407", "407", "407", "407", "407", "407",
> "407", "407", "407", "407", "407", "407", "407", "407", "407",
> "407", "407", "407", "407", "407", "407", "407", "407", "407",
> "407", "407", "407", "407", "407"), punto6 = c(3, 5, 3, 2, 2,
> 2, 0, 0, 0, 0, 0, 0, 3, 3, 5, 4, 5, 2, 1, 0, 0, 1, 1, 2, 1, 1,
> 0, 2, 1, 0, 0, 0, 0, 0, 0, 3, 0, 0, 2, 3, 3, 1, 3, 2, 2, 3, 3,
> 2, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 1, 1, 1, 1, 1, 0, 2, 1, 2,
> 1, 2, 2, 0, 4, 2, 2, 2, 0, 3, 2, 0, 2, 0, 2, 2, 0, 0, 1, 0, 0,
> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0,
> 2, 2, 0, 0, 0, 1, 1, 1, 1, 2, 0, 2, 0, 0, 0, 0, 0, 0, 2, 1, 0,
> 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 2,
> 2, 1, 0, 2, 1, 1, 5, 1, 3, 1, 0, 0, 1, 1, 0, 2, 2, 4, 5, 4, 4,
> 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0,
> 1, 4, 2, 1, 0, 2, 0, 1, 1, 0, 1, 0, 2, 3, 1, 1, 1, 1, 1, 2, 2,
> 1, 0, 0, 0, 0, 0, 0, 1, 2, 2, 0, 3, 0, 0, 1, 0, 1, 0, 0, 1, 3,
> 1, 3, 4, 2, 4, 5, 5, 3, 3, 3, 0, 0, 0, 0, 0, 1, 1, 3, 0, 0, 1,
> 2, 0, 0, 0, 0, 0, 0, 2, 1, 1, 4, 2, 0, 1, 2, 1, 2, 2, 2, 2, 1,
> 3, 0, 1, 0, 2, 3, 3, 2, 1, 4, 1, 0, 1, 1, 1, 1)), .Names = c("site",
> "sp", "route", "punto6"), class = "data.frame", row.names = c(NA,
> -294L))
>
> d
>
> library(lme4)
>
> # varying intercept by route, species fixed effect
> m1 <-  lmer(cbind(punto6,5) ~ sp + (1|route) ,family=binomial,data = d)
>
> # varying intercept by site within route, species fixed effect
> m2 <-  lmer(cbind(punto6,5) ~ sp + (site|route) ,family=binomial,data = d)
>  ### CRASHES!
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list