Lme error: "Error in reStruct"

Evan

4 beehives were equipped with sensors that collected temp, humidity, pressure, decibels inside the hive. these are the response variables.

the treatment was wifi exposure, the experimental groups were exposed to wifi from day 1 to day 20, then again from day 35-45, and data was collected until day day 54. n of hives = 4, n of data collected by sensors in each hive = ~million.

I am having difficulties running mixed effects models.

there is a data frame of all the hives' response variables.

names(Hives)
[1] "time"           "dht22_t"        "dht11_t"        "dht22_h"       
[5] "dht11_h"        "db"             "pa"             "treatment_hive"
[9] "wifi"   

time is in "%Y-%m-%d %H:%M:%S", dht11/22_t/h are either temperature and humidity data. "wifi" is a dichotomous variable (1=on 0=off) that corresponds to the time of exposure, and treatment hive is another dichotomous variable for the hives exposed to wifi (1=exposure, 0=control).

Here is the error i am getting.

attach(Hives)
model2 = lme(pa_t~wifi*treatment_hive, random=time, na.action=na.omit, method="REML",)

Error in reStruct(random, REML = REML, data = NULL) : 
Object must be a list or a formula

Here is a sample of the code:

    time    dht22_t dht11_t dht22_h dht11_h db  pa  treatment_hive  wifi
1   01/09/2014 15:19    NA      NA  NA      NA  51.75467    NA      0   1
2   01/09/2014 15:19    30.8    31  59.8    44  55.27682    100672  0   1
3   01/09/2014 15:19    30.8    31  60.3    44  54.81995    100675  0   1
4   01/09/2014 15:19    30.8    31  60.9    44  54.14134    100671  0   1
5   01/09/2014 15:19    30.8    31  61.1    44  53.88574    100672  0   1
6   01/09/2014 15:19    30.8    31  61.2    44  53.68800    100680  0   1

R version 2.15.1 (2012-06-22) Platform: i486-pc-linux-gnu (32-bit)
attached packages: [1] ggplot2_0.8.9 proto_0.3-9.2 reshape_0.8.4 plyr_1.7.1 nlme_3.1-104
[6] lme4_0.999999-0 Matrix_1.0-6 lattice_0.20-6

Ben Bolker

There are a variety of issues here, some relevant to programming (StackOverflow) but probably the statistical issues (suitable for CrossValidated or [email protected]) are more important.

tl;dr If you just want to avoid the error I think you need random=~1|hive (whatever your hive-indicator variable is) to fit a model where baseline response (intercept) varies across hives, but I'd encourage you to read on ...

  • can we have a (small!) reproducible example ?
  • don't use attach(Hives), use data=Hives in your lme() call (not necessarily the problem, but [much] better practice)
  • with only 4 hives it is a bit questionable whether a random effect specification across hives will work (although with a million observations you might get away with it)
  • the random effect must be composed of a categorical (factor) grouping variable; in your case I think "hive" is the grouping variable, but I can't tell from your question which variable identifies hives
  • you should almost certainly have a model that accounts for trends in time and variation in time trends across hives, i.e. a random-slopes model, which would be expressed as formula=...~...+time, random=~time|hive (where the ... represents the bits of your existing model)
  • you'll have to convert time to something sensible to use it in your model (see ?strptime or the lubridate package), something like seconds/minutes/hours from starting time might be most sensible. (What is your time resolution? Do you have multiple sensors per hive, in which case you should consider fitting a random effect of sensor as well?)
  • with millions of data points your model fit is likely to be very slow; you might want to consider the lme4 package
  • with millions of data points everything is going to be statistically significant, and very sensitive to aspects of the model that don't appear in the data, such as (1) nonlinear trends in time (e.g. consider fitting additive models of the time trends with mgcv::gamm or the gamm4 package); (2) temporal autocorrelation (consider adding a correlation parameter in your lme model).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Lme error: "Error in reStruct"

From Dev

standard error of outcome in lm and lme

From Dev

Convergence error for development version of lme4

From Dev

lme - Error: object of type 'closure' is not subsettable

From Dev

lme4 error message "Error in getOptfun(optimizer)"

From Dev

lme4 error message "Error in getOptfun(optimizer)"

From Dev

Error : object ‘sigma’ is not exported by 'namespace:lme4'

From Dev

Extracting coefficients and their standard error for each unit in an lme model fit

From Dev

Error : object ‘sigma’ is not exported by 'namespace:lme4'

From Dev

Error "cannot coerce class '"formula"' into a data.frame" when using lme function

From Dev

Error: (maxstephalfit) PIRLS step-halvings failed to reduce deviance in pwrssUpdate in lme4 for ratio data

From Dev

Making a loop for lme() in r

From Dev

Create lme object within a function

From Dev

Nested random effects in `lme {nlme}`

From Dev

How to modify slots lme4 >1.0

From Dev

Setting rhoend parameter with lme4

From Dev

Prediction with lme4 on new levels

From Dev

Does the varIdent function, used in LME work fine?

From Dev

R stargazer, lme4 and lmerTest incompatibility

From Dev

Backward selection in LME, singularity in backsolve occured

From Dev

bootstrapping with lme4 model and missing values

From Dev

lme4 calculate confidence intervals of covariances

From Dev

How to use lme4.0 with lmerTest?

From Dev

Does the varIdent function, used in LME work fine?

From Dev

Backward selection in LME, singularity in backsolve occured

From Dev

Setting rhoend parameter with lme4

From Dev

Interpreting glmer confidence interval in lme4

From Dev

Using car:::linearHypothesis() with lme4 models

From Dev

Hide warning message in lme4

Related Related

  1. 1

    Lme error: "Error in reStruct"

  2. 2

    standard error of outcome in lm and lme

  3. 3

    Convergence error for development version of lme4

  4. 4

    lme - Error: object of type 'closure' is not subsettable

  5. 5

    lme4 error message "Error in getOptfun(optimizer)"

  6. 6

    lme4 error message "Error in getOptfun(optimizer)"

  7. 7

    Error : object ‘sigma’ is not exported by 'namespace:lme4'

  8. 8

    Extracting coefficients and their standard error for each unit in an lme model fit

  9. 9

    Error : object ‘sigma’ is not exported by 'namespace:lme4'

  10. 10

    Error "cannot coerce class '"formula"' into a data.frame" when using lme function

  11. 11

    Error: (maxstephalfit) PIRLS step-halvings failed to reduce deviance in pwrssUpdate in lme4 for ratio data

  12. 12

    Making a loop for lme() in r

  13. 13

    Create lme object within a function

  14. 14

    Nested random effects in `lme {nlme}`

  15. 15

    How to modify slots lme4 >1.0

  16. 16

    Setting rhoend parameter with lme4

  17. 17

    Prediction with lme4 on new levels

  18. 18

    Does the varIdent function, used in LME work fine?

  19. 19

    R stargazer, lme4 and lmerTest incompatibility

  20. 20

    Backward selection in LME, singularity in backsolve occured

  21. 21

    bootstrapping with lme4 model and missing values

  22. 22

    lme4 calculate confidence intervals of covariances

  23. 23

    How to use lme4.0 with lmerTest?

  24. 24

    Does the varIdent function, used in LME work fine?

  25. 25

    Backward selection in LME, singularity in backsolve occured

  26. 26

    Setting rhoend parameter with lme4

  27. 27

    Interpreting glmer confidence interval in lme4

  28. 28

    Using car:::linearHypothesis() with lme4 models

  29. 29

    Hide warning message in lme4

HotTag

Archive