-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data vis 2 tutorial: mixed effect models #155
Comments
Hey @beverlytan ! There is a slight difference between
When you ask for Have you tried And if it has to be the lmer syntax, you can try So once those things are resolved, I think you should add the When you do that, could you also split this code chunk in two with some brief text in between, like "and now we will repeat the same actions for Narnia" or whatever, just so that the content is not all at once. Ugh, the image won't load, it's the code chunk that has the matrix multiplication stuff. Last question - this tutorial is scheduled to be delivered as a workshop on the 30th January - since you've spent so much time working on it, do you want to be a tutor for that workshop? No worries if not, just thought I should ask. |
Hi @gndaskalova , sorry for the late reply. Unfortunately, all of the following gives the problem of ggpredict expecting 6 values, while the model gives 42 instead.
Therefore, I tried out the lmer syntax, but I still can't make it the same as Haydn's. Doing the following all tells me that "Error: number of levels of each grouping factor must be < number of observations".
So I don't really know what to do hahaha. Actually I'm confused as to why even the graph produced by (1|plot) + (1|year) would look similar to what Hadyn's ~1|year produced, even though like you said that there is a slight difference? Or maybe the difference in whether theyre nested / independent is not relevant in this case? |
Hey @sandra-ab I was wondering if perhaps you might be able to help with this one? |
Hiya! Pitching in my two cents, hope I understand the issue(s) right. First, as for the model specification: I don’t think it’s right to nest year within plot (Haydn might disagree, but I always use year as a crossed, not a nested random effect). I would probably update the tutorial to change that. The logic behind that is that all the samples/plots/regions experience more similar conditions in one given year compared to the next, if that makes sense. The reason you get the error message about the number of observations is that you have only one observation per plot per year, so you can’t calculate variance on that. Therefore, I would specify the syntax as Beverly initially did:
(I get a singular fit for Hogsmeade, so I switched to Narnia for the example.) Also note that I created a new variable Second, when it comes to plotting the effects: I think one problem here is that the To plot fixed effect estimates accounting for the random effect structure, you need to specify Sadly, because Hogsmeade has a singular fit, it won’t give confidence intervals and I can’t replicate the graph exactly. However, for Narnia, if you compare the graph that has the “fe” vs “re” structure, you see that the error band gets wider when you account for random effects.
From the link above: “More technically speaking, type = "re" accounts for the uncertainty of the fixed effects conditional on the estimates of the random-effect variances and conditional modes”. So basically,
Hope that helps? I think it would be really useful to implement the ggpredict function in the tutorial – I hadn’t used it before but it’s great! Much more customisable than the sjPlot package I was using previously. Practically speaking, I would: 1- update Haydn’s code to lme4 rather than nlme Anything else I can do just let me know! |
Hey @sandra-ab That is awesome, thank you very much! All that sounds good to me, so if you want to go ahead and implement those tutorial edits, that'd be awesome! And I think it would be really useful to have some the text from your message above in the tutorial as it explains what the different syntaxes do very well! Having the We can have the graphs be just for Narnia, but might be useful to explain why they're not working for Hogsmeade (I imagine there isn't enough variance in those data? Or something like that?). Plotting the results of a mixed effect model is pretty much our most asked question, so the updates will be very useful to people I think! @beverlytan once Sandra has updated the tutorial, could you please tweet about it? Thanks very much team! |
Hi @sandra-ab and @gndaskalova, Thanks Sandra for going through the tutorial / trying to solve the questions I had, but yes please do just feel free to edit the ideas that I had previously developed, I honestly can't remember much of what I did at the point so would be best for you to just edit and update the tutorial! And yes, will tweet about it when it's been edited :-) |
Hey Sandra @sandra-ab Just going through issues and quickly wanted to check if the mixed eff tutorial got updated with your work from above? Bad internet here so the tutorial doesn't load for me to check. Thanks! |
@gndaskalova not yet - my bad! There wasn't really room for it after updating the advanced data vis tutorial, so I'll create a new example in the mixed model tutorial instead. (Currently I think that tutorial only suggests tables to report mixed model results!) I'll put that tut on my priority list to update as it's always a popular one. Thanks for the reminder! |
Hi @gndaskalova
Just thought I'd start a new issue thread here to ask for your input on the improvement for the second data vis tutorial. As per our previous discussion, I've left Hadyn's more complicated code to visualize the mixed effect models, but have just played around with using ggpredict from ggeffects to do the same thing, which I thought would be useful to present to anyone looking at the tutorial.
However, my biggest issue was that with Hadyn's original mixed effect model built with the function
lme
instead oflmer
, I for some reason am unable to use the ggpredict function and this error comes up:Error in filter_impl(.data, quo) : Result must have length 6, not 42
.I spent some time trying to see why that would be the case but couldnt figure it out so decided to try the same using
lmer
, and I was then able to use the ggpredict function and come up with the graph in that way. The code as follows:This piece of code produces a similar graph to what Haydn's code produces:
Therefore, I just wanted to ask if you would like me to add in this piece of code to show the use of ggpredict or if I should just leave it, since an entirely different function to develop the mixed effect model is being utilized here. Also, I'm actually unsure if i've stated the random effects correctly (Haydn's original random = ~1|year/plot vs my lmer using (1|plot) + (1|year) instead).
Let me know what you think is the most appropriate and I'd be happy to make the changes.
The text was updated successfully, but these errors were encountered: