Reputation: 61
I'm playing around with models.
If I run a basic GLM:
summary(glm(nfc~nform+p+namount+lime+pH+year, data=parkglm,family=gaussian()))
I get results that include year as an explanatory variable:
However, I need year to be nested in another factor, "period". There are 17 years, each year falls within one of two periods. I tried this using lme4 and lmer.
anova(lmer(nfc~nform+p+namount+lime+pH+(year|period), data=parkglm))
That gave me the below output which seems pretty reasonable, however you'll see that year or period aren't listed. I assume they've been controlled for, but I'm interested in their effects. I'm very iffy on nesting with in the lmer package.
I appreciate there might be alot wrong going on here and apologies for that. If it's just a mess, fine, don't be afraid to say! I'm new to linear models in r and have struggled to find the info I need in a manner I can implement.
Here is a slight snapshot of the top of the data with types of data in each column.
Upvotes: 0
Views: 494
Reputation: 421
This formula is for a mixed-effects model with a random intercept for "period", assuming that each observation is grouped by that variable. Note that "year" was included as a fixed effect.
library(lme4)
summary(fm <- lmer(nfc ~ nform + p + namount + lime + pH + year + (1|period), data = parkglm))
However the model may not be appropriate given the low number of categories in the variable "period".
I suggest you take a look to some references about linear models and think about strategies to model your data, perhaps building categories or exploring different models. Two good manuscripts you may be interested:
Upvotes: 2