[R-sig-ME] contextual effects in 3-level models

Thierry Onkelinx th|erry@onke||nx @end|ng |rom |nbo@be
Thu Sep 9 17:53:34 CEST 2021


Dear Timothy,

This won't work as your averaged X's will be highly correlated with each
other and with the original X.

I often find it easier to reason on a mathematical model. How would you
translate your 'contextual' effects into an equation? Or at least
clarify what a 'contextual' effect is.

Best regards,

ir. Thierry Onkelinx
Statisticus / Statistician

Vlaamse Overheid / Government of Flanders
INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND
FOREST
Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
thierry.onkelinx using inbo.be
Havenlaan 88 bus 73, 1000 Brussel
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
///////////////////////////////////////////////////////////////////////////////////////////

<https://www.inbo.be>


Op do 9 sep. 2021 om 17:38 schreef Timothy MacKenzie <fswfswt using gmail.com>:

> Dear Colleagues,
>
> I'm revising my question for better clarity. Suppose we have two
> nested grouping variables (ID1 and ID2). The data structure looks like
> below.
>
> To obtain the contextual effects for ID1 and ID2, I wonder which
> option is appropriate?
>
> #-- Option 1: Create mean of X across ID1 (X_ave_ID1) and mean of X
> across ID2 *ignoring* ID1 (X_ave_ID2)
> #-- Option 2: Create mean of X across ID1 (X_ave_ID1) and mean of X
> across ID2    *within*  ID1 (X_ave_ID2)
>
> For both options, then, I will fit (in lme4::lmer()):
>
> y ~ X + X_ave_ID1 + X_ave_ID2 + (1 | ID1 / ID2)
>
> Thank you,
> Tim
>
> #------ DATA  STRUCTURE AND R CODE:
>
> ID1    ID2                   X                      y
> 1       1                       0.474111397    1.9534671
> 1       1                      -0.712228120   0.9355230
> 1       2                      -0.009957293   1.1088756
> 1       2                      -1.237918646   0.8675550
> 2       1                      -0.554944765   2.7831133
> 2       1                      -0.320668268   0.1479290
> 2       2                       1.066993108   0.1688187
> 2       2                     -1.084870417    1.0536264
>
> library(dplyr)
>
> #-- Option 1:
>     data %>%
>     group_by(ID1) %>%
>     mutate(X_ave_ID1 = mean(X)) %>%
>     group_by(ID2) %>%
>     mutate(X_ave_ID2 = mean(X))
>
> #-- Option 2:
>   data %>%
>   group_by(ID1) %>%
>   mutate(X_ave_ID1 = mean(X)) %>%
>   group_by(ID2, .add = TRUE) %>%
>   mutate(X_ave_ID2 = mean(X))
>
> On Mon, Sep 6, 2021 at 1:31 PM Timothy MacKenzie <fswfswt using gmail.com>
> wrote:
> >
> > Dear All,
> >
> > Suppose X is a continuous predictor that can vary within and between
> > two nested grouping variables in a 3-level linear mixed model:
> >
> > effect.size ~ X + (1 | studies/outcomes)
> >
> > How can I obtain the within effect of X, contextual effect of X at
> > level 2, and contextual effect of X at level 3?
> >
> > I can think of two options but wonder which one makes more sense
> > (below)?   For both options, I will fit:
> >
> > effect.size ~ X + X_ave_study + X_ave_outcome + (1 | studies/outcomes)
> >
> > Thank you,
> > Tim
> >
> > library(dplyr)
> >
> > #-- Option 1:
> >     data %>%
> >     group_by(study) %>%
> >     mutate(X_ave_study = mean(X)) %>%
> >     group_by(outcome) %>%                         ## Here mean of
> > outcome *ignoring* studies is computed
> >     mutate(X_ave_outcome = mean(X))
> >
> > #-- Option 2:
> >   data %>%
> >   group_by(study) %>%
> >   mutate(X_ave_study = mean(X)) %>%
> >   group_by(outcome, .add = TRUE) %>%     ## Here mean of outcome
> > *within* each study is computed
> >   mutate(X_ave_outcome = mean(X))
>
> _______________________________________________
> R-sig-mixed-models using 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