Fitting mixed models in R (with lme4)

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ต.ค. 2024
  • Learning Objectives:
    Understand lmer syntax (fixed, random, cluster)
    Understand how to interpret fixed effect parameters
    Here's the dataset I'm using: quantpsych.net...
    Here's my video that shows you how to identify your cluster variable: • How to identify your c...
    Here's a video about how to determine whether an effect is fixed or random: • How to decide whether ...
    Link about EDA versus CDA: • Ethics in Statistics P...
    My Multivariate playlist: • Multivariate Statistics
    And here's a paper I wrote about my eight step approach to data analysis: psyarxiv.com/r...
    Undergraduate curriculum playlist (GLM-based approach): www.youtube.co....
    Graduate curriculum playlist (also GLM-based approach): www.youtube.co....
    Exonerating EDA paper: psyarxiv.com/5...
    Download JASP (and visual modeling module): www.jasp-stat.org

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

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

    Yes, I know my head is in the way of the output. Sorry! But you should still get an idea of how to do these things in R.

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

      When will you upload the next video? I'm desperately waiting for it!

  • @martinabautista
    @martinabautista 8 หลายเดือนก่อน +3

    You're funny. I feel glad to came across your content!! I'm using lme4 for my dissertation project

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

    07:40 unfortunately your head is blocking the summary table you are talking about :d
    5 referred to fixed effect intercept estimate
    3.261 referred to random effects residual Variance
    1.8 referred to random effects residual SD
    cba to do it for the next table atm

  • @vinitalec
    @vinitalec 3 หลายเดือนก่อน +1

    Your videos are excellent!Thanks for helping me understand this subject.

  • @interwebzful
    @interwebzful หลายเดือนก่อน +1

    i know this is an annoying comment but pretty sure lme4 took so long to install not because it's a "big library" so much as because it was also compiled for your system. anyway, great content, thank youuu

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

    In the CSV file, the variable is named dojo_id not jedi_id. I always tell my students, "KNOW THY DATA" and that applies to me too. Bad zim for blindly typing what was in the video instead of verifying with the data first :)

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

    Interested in your view about the following question. Your third model allows slope(darkness,anger) to depend on jedi_id. You could also just add an interaction term darkness*factor(jedi_id) right? Assuming this model is identifiable (and I think it is because anger is varying over time within jedi_id) what is the value of the random effects model which makes the arbitrary assumption that the jedi-specific slopes follow a normal distribution?

  • @mykiawiggins3318
    @mykiawiggins3318 9 หลายเดือนก่อน +1

    Not a fistbump...😳You punched my face!🤣😂
    Thank goodness for your videos you're so frrreakin FUNNIEEEEE!

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

    As always, love ur videos, specially if they involve R. However, while it did not prevent me from following you, your face camera occluded the results window..just being picky :)
    Different topic...do u consider uploading some machine learning tutorial for dummies?

  • @elena.s.v.
    @elena.s.v. 7 หลายเดือนก่อน

    Hello! Thank you for your videos, they help a lot. Would it be possible to get more information about the warnings one gets when fitting a random effect model, called "full" in your videos (e.g. singularity, did not converge, etc.) and how to solve them? I used the model comparison to verify whether I should fit a variable as a fixed effect only or as a fixed/random effect and some of my "full" models do not converge or "are singular". I also get warnings when trying to fit my final models (linear mixed model and generalized mixed models (poisson and negative binomial). Thank you for your help!

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

    This was extremely helpful... Thank you so much for this!

  • @EmmaCalikanzaros
    @EmmaCalikanzaros 8 หลายเดือนก่อน

    Thanks, I found your video super helpful. Could you explain what it means when the error "singular model" apprears?

  • @toribentley2409
    @toribentley2409 26 วันที่ผ่านมา

    i have a repeated measures dataset. there are 90 patients with 3 observations each(at baseline 6 months and 12 months), so when made long i will have a dataset of 270 rows. The issue is i have a situation where 57 out of the 270 observations have missing data at 6months and 12months. How do i approach modelling this data using lmer? do i need to handle missing values or just model it like that? I would appreciate if you can help me or possibly we can even hop on a call, really need hep right now

    • @QuantPsych
      @QuantPsych  26 วันที่ผ่านมา

      No need to handle missing data, assuming the data are MAR or MCAR. lmer will drop them, but it will still estimate a regression line for those missing data at 6/12 months. You might have convergence issues, but the estimation should be unbiased (again, provided it's mar or mcar).

  • @taranaferdous2858
    @taranaferdous2858 5 หลายเดือนก่อน

    Hi! Thank you for this clear explanation. I followed the same for my data (data is in the same format that you have shown). My models worked fine up to fixed part. The moment I added the random part (1 + *** | ID), I got this error : number of observations (=100) < = number of random effect for term (1 + *** | ID).
    What am I missing here or doing wrong?

    • @IbrahimKwakuDuah
      @IbrahimKwakuDuah 5 หลายเดือนก่อน

      It is not 1+*, I guess the * would mean everything but you can't do everything

  • @nikashomeil2369
    @nikashomeil2369 5 หลายเดือนก่อน

    Thank you so much for your wonderful video, I have a question, I have a model in which my fixed effect has 3 levels but when I ask for the summary one of the levels is not reported in the fixed effect, do you have any idea why is that?

  • @EikeRo
    @EikeRo 5 วันที่ผ่านมา

    This video is quite old but maybe you see it. Can I have multiple cluster variables? my dataset is over multiple years and in different areas. So as I understand it I would cluster it by the year but also to the areas?

    • @QuantPsych
      @QuantPsych  5 วันที่ผ่านมา +1

      You can, but it's more complicated and I don't have any videos on that. But you can google something like "3 level mixed models"

    • @EikeRo
      @EikeRo 5 วันที่ผ่านมา

      @@QuantPsych Wow thanks for the quick answer! I don't even know if its necessary 🐒

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

    awesome video. I have a question : I have two clustering variables for a finance dataset where data is nested in banks and scores are time series reported quarterly. How to include the variable date in the script for the fixed model :
    fixed_y = lmer(y ~ 1 + x1 + x2 + x4 + x4 + (1 | Bank))

    • @QuantPsych
      @QuantPsych  7 หลายเดือนก่อน +1

      Good question. I think the proper notation is "...(1|Bank:Time)"

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

    Hi prof Fife, I have a question for you: let's assume you want to add age_started as a predictor of darkness. Of course age_started doesn't vary within each level of the jedi_id cluster variable (i.e., each jedi has just a unique value of age_started). Could you add it with no problems? Is it possible to use age_started as fixed effect + jedi_id as random effect together? Or would you encounter some separation / convergence issues? I'm struggling to understand this point but I feel kind of lost. Thank you for your enlightening videos!

  • @EW-to9sr
    @EW-to9sr 2 ปีที่แล้ว

    Hello, thanks for uploading these tutorial videos. I'm a uni student trying to understand statistics in R and I found your channel is extremely helpful, thanks!
    Besides, I'd like to know is it reasonable to consider a factor as fixed and random at the same time?
    Looking forward to seeing you how explain the mixed model in following videos!

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

      Yes. All random effects also have fixed effects. You cannot have a random effect without a fixed effect.

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

    Head's in the way bro! 😜
    Still luvs ya videos though, as always thanks for sharing 😊

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

    Thank you..
    If you can explain the difference between the model with ~1 and the last one, I 'd really appreciate that..

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

      ~1 just means to fit an intercept. If it's omitted, R will fit an intercept anyway. The first model (baseline) has to have it because there are no predictors (i.e., fitting this will throw an error: lmer(y~ ( | id), data=d)). For the remaining models, it's redundant, but I put it there so you can easily track what I've added to the model.

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

    In there a scenario where makes sense to have random slope and intercept for jedi_id? If so, how would you code it? thx

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

      I'm not sure I understand your question...cluster variables don't have random slopes and intercepts. Variables do.

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

    Cool, but if we could actually see the output while you're interpreting it and not your face, that would be tremendously helpful. Informative nonetheless 👍.

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

    Hey, i really like your video and your way of explaining things. Way clearer and simpler than other channels out here :D it is a great example on how mixed models work. However, i may have an understanding problem when it comes to the data format. At 3:40 you say that in their first year, when they are 5, they already killed someone. Does the dataset offers any time-specific variable? because the 5 stands for the point in time they started training, which should be always the same when looking at one jedi. (here jedi_id = jedi_1). Did I miss something? I'm only a poliscience student who stumbled upon that one :)

    • @QuantPsych
      @QuantPsych  7 หลายเดือนก่อน +2

      Ah, good point.
      I was getting really worried that five year olds were murdering people, but you're right. They might have waited until they were seven :)

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

    Dear Dustin I really enjoy your videos and love flexplot, but you always fit linear models. I'm a neonatologist, and almost 90% of my outcomes are binary o dichotomous. Is it possible to give usa video about non linear mixed models, aka logistic, ordinal etc.. ? I guess you'll use the nlme function but I'd really love to have your explanations. Thanks!!!

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

      I'm pretty sure I made a generalized mixed model video. I think it was poisson mixed models, but it might have been logistic. Just take my logistic regression videos, combine those with my mixed models videos, and you'll get it.

  • @mind_palace
    @mind_palace 6 หลายเดือนก่อน

    Repeated measures....to make sense of it, I'd say it could be that every measure per jedi_id, could be the therapist measuring their anger level for every session?

    • @QuantPsych
      @QuantPsych  6 หลายเดือนก่อน

      That works :)

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

    Definitely not watching this as a SAS to R transplant for my dissertation 😂

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

    Your head is in front of the output 😕

    • @QuantPsych
      @QuantPsych  7 หลายเดือนก่อน

      I can't help having a fat head :)

  • @JohnstoneYves-i4y
    @JohnstoneYves-i4y 7 วันที่ผ่านมา

    Ignacio Wells

  • @NellyIvy-r3v
    @NellyIvy-r3v 25 วันที่ผ่านมา

    Lera Ferry

  • @BaconYedda
    @BaconYedda 24 วันที่ผ่านมา

    9292 Jordi Place

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

    Why is it a 1? You reallj don't know? C'mon man! (Just call me Joe Biden). It obviously refers to a column of 1's in the design matrix.

  • @diptarshis
    @diptarshis 6 หลายเดือนก่อน

    Could you please stop with the clowning and get on with the explanations. Your attempt at deadpan humor sucks. You're way better at teaching, do that please !

    • @QuantPsych
      @QuantPsych  6 หลายเดือนก่อน +1

      No, it's so deeply ingrained in my personality. I do me, you do you.
      And it seems you're outvoted. Everyone else seems to like it :)