Equivalent R script for repeated measures SAS script, nested design <p>I'm having trouble converting an SAS script to the corresponding R script.</p> <p>The model is a repeated measures analysis of the response (<code>resp</code>) based on treatment (<code>trt</code>) with plot (<code>plot</code>) nested in the treatment.</p> <p>SAS code:</p> <pre><code>data data_set; input trt $ plot time resp; datalines; Burn 1 1 27 Burn 1 9 25 Burn 1 12 18 Burn 1 15 21 Burn 2 1 5 Burn 2 9 15 Burn 2 12 10 Burn 2 15 12 ... Unburn 1 1 57 Unburn 1 9 46 Unburn 1 12 49 Unburn 1 15 51 Unburn 2 1 43 Unburn 2 9 59 Unburn 2 12 59 Unburn 2 15 60 proc mixed data = data_set; class trt plot time; model resp = trt time trt*time / ddfm = kr; repeated time / subject = trt(plot) type = vc rcorr; run; </code></pre> <p>R code attempted (loading the data set from a CSV file):</p> <pre><code>library(nlme) data.set &lt;- read.csv( "data_set.csv" ) data.set$plot &lt;- factor( data.set$plot ) data.set$time &lt;- factor( data.set$time ) model1 &lt;- lme( resp ~ trt + time + trt:time, data = data.set, random = ~1 | plot ) </code></pre> <p>This works, but isn't the desired model. Other attempts I've tried have generally resulted in the error:</p> <pre><code>Error in getGroups.data.frame(dataMix, groups) : invalid formula for groups </code></pre> <p>Basically I'm off in the weeds here...</p> <p>Question 1: how to specify the same model in R as what is already specified in SAS?</p> <p>Question 2: I want to be able to change the covariance matrix to replicate other work done in SAS. I believe I know how to do this with the correlation parameter for the lme function. But please correct me if I'm wrong.</p> <p>Thanks in advance.</p>