[R-sig-eco] LMER: applying a random term to only one level of a factor

Aislinn Pearson aislinn.pearson at rothamsted.ac.uk
Thu Apr 7 16:47:20 CEST 2016


Thank you very much for your help Bob. I think that's a great idea.

-----Original Message-----
From: R-sig-ecology [mailto:r-sig-ecology-bounces at r-project.org] On Behalf Of r-sig-ecology-request at r-project.org
Sent: 07 April 2016 11:00
To: r-sig-ecology at r-project.org
Subject: R-sig-ecology Digest, Vol 97, Issue 1

Send R-sig-ecology mailing list submissions to
        r-sig-ecology at r-project.org

To subscribe or unsubscribe via the World Wide Web, visit
        https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
or, via email, send a message with subject or body 'help' to
        r-sig-ecology-request at r-project.org

You can reach the person managing the list at
        r-sig-ecology-owner at r-project.org

When replying, please edit your Subject line so it is more specific than "Re: Contents of R-sig-ecology digest..."


Today's Topics:

   1. LMER: applying a random term to only one level of a       factor
      (Aislinn Pearson)
   2.  model II regression with random effects (Pedro Daleo)
   3. Re: LMER: applying a random term to only one level of a
      factor (Bob O'Hara)
   4. Re: model II regression with random effects (Frank Berninger)


----------------------------------------------------------------------

Message: 1
Date: Wed, 6 Apr 2016 18:12:45 +0000
From: Aislinn Pearson <aislinn.pearson at rothamsted.ac.uk>
To: "r-sig-ecology at r-project.org" <r-sig-ecology at r-project.org>
Subject: [R-sig-eco] LMER: applying a random term to only one level of
        a       factor
Message-ID:
        <HE1PR01MB146651B6E10E09C6C0B07597C99F0 at HE1PR01MB1466.eurprd01.prod.exchangelabs.com>

Content-Type: text/plain; charset="UTF-8"

Hi,

I've tried googling this but haven't been very successful. Essentially, I'd like to know what is the most statistically valid way of dealing with a random term which doesn't apply to every level of fixed-effect factor.

I have a mixed effect model that looks like this

Disease level <- weight + Flown +(1|DateFlown)

Either I flew my insects on a flight mill (which can be thought of as a 'treadmill' for flying insects) or I didn't, hence flown is a two level factor (Yes or No) and I want to understand how this affects the amount of disease in my insect. To get as many replicates as I could on a single day, I had two different banks of flight mills (A & B), each bank containing 16 individual insect treadmills. The insects were randomly assigned to one of the two sets of 16 flight mills. Previous studies tell me there are differences between these two sets of flight mills, so I would like to account for them as a random term in my model.

However, I can't run this in LMER. When I tried I got the error;

Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
  contrasts can be applied only to factors with 2 or more levels

Which I imagine means that one of my factors (i.e. Flown) doesn't include any levels for the random term mill set (i.e. for all unflown insects the value in the mill set column is NA)

Is it possible to include this form of experimental design in LMER (the package I know best) or, alternatively, nlme (which I am a lot less accustomed to using)?

I would be really grateful if anyone has any insight.

Many thanks

Rothamsted Research is a company limited by guarantee, registered in England at Harpenden, Hertfordshire, AL5 2JQ under the registration number 2393175 and a not for profit charity number 802038.



        [[alternative HTML version deleted]]



------------------------------

Message: 2
Date: Wed, 6 Apr 2016 16:05:19 -0300
From: Pedro Daleo <pdaleo at mdp.edu.ar>
To: r-sig-ecology at r-project.org
Subject: [R-sig-eco]  model II regression with random effects
Message-ID:
        <CAE_yG=uoupq3ZCDLh0bNk+HmSMbpcjT0yzFq7s8snXz+LNiXEA at mail.gmail.com>
Content-Type: text/plain; charset="UTF-8"

Hi all,

Do any of you know if there is any package to perform model II regressions with random effects?

Thanks,
Pedro


--
Pedro Daleo
Laboratorio de Ecologia
IIMyC (CONICET-UNMdP)
Mar del Plata
*ARGENTINA*

        [[alternative HTML version deleted]]



------------------------------

Message: 3
Date: Thu, 7 Apr 2016 09:29:25 +0200
From: "Bob O'Hara" <bohara at senckenberg.de>
To: r-sig-ecology at r-project.org
Subject: Re: [R-sig-eco] LMER: applying a random term to only one
        level of a factor
Message-ID: <57060C55.1090101 at senckenberg.de>
Content-Type: text/plain; charset=windows-1252; format=flowed

On 06/04/16 20:12, Aislinn Pearson wrote:
> Hi,
>
> I've tried googling this but haven't been very successful. Essentially, I'd like to know what is the most statistically valid way of dealing with a random term which doesn't apply to every level of fixed-effect factor.
>
> I have a mixed effect model that looks like this
>
> Disease level <- weight + Flown +(1|DateFlown)
>
> Either I flew my insects on a flight mill (which can be thought of as a 'treadmill' for flying insects) or I didn't, hence flown is a two level factor (Yes or No) and I want to understand how this affects the amount of disease in my insect. To get as many replicates as I could on a single day, I had two different banks of flight mills (A & B), each bank containing 16 individual insect treadmills. The insects were randomly assigned to one of the two sets of 16 flight mills. Previous studies tell me there are differences between these two sets of flight mills, so I would like to account for them as a random term in my model.
As a practical matter, it's not worth setting a level with two levels as
random: you don't gain anything in the analysis and the variance component is really poorly estimated. In practice, this might actually make things cleaner, as you will have to look a bit more at the flight mill effects, so you should get a better feel for what's happening.

> However, I can't run this in LMER. When I tried I got the error;
>
> Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
>    contrasts can be applied only to factors with 2 or more levels
>
> Which I imagine means that one of my factors (i.e. Flown) doesn't
> include any levels for the random term mill set (i.e. for all unflown
> insects the value in the mill set column is NA)
>
> Is it possible to include this form of experimental design in LMER (the package I know best) or, alternatively, nlme (which I am a lot less accustomed to using)?
I can think of two ways of doing this: either set up a factor with three levels (Flight mill A, Flight mill B, Not Flown) or set the Not Flown to one of the flight mill levels. The first way feels less confusing, but you might have to set up some contrasts to estimate the differences. But hopefully your insects will cooperate nicely and make the difference between the flight ills will be much smaller than between flight mills and not flown.

HTH

Bob

> I would be really grateful if anyone has any insight.
>
> Many thanks
>
> Rothamsted Research is a company limited by guarantee, registered in England at Harpenden, Hertfordshire, AL5 2JQ under the registration number 2393175 and a not for profit charity number 802038.
>
>
>
>       [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


--

Bob O'Hara

Biodiversity and Climate Research Centre Senckenberganlage 25
D-60325 Frankfurt am Main,
Germany

Tel: +49 69 7542 1863
Mobile: +49 1515 888 5440
WWW:   http://www.bik-f.de/root/index.php?page_id=219
Blog: http://blogs.nature.com/boboh
Journal of Negative Results - EEB: www.jnr-eeb.org



------------------------------

Message: 4
Date: Thu, 7 Apr 2016 10:41:13 +0300
From: Frank Berninger <frankberninger at gmail.com>
To: r-sig-ecology at r-project.org
Subject: Re: [R-sig-eco] model II regression with random effects
Message-ID: <57060F19.9080606 at gmail.com>
Content-Type: text/plain; charset=windows-1252

I think one way of making correct inferences from similar problems would be to make a Bayesian regression with error in variables and grouped errors.

Using Laplaces demon in R (the package is not anymore in CRAN but seems still to run and can be downloaded from the maintainer (an enterprise called Bayesian inference) it should be quite straightforward to set the analysis up.


Frank
On 04/06/2016 10:05 PM, Pedro Daleo wrote:
> Hi all,
>
> Do any of you know if there is any package to perform model II
> regressions with random effects?
>
> Thanks,
> Pedro
>
>



------------------------------

Subject: Digest Footer

_______________________________________________
R-sig-ecology mailing list
R-sig-ecology at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology

------------------------------

End of R-sig-ecology Digest, Vol 97, Issue 1
********************************************



Rothamsted Research is a company limited by guarantee, registered in England at Harpenden, Hertfordshire, AL5 2JQ under the registration number 2393175 and a not for profit charity number 802038.



More information about the R-sig-ecology mailing list