title: How to construct custom correlation structure for mixed models in nlme
body: <p>I am trying to fit a linear mixed model in the <code>R</code> package <code>nlme</code>, using the <code>lme</code> function.  There are a number of commonly-used correlation structures available to be used as values for the <code>correlation</code> argument.  However, I would like to define a custom correlation structure.  Based on the documentation, I believe that this is possible, but I don't understand their instructions well enough to implement it.  As an example, suppose I want to use the following correlation structure: </p>
  
  <p><a href="https://i.stack.imgur.com/yjvy4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yjvy4.png" alt="enter image description here"></a></p>
  
  <p>How would I set the <code>correlation</code> argument of <code>lme</code> to this structure?</p>
  
  <p>I provide a toy data set below, in case setting the <code>correlation</code> argument requires it.</p>
  
  <pre><code># independent variable
  x &lt;- rnorm(3)
  
  # effect of independent variable on dependent variable
  slope &lt;- 2
  
  # error term
  error &lt;- rnorm(3, sd = 1/4)
  
  # making successive independent variable observations correlated
  alpha &lt;- 0.5
  y &lt;- c()
  y[1] &lt;- slope * x[1] + error[1]
  for (i in 2:length(x)){
    y[i] &lt;-  (1 - alpha) * (slope * x[i] + error[i]) + alpha * y[i-1]
  }
  </code></pre>