<p>This formula is for a mixed-effects model with a random intercept for &quot;period&quot;,
assuming that each observation is grouped by that variable.
Note that &quot;year&quot; was included as a fixed effect.</p>
<pre><code>library(lme4)
summary(fm &lt;- lmer(nfc ~ nform + p + namount + lime + pH + year + (1|period), data = parkglm))
</code></pre>
<p>However the model may not be appropriate given the low number of categories
in the variable &quot;period&quot;.</p>
<p>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:</p>
<p><a href="http://arxiv.org/pdf/1308.5499.pdf" rel="nofollow noreferrer">Winter, B. (2013). Linear models and linear mixed effects models in R
with linguistic applications. arXiv:1308.5499.</a></p>
<p><a href="https://www.jstatsoft.org/article/view/v067i01" rel="nofollow noreferrer">Douglas Bates, Martin Maechler, Ben Bolker, Steve Walker (2015).
Fitting Linear Mixed-Effects Models Using lme4. Journal of Statistical
Software, 67(1), 1-48. doi:10.18637/jss.v067.i01.</a></p>
How to nest effects within lmer?
<p>I'm playing around with models.</p>
<p>If I run a basic GLM:</p>
<pre><code>summary(glm(nfc~nform+p+namount+lime+pH+year, data=parkglm,family=gaussian()))
</code></pre>
<p>I get results that include year as an explanatory variable:</p>
<p><a href="https://i.stack.imgur.com/2u1av.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2u1av.png" alt="enter image description here" /></a></p>
<p>However, I need year to be nested in another factor, &quot;period&quot;. There are 17 years, each year falls within one of two periods. I tried this using lme4 and lmer.</p>
<pre><code>anova(lmer(nfc~nform+p+namount+lime+pH+(year|period), data=parkglm))
</code></pre>
<p>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.</p>
<p><a href="https://i.stack.imgur.com/uBiDZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uBiDZ.png" alt="lmer output" /></a></p>
<p>I appreciate there might be <em>alot</em> 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.</p>
<p>Here is a slight snapshot of the top of the data with types of data in each column.</p>
<ul>
<li>Period = categoric and is either &quot;pre&quot; or &quot;post&quot;</li>
<li>Year = continuous</li>
<li>Plot = ignore</li>
<li>Nform = categoric</li>
<li>namount =   continuous</li>
<li>p = binary/categoric (0 or 1)</li>
<li>k = ignore</li>
<li>lime = binary /
categoric (0 or 1)</li>
<li>ph:nfc = all continuous</li>
</ul>
<p><a href="https://i.stack.imgur.com/N37lC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N37lC.png" alt="data snap." /></a></p>