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
[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 ...attach(Hives)
, usedata=Hives
in yourlme()
call (not necessarily the problem, but [much] better practice)formula=...~...+time, random=~time|hive
(where the...
represents the bits of your existing model)?strptime
or thelubridate
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?)lme4
packagemgcv::gamm
or thegamm4
package); (2) temporal autocorrelation (consider adding acorrelation
parameter in yourlme
model).