crsh / papaja

papaja (Preparing APA Journal Articles) is an R package that provides document formats to produce complete APA manuscripts from RMarkdown-files (PDF and Word documents) and helper functions that facilitate reporting statistics, tables, and plots.
https://frederikaust.com/papaja_man/
Other
651 stars 132 forks source link

Anova doesn't show MSE anymore #562

Closed julianrottenberg closed 12 months ago

julianrottenberg commented 1 year ago

Hello,

Describe the bug Earlier today, when I used apa_table to create a table for an anova it created an anova that had the same rows as the one in the book - $\eta{G}^{2}, F, df, df{res}, MSE, p$. At some point today it swapped $MSE$ for $90% CI$. This also happens if I use the code from the example in the book...

Using mse = TRUE in apa_print() doesn't help the issue either.

Also I tried the same file on a fresh R and rStudio install on my old laptop and it works perfectly. It seems like the issue happens with apa_print. When I look at cosmetic_surgery_anova on here vs the fresh install, i can't spot a difference. But when I compare apa_anova to the one on the fresh install, I see the issue. On the fresh install it lists MSE but on my current one it lists conf.int.

Update: I uninstalled papaja and afex and reinstalled them, that doesn't fix the issue, also I'm using the devel version of papaja.

To Reproduce

load("cosmetic_surgery.rdata")
cosmetic_surgery_anova <- afex::aov_ez(
  data = cosmetic_surgery
  , dv = "Post_QoL"
  , id = "ID"
  , between = c("Clinic", "Gender")
)
apa_anova <- apa_print(cosmetic_surgery_anova)
apa_table(
  apa_anova$table
  , caption = "A really beautiful ANOVA table."
  , note = "Note that the column names contain beautiful mathematical copy: This is because the table has variable labels."
)

Expected behavior See here https://frederikaust.com/papaja_man/reporting.html#analysis-of-variance-anova (A really beautiful ANOVA table).

Screenshots This is what I get now image

mariusbarth commented 1 year ago

Hi @Sashpta,

this is actually not a bug but a feature, but I admit that it may deserve better documentation. Whether or not MSE is reported in the ANOVA table depends on the estimate that is being calculated (here, typically generalized eta-squared). papaja now uses the effectsize package to calculate the estimate together with CIs if it is installed -- if so, MSE is not reported.

Solution: If you set apa_print(., estimate = "ges") (the old default), the effectsize package is not used and only the point estimates of generalized eta-squared are calculated -- also, MSE is reported.

@crsh: If mse = TRUE is set, should we always report MSE irrespective of what is specified as estimate?

julianrottenberg commented 1 year ago

Solution: If you set apa_print(., estimate = "ges") (the old default), the effectsize package is not used and only the point estimates of generalized eta-squared are calculated -- also, MSE is reported.

That did the trick, thank you! :)

mariusbarth commented 1 year ago

Great that it worked! 🎉

mariusbarth commented 12 months ago

Hi @Sashpta, with the most recent development version of papaja, it is now possible to request MSEs even if confidence intervals are also included in the output. For example:

> aov_4(formula = yield ~ (N|block), data = npk) |>
+   apa_print(mse = TRUE)
$estimate
$estimate$N
[1] "$\\hat{\\eta}^2_G = .300$, 90\\% CI $[.000, .672]$"

$statistic
$statistic$N
[1] "$F(1, 5) = 9.61$, $\\mathit{MSE} = 9.85$, $p = .027$"

$full_result
$full_result$N
[1] "$F(1, 5) = 9.61$, $\\mathit{MSE} = 9.85$, $p = .027$, $\\hat{\\eta}^2_G = .300$, 90\\% CI $[.000, .672]$"

$table
A data.frame with 8 labelled columns:

  term estimate     conf.int statistic df df.residual  mse p.value
1    N     .300 [.000, .672]      9.61  1           5 9.85    .027

term     : Effect 
estimate : $\\hat{\\eta}^2_G$ 
conf.int : 90\\% CI 
statistic: $F$ 
df       : $\\mathit{df}^{\\mathrm{GG}}$ 
... (3 more labels)
attr(,"class")
[1] "apa_results" "list"