Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting mixed model formula from SAS to R
    primarykey
    data
    text
    <p>I want to fit a mixed model using nlme package in R which is equivalent to following SAS codes:</p> <pre><code>proc mixed data = one; class var1 var2 year loc rep; model yld = var1 * var2; random loc year(loc) rep*year(loc); </code></pre> <p>EDITS: Explanation of what is experiment about </p> <p>the same combination of var1 and var2 were tested in replicates (rep- replicates are numbered 1:3). The replicates (rep) is considered random. This set of experiment is repeated over locations (loc) and years (year). Although replicates are numbered 1:3 within each location and year for covinience because they do not have any name, replication 1 within a location and a year doesnot have correlation replication 1 within other location and other year</p> <p>I tried the following codes:</p> <pre><code> require(nlme) fm1 &lt;- lme(yld ~ var1*var2, data = one, random = loc + year / loc + rep * year / loc) </code></pre> <p>Is my codes correct? </p> <p>EDITS: data and model based on suggestions you can download the example data file from the following link: <a href="https://sites.google.com/site/johndatastuff/mydata1.csv">https://sites.google.com/site/johndatastuff/mydata1.csv</a></p> <pre><code>data$var1 &lt;- as.factor(data$var1) data$var2 &lt;- as.factor(data$var2) data$year &lt;- as.factor(data$year) data$loc &lt;- as.factor(data$loc) data$rep &lt;- as.factor(data$rep) following suggestions from the comments below: fm1 &lt;- lme(yld ~ var1*var2, data = data, random = ~ loc + year / loc + rep * year / loc) Error in getGroups.data.frame(dataMix, groups) : Invalid formula for groups </code></pre> <p>EXPECTED BASED ON SAS OUTPUT</p> <pre><code>Type 3 tests of fixed effects var1*var2 14 238 F value 16.12 Pr &gt;F = &lt; 0.0001 Covariance parameters: loc = 0, year(loc) = 922161, year*rep(loc) = 2077492, residual = 1109238 </code></pre> <p>I tried the following model, I still getting some errors: </p> <pre><code>Edits: Just for information I tried the following model require(lme4) fm1 &lt;- lmer(yld ~ var1*var2 + (1|loc) + (1|year / loc) + (1|rep : (year / loc)), data = data) Error in rep:`:` : NA/NaN argument In addition: Warning message: In rep:`:` : numerical expression has 270 elements: only the first used </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload