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

afex_plot missmatch when DV is transformed #85

Open
mattansb opened this issue Jun 10, 2020 · 1 comment
Open

afex_plot missmatch when DV is transformed #85

mattansb opened this issue Jun 10, 2020 · 1 comment

Comments

@mattansb
Copy link
Contributor

When data is transformed, afex_plot shows data on transformed scale, but emmeans on response scale:

library(afex)
#> Loading required package: lme4
#> Loading required package: Matrix
#> Registered S3 methods overwritten by 'car':
#>   method                          from
#>   influence.merMod                lme4
#>   cooks.distance.influence.merMod lme4
#>   dfbeta.influence.merMod         lme4
#>   dfbetas.influence.merMod        lme4
#> ************
#> 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(): 'KR', 'S', 'LRT', and 'PB'
#> - 'afex_aov' and 'mixed' objects can be passed to emmeans() for follow-up tests
#> - NEWS: library('emmeans') now needs to be called explicitly!
#> - 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

data(stroop, package = "afex")

stroop <- na.omit(stroop)
stroop <- subset(stroop, study == "1")

fit <- aov_ez("pno", "rt", stroop,
              within = c("congruency", "condition"),
              include_aov = FALSE)
#> Warning: More than one observation per cell, aggregating the data using mean
#> (i.e, fun_aggregate = mean)!

fit2 <- aov_ez("pno", "rt", stroop,
               transformation = "log",
              within = c("congruency", "condition"),
              include_aov = FALSE)
#> Warning: More than one observation per cell, aggregating the data using mean
#> (i.e, fun_aggregate = mean)!

afex_plot(fit, ~ congruency)
#> Substituting multivariate/lm model, as aov object missing.
#> Warning: Panel(s) show within-subjects factors, but not within-subjects error bars.
#> For within-subjects error bars use: error = "within"

afex_plot(fit2, ~ congruency)
#> Substituting multivariate/lm model, as aov object missing.
#> Warning: Panel(s) show within-subjects factors, but not within-subjects error bars.
#> For within-subjects error bars use: error = "within"

Created on 2020-06-10 by the reprex package (v0.3.0)

@mattansb
Copy link
Contributor Author

mattansb commented Jun 4, 2024

Here is a work-around for this case:

library(afex)
#> Loading required package: lme4
#> Warning: package 'lme4' was built under R version 4.3.3
#> 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
#> - Get and set global package options with: afex_options()
#> - Set 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
data(stroop, package = "afex")

stroop <- na.omit(stroop)
stroop <- subset(stroop, study == "1")

fit2 <- aov_ez("pno", "rt", stroop,
               transformation = "log",
               within = c("congruency", "condition"),
               include_aov = FALSE)
#> Warning: More than one observation per design cell, aggregating data using `fun_aggregate = mean`.
#> To turn off this warning, pass `fun_aggregate = mean` explicitly.
# 1) save ggplot object
p2 <- afex_plot(fit2, ~ congruency)
#> Warning: Panel(s) show within-subjects factors, but not within-subjects error bars.
#> For within-subjects error bars use: error = "within"
# 2) back transform the y column in the first layer (raw data)
p2$layers[[1]]$data$y <- exp(p2$layers[[1]]$data$y)

p2 + ggplot2::labs(y = "rt")

Created on 2024-06-04 with reprex v2.1.0

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

1 participant