[R-sig-ME] lme4

Thierry Onkelinx thierry.onkelinx at inbo.be
Tue Jul 18 09:45:00 CEST 2017


Dear Dan,

It looks like you need to do some reading about the theory on mixed models.
The random effects are use to account for a grouping effect which a) we
must take into account and b) are not really interested in the actual
effect. E.g. repeated measurements on the same individual. The measurement
from the same individual are not independent. So solve this by using the
individual id as a random effect.

So you need to think about the grouping in your dataset. One observation
isn't a group ;-)

Best regards,

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

2017-07-18 1:33 GMT+02:00 Dan Selechnik <danselechnik op gmail.com>:

> Hi Ben,
>
> Thank you very much for the reply, but I'm still not sure what exactly is
> the fix here? Every sample has a single ID. Is this my issue...?
>
> Cheers,
> Dan
>
> On Sat, Jul 15, 2017 at 12:10 PM, Ben Bolker <bbolker op gmail.com> wrote:
>
> >
> >
> > On 17-07-14 09:26 PM, Dan Selechnik wrote:
> > > Hello,
> > >
> > > My name is Dan and I'm a PhD student in Australia. I was hoping that I
> > > could ask you for some help with using lme4. I have a dataset in which
> I
> > > have PC1 as a response variable. Population, treatment, RBC, and
> > > population*treatment are my explanatory variables. ID is a random
> factor.
> > > (I have attached the CSV file here)...
> > >
> > > I am trying to run a power analysis, and first to fit my data using
> lmer.
> > >
> > > First I read my data into R:
> > > pc1=read.csv("R-PowerAnalysis.csv", header=TRUE)
> > >
> > > Then I attempt to fit:
> > > fm1=lmer(pc1$PC1 ~ pc1$RBC + pc1$Population + pc1$Treatment +
> > > pc1$Population*pc1$Treatment + (1|pc1$ID), data=pc1, REML=FALSE)
> >
> >    A small point, but in general you should *not* use pc1$ in specifying
> > your formula: instead,
> >
> > fm1=lmer(PC1 ~ RBC + Population*Treatment + (1|ID), data=pc1,
> >     REML=FALSE)
> >
> > (also, the * operator includes both the main effects of Population and
> > Treatment and their interaction). But that should be tangential to your
> > problem.
> >
> > >
> > > However, this fails, returning the message:
> > > Error: number of levels of each grouping factor must be < number of
> > > observations
> > >
> > > My number of populations and treatments is much less than my number of
> > > observations, so I am not sure why I am getting this error...
> >
> >   That's not your problem.  lme4 is referring to the number of levels of
> > the *grouping factor*, which is ID (not Population or Treatment).  Your
> > ID variable must contain a single observation per group (cheating and
> > looking at the data you sent me offline, I can see that's true).
> >
> > If you had sent the results of summary(pc1), we could have guessed this:
> > ID is coded as an integer so we don't know for sure that it consists of
> > the values 1..20, but since the min is 1 and the max is 20 and mean is
> > 10.5, we can guess that that's the case ...
> >
> >        ID        Population         Treatment       RBC
> >  Min.   : 1.00   QLD:10     LPS-Injection:10   Min.   :-113.00
> >  1st Qu.: 5.75   WA :10     PBS-Injection:10   1st Qu.:  22.00
> >  Median :10.50                                 Median :  49.00
> >  Mean   :10.50                                 Mean   :  53.55
> >  3rd Qu.:15.25                                 3rd Qu.: 107.00
> >  Max.   :20.00                                 Max.   : 181.00
> >       PC1
> >  Min.   :-4.5411
> >  1st Qu.: 0.1017
> >  Median : 1.1470
> >  Mean   : 0.6258
> >  3rd Qu.: 1.9251
> >  Max.   : 3.2004
> >
> >
> > Also, when I
> > > run this, it works fine:
> > > fm1=lm(pc1$PC1 ~ pc1$RBC + pc1$Population + pc1$Treatment +
> > > pc1$Population*pc1$Treatment + (1|pc1$ID), data=pc1)
> >
> > If you look at the results of this model:
> >
> > Coefficients:
> >                         (Intercept)                                  RBC
> >                             1.47759                              0.01318
> >                        PopulationWA               TreatmentPBS-Injection
> >                            -1.38234                             -1.85619
> >                          1 | IDTRUE  PopulationWA:TreatmentPBS-Injection
> >                                  NA                              0.24754
> >
> > you can see that something funny is happening to the (1|ID) term ...
> >
> > >
> > > I was hoping I could ask for your assistance in figuring out what may
> be
> > > the problem. Thank you very much.
> > >
> > > Cheers,
> > > Dan
> > > _______________________________________________
> > > R-sig-mixed-models op r-project.org mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> > >
> >
> > _______________________________________________
> > R-sig-mixed-models op r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> >
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-mixed-models op r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>

	[[alternative HTML version deleted]]



More information about the R-sig-mixed-models mailing list