8

I've had a search for similar questions and come up short so apologies if there are related questions that I've missed.

I'm looking at the amount of time spent on feeders (dependent variable) across various conditions with each subject visiting feeders 30 times.

Subjects are exposed to feeders of one type which will have a different combination of being scented/unscented, having visual patterns/being blank, and having these visual or scented patterns presented in one of two spatial arrangements.

So far my model is:

mod<-lmer(timeonfeeder ~ scent_yes_no + visual_yes_no + 
    pattern_one_or_two + (1|subject), data=data)

How can I incorporate the visit numbers into the model to see if these factors have an effect on the time spent on the feeders over time?

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
wonderburg
  • 95
  • 1
  • 1
  • 5
  • 1
    would you have an example of the data? – Mathieu B Feb 25 '16 at 13:09
  • if you assume constant change across time (visit numbers) you just add it as additional level one predictor. if you assume varying change across subjects, you can additionally specify a random coefficient for the time variable. But let me ask: If you are interested in questions of timing (amount of time spend), shouldn't you rather do a duration analysis (aka event history analysis)? – Dominix Feb 25 '16 at 13:28
  • @MathieuB here's how the data is put together ![post image](http://postimg.org/image/h85spau99/) the data set is pretty huge so it would be difficult to show you the data of even just one subject. – wonderburg Feb 25 '16 at 14:05

1 Answers1

14

You have a variety of choices (this question might be marginally better for CrossValidated).

  • as @Dominix suggests, you can allow for a linear increase or decrease in time on feeder over time. It probably makes sense to allow this change to vary across birds:

    timeonfeeder ~ time + ... + (time|subject)
    
  • you could allow for an arbitrary pattern of change over time (i.e. not just linear):

    timeonfeeder ~ factor(time) + ... + (1|subject)
    

    this probably doesn't make sense in your case, because you have a large number of observations, so it would require many parameters (it would be more sensible if you had, say, 3 time points per individual)

  • you could allow for a more complex pattern of change over time via an additive model, i.e. modeling change over time with a cubic spline. For example:

    library(mgcv)
    gamm(timeonfeeder ~ s(time) + ... , random = ~1|subject
    

    (1) this assumes the temporal pattern is the same across subjects; (2) because gamm() uses lme rather than lmer under the hood you have to specify the random effect as a separate argument. (You could also use the gamm4 package, which uses lmer under the hood.)

  • You might want to allow for temporal autocorrelation. For example,

    lme(timeonfeeder ~ time + ... ,
        random = ~ time|subject,
        correlation = corAR1(form= ~time|subject) , ...)
    
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • 1
    almost, but `(1|subject)` is redundant; `(visit_no|subject)` is equivalent to `(1+visit_no|subject)`, i.e. includes variation in both the slope and the intercept across subjects – Ben Bolker Feb 25 '16 at 14:23
  • Thanks all for taking the time to answer. I think as Dominix and Ben suggested my best option is to allow for a linear increase or decrease in time on feeder over time. Just to clarify if this is the case would I then change my model to... mod<-lmer(timeonfeeder ~ visit_no + scent_yes_no + visual_yes_no + pattern_one_or_two + (1|subject) + (visit_no|subject), data=data). Forgive me if this isn't correct i'm fairly new to both r and mixed models (and commenting on Stack Overflow). Confusion abounds! – wonderburg Feb 25 '16 at 14:24
  • Brilliant thank you very much. Sorry about the terrible formatting. – wonderburg Feb 25 '16 at 14:25
  • if the question solved your problem, you are encouraged to click the check mark to accept it ... – Ben Bolker Feb 25 '16 at 17:20