1
$\begingroup$

I collected crop yield and rainfall data from multiple counties and year ( > 30 years). Each county can only belong to one province and each province can only belong to one region. I am interested in knowing the relationship between crop yield and rainfall.

Which of the two is the right way to specify the nested structure ( I guess it's the first one):

mod1 <- lmer(yield ~ rainfall + (1|region/province), data = dat)
mod2 <- lmer(yield ~ rainfall + (1|region) + (1|province), data = dat)  

Building on this, if I am also interested in including the time trend of each county, is the following specification correct:

 mod3 <- lmer(yield ~ rainfall + year + (1|region/province) + (1 + year|county), data = dat)

Lastly if I am interested in fitting a model just based on year and location (i.e. no rainfall), is it the right way to specify yield as a function of year and location and year trend is allowed to vary by county?:

mod4 <- lmer(yield ~ year + (1|region/province) + (1 + year|county), data = dat)
$\endgroup$

1 Answer 1

1
$\begingroup$

You are correct for the first model but you would use this syntax.

mod1 <- lmer(yield ~ rainfall + (1|region:province), data = dat)

The syntax below are for if you have crossed random effects where provinces are included in multiple regions.

mod2 <- lmer(yield ~ rainfall + (1|region) + (1|province), data = dat)  

How many counties do you have? To model the trend of counties over time you might want to include your time and county variables as fixed effects, presumably multiple dummy coded county variables, and an interaction between time and the county variables.

mod4 <- lmer(yield ~ year + county_1 + year*county_1 +(1|region:province), data = dat)
$\endgroup$
8
  • $\begingroup$ Thank you. I have around 5000 counties and for each county I have collected yield data for 35 years. If I want the time trend to a random effect, how do I insert it? $\endgroup$
    – 89_Simple
    Commented Oct 6, 2018 at 22:14
  • $\begingroup$ Oh I see so you want to model repeated measures, I was thinking you want to look at differences between counties over time. $\endgroup$ Commented Oct 6, 2018 at 22:47
  • $\begingroup$ I would change the random effects so it would be (1|region:province:county) and if you want to let the slopes for time to vary it would be (year | region:province:county). $\endgroup$ Commented Oct 6, 2018 at 22:54
  • $\begingroup$ Okay. I did not understand why I need county as a random effect. I am using province to group my counties as in ` (1 | region:province)` but I also need to add the time trend of each county as well. Does this make sense? ` (1 | region:province) + (year|county)`? $\endgroup$
    – 89_Simple
    Commented Oct 7, 2018 at 9:58
  • 1
    $\begingroup$ Each of your county has multiple measurements right? So if you include county as a random effect it accounts for repeated measures. $\endgroup$ Commented Oct 7, 2018 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.