2

I am analysing some whale tourism data and am trying to construct linear mixed effect models in the nlme package to see if any of my explanatory variables affect encounter time between whales and tourists. (I am also open to running this model in lme4.)

My variables are:

  • mins: encounter time (response variable)
  • Id: individual whale ID (random effect)
  • Vessel: vessel Id (random effect)
  • Sex: sex of the animal
  • Length: length of the animal
  • Year
  • Month (nested within Year).

So my random variables are Id and Vessel and I also have Year and Month as nested random effects.

I have come up with the following:

form1 <- formula(Min ~ length + Sex+ Encounter)
 model1 <- lme(form1, 
              random = list(Id = ~1, 
                            Vessel = ~1, 
                            Year=~1,
                            Month = ~1), data=wsdata, method="ML")

But all my random effects become nested within Id.

Is there any way I can define Id and Vessel as separate random effects and Year and Month as nested random effects?

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453

1 Answers1

2

In general it's much easier to specify crossed (what you mean by "separate", I think) random effects in lme4, so unless you need models for temporal or spatial autocorrelation or heteroscedasticity (which are still easier to achieve with nlme), I would go ahead with

library(lme4)
fit <- lmer(mins ~ Length + Sex+ (1|Id) + (1|Vessel) +
                (1|Year/Month), data=wsdata, REML=FALSE)

A few other comments:

  • what is encounter? it was in your formula but not in your description of the data set
  • it seems quite likely that encounter times (a duration of encounters?) would be skewed, in which case you might want to log-transform them.
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • Thanks Ben! Encounter is the number of times each individual was encountered (I just labelled these 1, 2, 3 so on). You are right the duration of encounter is skewed and I have tried log transforming them, but does this affect the way I have to interpret my models? – Alicia.Spinnett Apr 05 '16 at 02:04
  • well, it means you will be modeling *proportional* changes in encounter duration with respect to covariates (and the encounter durations will be assumed to be log-Normally distributed among individuals, vessels, etc.). – Ben Bolker Apr 05 '16 at 02:16
  • Ok, got it. The log-transformed model looks a lot better already. Thanks for the help – Alicia.Spinnett Apr 05 '16 at 02:17