title: nlme with correlation structure not fitting and crashes R
body: <p>I have a mixed model with a non-linear term, so I would like to use the R package <code>nlme</code> instead of <code>lme</code>. However, switching to <code>nlme</code>, even without adding anything to the model, causes Rstudio and R to crash.</p>
  <p>I have found that even generated data, which can easily be fitted using <code>lme</code>, causes this behaviour (on my computer).</p>
  <p>Let's start by loading the libraries and setting up a <code>data.frame</code> with the grouping <code>id</code> and spatial coordinate <code>x</code>.</p>
  <pre><code>library(nlme)
  
  nid &lt;- 300
  nx &lt;- 10
  
  data &lt;- expand.grid(
    x = seq(nx),
    id = seq(nid)
  )
  </code></pre>
  <p>Now, let's add correlated error and uncorrelated error as separate columns, as well as a random intercept value per <code>id</code>. The output of <code>arima.sim</code> requires a normalisation step.</p>
  <pre><code>data$ec &lt;- c(
    replicate(
      nid,
      as.numeric(
        arima.sim(
          model = list(
            order = c(1, 0, 0),
            ar = 0.5
          ),
          n = nx
        )
      )
    )
  )
  data$ec &lt;- data$ec / sd(data$ec)
  data$eu &lt;- rnorm(nid * nx)
  data$random &lt;- rep(rnorm(nid), each = nx)
  </code></pre>
  <p>Now, we can create 3 dependent variables, for 3 models. The first is a mixed model with uncorrelated (regular) error. The second includes an exponential (AR1) correlation structure. The third combines both. I am adding an intercept of 1, an sd of the random effect of 2 and an sd of the total residual error of 3.</p>
  <pre><code>data$y1 &lt;- 1 + 2 * data$random + 3 * data$eu
  data$y2 &lt;- 1 + 2 * data$random + 3 * data$ec
  data$y3 &lt;- 1 + 2 * data$random + sqrt(8) * data$ec + sqrt(1) * data$eu
  </code></pre>
  <p>All of the following <code>lme</code> models fit without problem, giving the expected result.</p>
  <pre><code>l1 &lt;- lme(
    fixed = y1 ~ 1,
    random = ~ 1 | id,
    data = data,
    method = &quot;ML&quot;
  )
  l2 &lt;- lme(
    fixed = y2 ~ 1,
    random = ~ 1 | id,
    correlation = corExp(
      form = ~ x | id
    ),
    data = data,
    method = &quot;ML&quot;
  )
  l3 &lt;- lme(
    fixed = y3 ~ 1,
    random = ~ 1 | id,
    correlation = corExp(
      form = ~ x | id,
      nugget = TRUE
    ),
    data = data,
    method = &quot;ML&quot;
  )
  </code></pre>
  <p>As far as I know, the following <code>nlme</code> code specifies exactly the same models as above. The first runs without issues. But the ones with a correlation structure crash R / RStudio. No warning or error message is provided. Fiddling with the arguments and with <code>nlmeControl</code> does not help, though I do think <code>nlmeControl</code> could be the place to search for a solution.</p>
  <pre><code>nlme(
    model = y1 ~ b0,
    fixed = b0 ~ 1,
    random = b0 ~ 1,
    group = ~ id,
    data = data,
    start = list(
      fixed = fixed.effects(l1),
      random = setNames(random.effects(l1), &quot;b0&quot;)
    ),
    method = &quot;ML&quot;
  )
  nlme(
    model = y2 ~ b0,
    fixed = b0 ~ 1,
    random = b0 ~ 1,
    group = ~ id,
    correlation = corExp(
      form = ~ x
    ),
    data = data,
    start = list(
      fixed = fixed.effects(l2),
      random = setNames(random.effects(l2), &quot;b0&quot;)
    ),
    method = &quot;ML&quot;
  )
  nlme(
    model = y3 ~ b0,
    fixed = b0 ~ 1,
    random = b0 ~ 1,
    group = ~ id,
    correlation = corExp(
      form = ~ x,
      nugget = TRUE
    ),
    data = data,
    start = list(
      fixed = fixed.effects(l3),
      random = setNames(random.effects(l3), &quot;b0&quot;)
    ),
    method = &quot;ML&quot;
  )
  </code></pre>
  <p>Has anyone experienced this before? Does my example code give the same problem on your computer? What are good strategies to change <code>nlmeControl</code> to attempt to remedy this?</p>