Hi R-help. I am trying to run a linear mixed model with nested factors with either lme or lmer and I am having no luck obtaining the same results as Minitab. Here is Minitab's code: MTB > GLM 'count' = site year replicate(site year) site*year; SUBC> Random 'year' 'replicate'; Can you tell me how to code this in R? The settings are typeII, Tukey, 95%confidence interval, but I know how to set those in R. I have basic R skills and I've worked with this on and off for several days, and have also consulted some people with basic R experience, but nobody can get it to work as it seems to be a bit complex. I'd prefer to use R rather than Minitab for the research project I'm working on, but the time spent on this problem has gotten to be too much. Thanks in advance. Sincerely, David student - Norway
David: It is unlikely you will get a helpful response to this. Instead, you will improve your chances of a good response if you do three things: 1) Provide a mathematical description of the model you are trying to estimate 2) Provide a description of the data you have 3) Provide some code or any efforts you have made with the lmer function so far. For example, for (1) you might provide something like, "I want a model as" y_ji = mu + beta(x) + u_j + e_ij where x is ... For (2) You can show your data structure as:> str(myData)And for (3) just indicate what you have done so far. For example, I have tried> lmer(response ~ covariate + (1|covariate), myData)> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On > Behalf Of David Dudek > Sent: Monday, March 07, 2011 1:29 PM > To: r-help at r-project.org > Subject: [R] linear mixed model with nested factors > > Hi R-help. > > I am trying to run a linear mixed model with nested factors with either > lme or lmer and I am having no luck obtaining the same results as Minitab. > Here is Minitab's code: > > MTB > GLM 'count' = site year replicate(site year) site*year; > SUBC> Random 'year' 'replicate'; > > Can you tell me how to code this in R? > > The settings are typeII, Tukey, 95%confidence interval, but I know how to > set those in R. > > I have basic R skills and I've worked with this on and off for several > days, and have also consulted some people with basic R experience, but > nobody can get it to work as it seems to be a bit complex. I'd prefer to > use R rather than Minitab for the research project I'm working on, but the > time spent on this problem has gotten to be too much. > > Thanks in advance. > > Sincerely, > David > student - Norway > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Think about it. You have asked for help from the R list but have posted no R code, only Minitab code. That means in order to answer, the helpeR must know Minitab. Well, some may, but there's certainly no reason to expect so on an R list. Don't you therefore think it might be wiser to post a careful description of your study design and the model you wish to fit along with any R code attempting to accomplish this, as the posting guide asks? A minimal reproducible example might also help you get a response. Again, as the posting guide asks. FWIW, if your response variable is a count of some sort, you will probably need glmer in the lme4 package to fit the data, as lme only fits continuous, approximately Gaussian data. But of course, with no details, this is just a guess. -- Bert On Mon, Mar 7, 2011 at 10:29 AM, David Dudek <david.dudek at student.umb.no> wrote:> Hi R-help. > > I am trying to run a linear mixed model with nested factors with either > lme or lmer and I am having no luck obtaining the same results as Minitab. > Here is Minitab's code: > > MTB > GLM 'count' = site year replicate(site year) site*year; > SUBC> ? Random 'year' 'replicate'; > > Can you tell me how to code this in R? > > The settings are typeII, Tukey, 95%confidence interval, but I know how to > set those in R. > > I have basic R skills and I've worked with this on and off for several > days, and have also consulted some people with basic R experience, but > nobody can get it to work as it seems to be a bit complex. I'd prefer to > use R rather than Minitab for the research project I'm working on, but the > time spent on this problem has gotten to be too much. > > Thanks in advance. > > Sincerely, > David > student - Norway > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Bert Gunter Genentech Nonclinical Biostatistics
David Dudek <david.dudek <at> student.umb.no> writes:> > Hi R-help. > > I am trying to run a linear mixed model with nested factors with either > lme or lmer and I am having no luck obtaining the same results as Minitab. > Here is Minitab's code: > > MTB > GLM 'count' = site year replicate(site year) site*year; > SUBC> Random 'year' 'replicate'; > > Can you tell me how to code this in R?Guessing: lmer(count~site+(site|year)+(1|replicate:site:year),data=...) This assumes (1) you're willing to treat your data as normally distributed (see previous comments) (2) you really have multiple samples within each value of 'replicate' (otherwise 'replicate' will be confounded with your residual error) (3) every site is measured in more than one year (most or all years if you want decent power) I'm having a bit of a hard time figuring out what you want to do with 'replicate'. Are replicates coded uniquely, or within sites? If you have multiple samples per replicate, and they are strictly nested, it will probably be easiest to take the averages for each replicate -- then your model would reduce to avgcount~site+(site|year), and the residual error would be the among-replicate within site-year variation.