title: Simulating a mixed linear model and evaluating it with lmerTest in R
body: <p>I am trying to understand how to use mixed linear models to analyse my data by simulating a model, but I can't reproduce the  input parameters. What am I missing?</p>
  
  <p>I want to start simulating a model with a random intercept for each subject. Here is the formula of what I want to simulate and reproduce:
  <a href="https://i.stack.imgur.com/8cX6v.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8cX6v.png" alt="enter image description here"></a></p>
  
  <p>If beta1 (&lt;11) is small I find gamma00 as the intercept in fixed section, but I am completedly unaable to retrieve the slope (beta1). Also, the linear effect is not significant. Where is my conceptual mistake?</p>
  
  <pre><code>library(lmerTest)
  # Generating data set
  # General values and variables
  numObj &lt;- 20
  numSub &lt;- 100
  e      &lt;- rnorm(numObj * numSub, mean = 0, sd = 0.1)
  x      &lt;- scale(runif(numObj * numSub, min = -100, max = 100))
  y      &lt;- c()
  index  &lt;- 1
  
  # Coefficients
  gamma00 &lt;- 18
  gamma01 &lt;- 0.5
  beta1   &lt;- -100
  w       &lt;- runif(numSub, min = -3, max = 3)
  uo      &lt;- rnorm(numSub, mean = 0, sd = 0.1)
  meanBeta0 &lt;- mean(gamma00 + gamma01*w + uo) # I should be able to retrieve that parameter. 
  
  for(j in 1:numSub){
    for(i in 1:numObj){
      y[index] &lt;- gamma00 + gamma01*w[j]+ uo[j] + beta1*x[i] + e[index]
      index &lt;- index + 1
    } 
  }
  
  dataFrame2 &lt;- data.frame(y = y, x = x, subNo = factor(rep(1:numSub, each = numObj)), objNum = factor(rep(1:numObj, numSub))) 
  
  model2 &lt;- lmer(y ~  x + 
                   (1 | subNo), data = dataFrame2)
  summary(model2)
  anova(model2)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/zczIw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zczIw.png" alt="enter image description here"></a></p>