[R-sig-ME] lmer fits model with counter-intuitive nesting?

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Tue Aug 6 10:10:24 CEST 2013


Dear Björn,

Fit the model like the example below. Which is the same model as your expect with a different parameterization. Then look at the random effects. Notice that the coefficients will be near zero for the combination for which you don't have data.

library(lme4)
set.seed(12345)
dataset <- expand.grid(
  Observation = seq_len(35),
  Phase = factor(c("A", "B")),
  Subject = seq_len(30)
)
dataset$Group <- factor(dataset$Subject <= 15)
dataset$Prob <- rnorm(
  60,
  mean = rnorm(4)[interaction(dataset$Phase, dataset$Group)][interaction(dataset$Phase, dataset$Subject)],
  sd = runif(4)[interaction(dataset$Phase, dataset$Group)][interaction(dataset$Phase, dataset$Subject)]
)[interaction(dataset$Phase, dataset$Subject)]
dataset$Prob <- plogis(dataset$Prob)
dataset$Response <- rbinom(nrow(dataset), size = 1, prob = dataset$Prob)
xtabs(~ Subject + Group, data = dataset)
model <- glmer(Response ~ Phase * Group + (0 + Phase : Group|Subject), data = dataset)
ranef(model)


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
+ 32 2 525 02 51
+ 32 54 43 61 85
Thierry.Onkelinx op inbo.be
www.inbo.be

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

-----Oorspronkelijk bericht-----
Van: r-sig-mixed-models-bounces op r-project.org [mailto:r-sig-mixed-models-bounces op r-project.org] Namens Björn Lindström
Verzonden: maandag 5 augustus 2013 23:19
Aan: Jake Westfall; r-sig-mixed-models op r-project.org
Onderwerp: Re: [R-sig-ME] lmer fits model with counter-intuitive nesting?

Hi, yea I totally agree.

Here is the xtabs output. Looks correct  right?

> xtabs(~Subject+Group, data=data)
       Group
Subject      A            B
     1            70            0
     2             0           70
     3            70            0
     5            70            0
     6             0           70
     7            70            0
     8             0           70
     9            70            0
     10            0           70
     11           70            0
     12            0           70
     13           70            0
     14            0           70
     15           70            0
     16            0           70
     17           70            0
     18            0           70
     19            0           70
     20           70            0
     21            0           70
     22           70            0
     24           70            0
     25            0           70
     26           70            0
     27            0           70
     28           70            0
     29            0           70
     30           70            0

/Björn
________________________________________
Från: r-sig-mixed-models-bounces op r-project.org [r-sig-mixed-models-bounces op r-project.org] för Jake Westfall [jake987722 op hotmail.com]
Skickat: den 5 augusti 2013 22:34
Till: r-sig-mixed-models op r-project.org
Ämne: Re: [R-sig-ME] lmer fits model with counter-intuitive nesting?

Hi Bjorn,

Of course my first thought is that there is a coding error in the dataset. Would be curious to see the output from xtabs(~Subject+Group, data=data) to verify the structure is what it should be...

Other than that I don't really have any ideas.

Jake

From: Bjorn.Lindstrom op ki.se
To: r-sig-mixed-models op r-project.org
Date: Mon, 5 Aug 2013 16:20:59 +0000
Subject: [R-sig-ME] lmer fits model with counter-intuitive nesting?

Dear all, I am a new member (although long time reader) to the list.

My motivation for finally joining is to clearify a (for me) very confusing issue. I apologize beforehand if I have missed any standard or crucial information.

I am analyzing data from a learning experiment with the following structure:

30 subjects with 70 binary resposes each. These respones are ordered by Phase(Factor w/ 2 levels) within subject, where each Phase level is associated with 35 responses.
The subjects are nested within Group(Factor w/ 2 levels), but have an unique index (1:30).

I am interested in the Phase*Group interaction. My orginal model was just lmer(response ~ Group*Phase+(Phase|Subject),family=binomial(link="logit"),data=data), since this seem to be the logical and standard formulation for models with both within and beteen -subjects predictors.

For various obscure reasons, I fitted lmer(response ~ Group*Phase+(Phase*Group|Subject)), which I expected to fail since no Subject belong to both groups (I double checked ...).
However, lmer gladly accepted this and gave by-subject random effects for both the Group effect and the Phase*Groupp interaction.

As far as I see, this situation is identical to trying to fit random slopes for Gender for each subject....

How is this possible? What am i missing?

kind regards
Björn

        [[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]]


_______________________________________________
R-sig-mixed-models op r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
* * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document.
The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document.



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