简体   繁体   中英

Lme error: “Error in reStruct”

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

There are a variety of issues here, some relevant to programming (StackOverflow) but probably the statistical issues (suitable for CrossValidated or r-sig-mixed-models@r-project.org ) 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, ie 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 (eg 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM