Building and Comparing Mixed Models in R: ICC, Bayes Factor, and Variance Explained

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ก.พ. 2025
  • The process of comparing mixed models is actually simple!
    Learning Objectives:
    What is the ICC and what does it tell us
    What is the general strategy for doing mixed models?
    Know the estimates of interest
    This video is part of my multivariate playlist: This is part of a playlist on multivariate statistics: www.youtube.co....
    Here are other videos about mixed models:
    • Mixed Models, Hierarch...
    • Mixed Model Notation -...
    • Explaining Variance Ex...
    For more information on using Flexplot, see this link: psyarxiv.com/k...

ความคิดเห็น • 38

  • @SagangaKapaya
    @SagangaKapaya 2 ปีที่แล้ว +2

    Thanks very much, your illustrations are very clear.

  • @srensommer3434
    @srensommer3434 2 ปีที่แล้ว

    And also,you are sharing music theme with It's allways sunny in Philadelphia - Also brings a smile..

  • @dewidinevandercolff3999
    @dewidinevandercolff3999 2 ปีที่แล้ว +2

    You make these things cool! Thanks! I am subscribing!

  • @Pmonfrost
    @Pmonfrost 2 ปีที่แล้ว +1

    Thanks!

  • @FilippoGianburrasca
    @FilippoGianburrasca ปีที่แล้ว +1

    3:54 "we want to fit a fixed slope as well as a random slope" should be "we want to fit a fixed intercept as well as a random intercept", right?

  • @andriismykovskyi2999
    @andriismykovskyi2999 3 ปีที่แล้ว +5

    Hi Dustin. Thanks for your videos, they greatly develop the intuition behind Mixed Models and you also make me laugh sometimes :) . I am using flexplot 0.13.3
    Even though I execute exactly the same lines of code as you in the video:
    baseline

  • @hm.91
    @hm.91 2 ปีที่แล้ว +5

    Thanks for this superb video! I'm using the same data from the flexplot package and running the same code of the video, but unfortunately the visualize function returns for any model (that I copied based on your script):
    Error in if (preds[i] != term.re) { : argument is of length zero
    Why could that be?
    Thanks!

    • @teslanova
      @teslanova 2 ปีที่แล้ว +2

      I had the same problem - turns out its if you've already loaded lmerTest into your library before you run the lmer function to build the models with lme4, it'll return this error. I fixed by just either 1. detaching the lmerTest package until later in the script when its needed or 2. telling r that you want to use the lmer function from lme4 specifically, lme4::lmer(...). From what I can gather the lmerTest overlays the {lme4} lmer function which causes that specific error.
      Hope that helps.

  • @MegaSesamStrasse
    @MegaSesamStrasse 3 ปีที่แล้ว +1

    what would a random effect of the variable minority mean? and why wasn't it tested?

  • @alsayer8726
    @alsayer8726 ปีที่แล้ว

    Hey,
    Thanks very much for the great explanation. Unfortunately, visualize argument does not work, I followed and used the same code you explained, but the argument shows this error "Error in match.arg(plot, c("all", "residuals", "model")) :
    'arg' should be one of “all”, “residuals”, “model”". Any solution?

  • @annawassel1247
    @annawassel1247 3 ปีที่แล้ว +1

    Hmm I'm running this on my personal data, but when I visualize my baseline model (lmer(responsevariable~1+(1|cluster), data= my data), my red line is labeled "object (lmerMod)" instead of fixed effect and the random effects line is missing. Any idea what's causing this? My data set is much smaller than this example set. Could that be it?

  • @brazilfootball
    @brazilfootball 2 ปีที่แล้ว +1

    What does an $icc output of "[1] 1, $design.effect [1] 13.42553" mean?

  • @mingjingchen1238
    @mingjingchen1238 3 ปีที่แล้ว +3

    Thank you for your awesome videos and packages! You are lifesavers and all concepts are clearly explained. But when I tried to rerun the code "visualize(baseline,plot = "model"), there is an error: `_inherit` must be a ggproto object. I am not sure why, thank you for your help!

    • @QuantPsych
      @QuantPsych  3 ปีที่แล้ว +1

      what version of flexplot are you using? Also, maybe show me the code where you create baseline.

    • @mingjingchen1238
      @mingjingchen1238 3 ปีที่แล้ว +1

      @@QuantPsych I am using flexplot (0.11.3), and I used the same code as yours for baseline: baseline=lmer(MathAch~1+(1|School), data = math), error:`_inherit` must be a ggproto object., is it because I used the previous version of flexplot? Except for visualizing baseline, other functions of flexplot work perfect. Thank you for your prompt response. :)

    • @mingjingchen1238
      @mingjingchen1238 3 ปีที่แล้ว +1

      Today I tried my flexplot again and it works now! Thank you for developing such a wonderful package!

  • @annaferrusolapastrana2516
    @annaferrusolapastrana2516 3 ปีที่แล้ว +2

    When I load flexplot it says: Warning in install.packages :
    package ‘flexplot’ is not available (for R version 4.0.0)

    • @QuantPsych
      @QuantPsych  3 ปีที่แล้ว

      I'd post an issue on github (github.com/dustinfife/flexplot)

  • @Jonathan-zd6ns
    @Jonathan-zd6ns 2 ปีที่แล้ว

    Dear professor, can I ask how to show p value for the beta coefficient in summary functions??? Thanks !!!

  • @tatjanajak
    @tatjanajak 3 ปีที่แล้ว +1

    The command "visualize(baseline, clusters=3)" generates: Error in compare.fits(formula, data = k, model1 = object, model2 = object, :
    formal argument "clusters" matched by multiple actual arguments. My baseline is a result of lmer function (i.e. baseline=lmer(data=data.it, y~1+(1|subject)). The visualize function produced same error for various values of cluster. When I omit the cluster, I get the graphic.

    • @QuantPsych
      @QuantPsych  3 ปีที่แล้ว

      Well dang. I'll make a note to investigate this.

  • @luismiguelloperaparra5994
    @luismiguelloperaparra5994 3 ปีที่แล้ว

    Hi. I have clusters built yearly for twenty years. I want do get measures of variabulity ínter cluster and intra cluster but I dont know how to theoretically document my procedure. How can I?

  • @izzthewizz6
    @izzthewizz6 3 ปีที่แล้ว +1

    Hey Dustin, I've been trying to plot the baseline model using flexplot::visualize and keep getting this error:
    Error in if (preds[i] != term.re) { : argument is of length zero
    The model and ICC run fine, I just cant get visualize to work. Dustin or anyone who knows what to do, your help would be appreciated.

  • @rutgervanbasten2159
    @rutgervanbasten2159 ปีที่แล้ว

    Hi! , you conclude that SES needs to be included as a FIXED effect (hence a fixed slope ).
    Then you add minority to the model/
    However, in the model "minority" you have added SES to have a random intercept and slope per school (SES | school) .
    Shouldt you add have the model to be
    minority_fixed

  • @morriskrainz3997
    @morriskrainz3997 2 ปีที่แล้ว

    Hi there,
    thanks for the great videos, they are super helpful! I am currently trying to interpret model fits of fixed and random slopes models and am a bit confused regarding R-squared-change:
    > model.comparison(intensity_model_predicted, intensity_model_predicted_RS)
    refitting model(s) with ML (instead of REML)
    $statistics
    aic; bic; bayes.factor; p
    intensity_model_predicted 1146.993; 1161.407; 1851.166; 0.097
    intensity_model_predicted_RS 1147.626; 1176.454; 0.001
    $predicted_differences
    0% 25% 50% 75% 100%
    0.012 0.898 2.407 4.703 25.677
    $r_squared_change
    (Intercept) Residual
    -0.3032796 -0.6475945
    From the $statistics output, I'd conclude that the model in the upper row (fixed effects model) probably explains the data much more accurately than the random slopes model (lower aic, bic, and very high bayes factor) BUT then when I look at $r_squared_change it seems like the random slopes model explains much more variance (since the R^2 change is a negative number)? Is that the correct interpretation or have I got something wrong here?

  • @srishtitripathi8543
    @srishtitripathi8543 3 ปีที่แล้ว

    Thank you for your nice videos. Where can I get the data set you are using in this video?

    • @QuantPsych
      @QuantPsych  3 ปีที่แล้ว

      It's embedded in the flexplot package.

  • @francescamalcangi8221
    @francescamalcangi8221 3 ปีที่แล้ว

    which version of R do you have, because mine doesn't install flexpot package

    • @QuantPsych
      @QuantPsych  3 ปีที่แล้ว

      Are you installing through github?
      install.packages("devtools")
      devtools::install_github("dustinfife/flexplot")

  • @bumblebee7597
    @bumblebee7597 ปีที่แล้ว

    How can we take classes with you?

    • @zimmejoc
      @zimmejoc ปีที่แล้ว +1

      he just posted a new vid a couple days ago where you can take a class with him in the near future.

    • @bumblebee7597
      @bumblebee7597 ปีที่แล้ว

      @@zimmejoc thank you so much!

  • @AmanzholBekmagambetov
    @AmanzholBekmagambetov 3 ปีที่แล้ว

    Hello. On 14.35, did you mean to say that school doesn't have any NON-minorities?

    • @QuantPsych
      @QuantPsych  3 ปีที่แล้ว +1

      Yes. Good catch!

  • @bumblebee7597
    @bumblebee7597 ปีที่แล้ว

    Great explanation! However I'm sure the minority kids in the dataset didn't include indian American kids! 😂