R demo | How to visualize models Part 1 | multiple linear models, all assumptions & post-hocs
HTML-код
- Опубликовано: 21 авг 2024
- In this video, we'll visualize in RStudio the results and coefficients of:
- simple linear models with categorical predictor
- simple linear models with numeric predictor
- multiple linear models with numeric and categorical predictors &
- multiple linear models with interactions
...moreover, you'll get:
bonus 1: check and visualize all the assumption in one line of code ... actually in one command!
bonus 2: easy post-hocs ... also one line of R code!
bonus 3: make several models on the same plot quickly! ... without even explicitly modelling! only by using ggplot2 package
Visualizing model results is the best kind of data visualization, because such data is already processed and delivers even more valuable insights than the row data.
The code is provided here: yuzar-blog.net...
Music by Vincent Rubinetti
Download the music on Bandcamp:
vincerubinetti...
Stream the music on Spotify:
open.spotify.c...
Enjoy! 🥳
One of the most detailed and enjoyable statistics videos I have ever seen. So many useful tips here and your passion really shines through. Thanks a lot for this!
Wow, thank you! Glad you liked it! It this old one was helpful, you might enjoy the more recent videos, especially on emmeans package and all kind of modelling, like bootstrap, quantile or glmulti. Thanks for watching! cheers.
@@yuzaR-Data-Science Thank you, working with emmeans at the moment so definitely going to have a look. Have a great day!
@@angusyoung6932 thanks! you too! :)
Dear Dr. Yury Zablotski, thank you very much for this very nice and instructive video. I am looking forward to watching the next one. Congrats! \o/
Thanks a lot, Rafael! I am sooo glad it is useful!!! The second part of it will be online very soon, I already have the code (about the models I promised in the beginning). Just need to record the video. Stay healthy! Cheers!
This is an amazing tutorial! I love this video; scratch that I love all of your videos. Looking forwarding to more videos. Amazing
Thank you so much for such a nice feedback! And for watching! That encourages to do more!
Thank you for this great tutorial video that I am going to use to train my students. Again, thank you and I can't wait for more videos from you.
Dear Eddy, thanks for such a great feedback! It means a lot for me, because I also teach students and colleagues. 😁 In the medical field, where I work, we mostly do classic statistical tests and if this would be of use to you and your students, please, have a look at 3 videos on Box Plots with statistical details I did just recently. My students liked those videos more, since modelling was too fancy and complex for them. Kind regards!
Fantastic!!!!!
So nice of you! Thanks!
This was just awesome, thank you!
Eagerly looking forward to the next video:)
Thanks a ton for such a nice feedback, Aman! 😊 I am already working on the second part of it. Will be online latest next week.
Thanks, just mind bowling crazy stuff. It really force me to switch from Stata to R
Thanks for a nice feedback, Abdulahad! I don't know much about Stata, but I certainly love R! :)
Thank you very much for this video. I think I learned a lot from it. Please also make the R script available, perhaps on Github. That will help us try your techniques with our own data. Thanks again.
Thanks a lot for your feedback Udayan! That helps a lot! :) Yes, I have thought about the code, but my Webside, where I usually keep the code isn't running at the moment. Technical reasons, I am not able to solve. So, I plan to get a github profile and produce a new website (blog) where I'll put all the code in the near future. Unfortunately the day job at the university takes the most of my time, so it might take a wile. But when it is done, I'll add the link to the description of the video. So, please, stay tuned. Kind regards! Yury
Why do `lm()` and `allEffects()` produce different estimates of the mean of the first level of the factor `jobclass` in the additive model with two categorical predictors (the third model in the video)? This anomaly disappears in the interactive model with the same two predictors (the sixth model).
Thank you for doing this. Your videos are always relevant, clear, and well produced.
Dear Ameek, thanks for your question and sorry for the late reply, I needed to work a lot. I checked it and in my case the estimates of "1. Industrial" are both identical to the second decimal (rounded, I guess) place, namely, 103.170 in "summary(m)" and 103.1695 in "allEffects(m)". The CIs might sometimes vary though. Kind regards!
@@yuzaR-Data-Science Hi Yury, Thank you for the reply. Don't worry about the timing though, you do a lot here already, especially given your day job.
I got the estimate you got (103.170) from both `lm()` and `allEffects()` when only one predictor was put into the model (your first model). However, with two predictors [as in your third model, lm(salary ~ jobclass + education, d)], I got different estimates. From `lm()` I got "(Intercept)" equalling 83.9, while from `allEffects()` I got "1. Industrial" equalling 109.08.
# proof that the estimate of the first level of the first factor differs between `lm()` and `allEffects()`
# extracting the estimate produced by `allEffects()`
factor1_level1_allEffects %
allEffects() %>%
pluck("jobclass") %>%
as_tibble() %>%
filter(jobclass == '1. Industrial') %>%
select(fit)
# extracting the estimate produced by plain `lm()`
factor1_level1_lm %
tidy() %>%
filter(term == '(Intercept)') %>%
select(estimate)
isTRUE(factor1_level1_allEffects != factor1_level1_lm)
Hey Ameek, :) nice code, thanks! Yes, now I see where the problem is. In the first model you filter our the jobclass == '1. Industrial', right? But in the second the `(Intercept)` contains both "first" levels of both predictors at the same time, namely, '1. Industrial' from the "jobclass" and `1. < HS Grad` from the "education". The intercept in this model is the reference level for both predictors and for all their categories at the same time.
However, in the model with interactions "jobclass * education", the intercept take the first level of the fists predictor, which happens to be "jobclass". So, the intercept here is the `1. Industrial` of the `1. < HS Grad`, and then everything fits :)
Do we have an equivalent package to "sjplot" in the higher versions of r?
Thank you
What do you mean by the higher version of R? Older?
@@yuzaR-Data-Science My bad, I tried installing the sjPlot package and got an error message. I saw your reply and concluded that I'm the one who made a typo. Everything is ok.
Thank you so much.
Regards
@@fishfish20 no worries :) typos make 90% of my code-mistakes 😁