Skip to content
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

Residuals with mixed-fitted model #116

Open
pablobernabeu opened this issue Nov 28, 2022 · 3 comments
Open

Residuals with mixed-fitted model #116

pablobernabeu opened this issue Nov 28, 2022 · 3 comments

Comments

@pablobernabeu
Copy link
Contributor

Hi Henrik,

I would like to ask you if you could please advise me how to create condition-specific residuals plots for mixed-fitted models.

I have looked for possibilities but to little avail.

Thank you very much

@mattansb
Copy link
Contributor

Are you looking for something like this?

library(afex)
#> Loading required package: lme4
#> Loading required package: Matrix
#> ************
#> Welcome to afex. For support visit: http://afex.singmann.science/
#> - Functions for ANOVAs: aov_car(), aov_ez(), and aov_4()
#> - Methods for calculating p-values with mixed(): 'S', 'KR', 'LRT', and 'PB'
#> - 'afex_aov' and 'mixed' objects can be passed to emmeans() for follow-up tests
#> - NEWS: emmeans() for ANOVA models now uses model = 'multivariate' as default.
#> - Get and set global package options with: afex_options()
#> - Set orthogonal sum-to-zero contrasts globally: set_sum_contrasts()
#> - For example analyses see: browseVignettes("afex")
#> ************
#> 
#> Attaching package: 'afex'
#> The following object is masked from 'package:lme4':
#> 
#>     lmer
library(ggeffects)
library(patchwork)

data(md_12.1)
a <- aov_ez("id", "rt", md_12.1, within = c("angle", "noise"))

p1 <- ggemmeans(a, "angle") |> 
  plot(add.data = TRUE, jitter = 0.1) + 
  ggplot2::ggtitle("Raw Data")

p2 <- ggemmeans(a, "angle") |> 
  plot(residuals = TRUE, jitter = 0.1) + 
  ggplot2::ggtitle("Residualised scores")
#> Data was changed during ANOVA calculation. Thus, residuals cannot be added to original data.
#> residuals(..., append = TRUE) will return data and residuals.

#Compare
p1 + p2 &
  ggplot2::coord_cartesian(ylim = c(300, 1000))

Created on 2022-11-28 with reprex v2.0.2

@pablobernabeu
Copy link
Contributor Author

Thank you very much. Would it be possible to get Q-Q plots, please?

I would also like to comment on the function I used to fit my model, namely, mixed(). I've noticed that a custom function that was available to plot residuals (kindly provided by yourself in a previous issue) doesn't seem to work with models fitted by mixed. I'm echoing this previous issue.

Since that issue, do you know if it has become possible to create Q-Q plots in a way similar to your residuals_qqplot function, but with a mixed-fitted model?

I have googled into this but to no avail so far.

@pablobernabeu
Copy link
Contributor Author

pablobernabeu commented Nov 28, 2022

P.S. Even if there were a more cumbersome way, I would be very interested in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants