title: How to do stepwise model with random effect (lme4 + lmerTest?)
body: <p>I am trying to perform a stepwise model with a random effect, of which I can get a BIC value.</p>
  
  <p>The lmerTest package said it works with lme4, but I can only get it to work if I remove one of my independent variables from the model (which is a factor with two options (TM))</p>
  
  <p>The error code is:</p>
  
  <blockquote>
    <p>Error in <code>$&lt;-</code>(<code>*tmp*</code>, formula, value = Terms) :    no method for
    assigning subsets of this S4 class</p>
  </blockquote>
  
  <p>or</p>
  
  <blockquote>
    <p>Error in as_lmerModLmerTest(model) : 
      model not of class 'lmerMod': cannot coerce to class 'lmerModLmerTest</p>
  </blockquote>
  
  <p>I've read somewhere it might have something to do with the drop1, but I still didn't figure it out. I am also open to suggestions of other packages and functions.</p>
  
  <p>Before, when trying the
  full.model &lt;- lm ( ...
  everything worked. After changing to lmer, it didn't anymore.</p>
  
  <h1>The code I am using now:</h1>
  
  <pre><code>full.model &lt;- lme4::lmer(dep ~ TM + ind + (1 | dorp),  data=test)  #lmerTest:: give same outcome
  
  step.model&lt;- lmerTest::step(full.model, direction="both",k=log(16))   # n=16
  
  summary(step.model)
  
  BIC(step.model)
  </code></pre>
  
  <pre><code>#Example dataset
  
  test &lt;- data.frame(TM = as.factor(c(rep("org", 3), rep("min", 3),rep("org", 3), rep("min", 3),rep("org", 3), rep("min", 3))),
                     dep = runif(18,0,20),
                     ind = runif(18,0,7),
                     dorp = as.factor(c(rep(1,6),rep(2,6),rep(3,6))))
  
  </code></pre>