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

improved footnote posthoc anova #371

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions R/ancova.R
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,10 @@ AncovaInternal <- function(jaspResults, dataset = NULL, options) {
options$postHocTypeStandardBootstrap)

postHocRef <- emmeans::lsmeans(model, postHocVariablesListV)
postHocCorrections <- c("tukey", "scheffe", "bonferroni", "holm", "sidak")
wantsCorrections <- c(options[["postHocCorrectionTukey"]], options[["postHocCorrectionScheffe"]],
options[["postHocCorrectionBonferroni"]], options[["postHocCorrectionHolm"]],
options[["postHocCorrectionSidak"]])
postHocCorrections <- c("tukey", "scheffe", "bonferroni", "holm", "sidak")[wantsCorrections]

## Computation
resultPostHoc <- lapply(postHocCorrections, function(x)
Expand All @@ -950,7 +953,9 @@ AncovaInternal <- function(jaspResults, dataset = NULL, options) {
# if there is p-adjustment, then add footnote
if (nrow(resultPostHoc[[1]]) > 1 && any(grepl(attr(resultPostHoc[[1]], "mesg"), pattern = "P value adjustment")))
postHocStandardContainer[[thisVarNameRef]]$addFootnote(.getCorrectionFootnoteAnova(resultPostHoc[[1]],
(options$postHocCi && isFALSE(options$postHocTypeStandardBootstrap))))
(options$postHocCi && isFALSE(options$postHocTypeStandardBootstrap)),
includeEffectSize = options[["postHocTypeStandardEffectSize"]],
isBetween = TRUE))
avFootnote <- attr(resultPostHoc[[1]], "mesg")[grep(attr(resultPostHoc[[1]], "mesg"), pattern = "Results are averaged")]
if (length(avFootnote) != 0) {
avTerms <- .unv(strsplit(gsub(avFootnote, pattern = "Results are averaged over the levels of: ", replacement = ""),
Expand Down
11 changes: 5 additions & 6 deletions R/anovarepeatedmeasures.R
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ AnovaRepeatedMeasuresInternal <- function(jaspResults, dataset = NULL, options)
thisVarNameRef <- paste0(thisVarName, termIndex)
byVariable <- if (length(termsToLoop) > 1) postHocVariables[[postHocVarIndex]] else NULL

resultPostHoc <- summary(pairs(referenceGrid[[thisVarName]], adjust="bonferroni", by = byVariable[termIndex]),
resultPostHoc <- summary(pairs(referenceGrid[[thisVarName]], adjust="holm", by = byVariable[termIndex]),
infer = TRUE, level = options$postHocCiLevel)
numberOfLevels <- nrow(as.data.frame(referenceGrid[[thisVarName]]))
bonfAdjustCIlevel <- .computeBonferroniConfidence(options$postHocCiLevel,
Expand All @@ -978,15 +978,15 @@ AnovaRepeatedMeasuresInternal <- function(jaspResults, dataset = NULL, options)
level = bonfAdjustCIlevel,
by = byVariable[termIndex]))

resultPostHoc[["bonferroni"]] <- resultPostHoc[["p.value"]]
resultPostHoc[["holm"]] <- resultPostHoc[["p.value"]]

resultPostHoc[["tukey"]] <- summary(pairs(referenceGrid[[thisVarName]], adjust="tukey",
by = byVariable[termIndex]))[["p.value"]]

resultPostHoc[["scheffe"]] <- summary(pairs(referenceGrid[[thisVarName]], adjust="scheffe",
by = byVariable[termIndex]))[["p.value"]]

resultPostHoc[["holm"]] <- summary(pairs(referenceGrid[[thisVarName]], adjust="holm",
resultPostHoc[["bonferroni"]] <- summary(pairs(referenceGrid[[thisVarName]], adjust="bonferroni",
by = byVariable[termIndex]))[["p.value"]]

resultPostHoc[["cohenD"]] <- effectSizeResult[["effect.size"]]
Expand Down Expand Up @@ -1014,9 +1014,8 @@ AnovaRepeatedMeasuresInternal <- function(jaspResults, dataset = NULL, options)
resultPostHoc[["contrast_B"]] <- lapply(comparisons, function(x) paste(.unv(strsplit(x[[2]], "[ ,]")[[1]]),
collapse = ", "))

if (nrow(resultPostHoc[[1]]) > 1 && any(grepl(attr(resultPostHoc[[1]], "mesg"), pattern = "P value adjustment")))
postHocContainer[[thisVarNameRef]]$addFootnote(.getCorrectionFootnoteAnova(resultPostHoc[[1]],
(options$postHocCi && isFALSE(options$postHocTypeStandardBootstrap))))
if (nrow(resultPostHoc) > 1 && any(grepl(attr(resultPostHoc, "mesg"), pattern = "P value adjustment")))
postHocContainer[[thisVarNameRef]]$addFootnote(.getCorrectionFootnoteAnova(resultPostHoc, options[["postHocCi"]], options[["postHocEffectSize"]]))

avFootnote <- attr(resultPostHoc, "mesg")[grep(attr(resultPostHoc, "mesg"), pattern = "Results are averaged")]
if (length(avFootnote) != 0) {
Expand Down
7 changes: 5 additions & 2 deletions R/commonAnovaFreq.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
return(postHocTable)
}

.getCorrectionFootnoteAnova <- function(postHocObject, includeCI = FALSE) {
.getCorrectionFootnoteAnova <- function(postHocObject, includeCI = FALSE, includeEffectSize = FALSE, isBetween = FALSE) {

pvalAdjust <- attr(postHocObject, "mesg")[grep(attr(postHocObject, "mesg"), pattern = "P value adjustment")]
nEstimates <- regmatches(pvalAdjust, gregexpr("[[:digit:]]+", pvalAdjust))[[1]]
Expand All @@ -143,8 +143,11 @@

if (!includeCI) {
correctionFootnote <- gettextf("P-value adjusted for comparing a family of %s", as.character(nEstimates))
} else {
} else if (isFALSE(includeEffectSize) || isFALSE(isBetween)) {
correctionFootnote <- gettextf("P-value and confidence intervals adjusted for comparing a family of %1$s estimates (confidence intervals corrected using the %2$s method).", nEstimates, confAdjust)
} else {
correctionFootnote <- gettextf("P-value and confidence intervals adjusted for comparing a family of %1$s estimates (ci for mean difference corrected using the %2$s method; ci for effect size corrected using the bonferroni method).",
nEstimates, confAdjust)
}

return(correctionFootnote)
Expand Down
2 changes: 1 addition & 1 deletion inst/help/Ancova.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ ANCOVA allows the user to analyze the difference between multiple group means, w
<img src="%HELP_FOLDER%/gif/labelediting.gif"/>
</details>

- Correction: To correct for multiple comparison testing and avoid Type I errors, different methods for correcting the p-value are available:
- Correction: To correct for multiple comparison testing and avoid Type I errors, different methods for correcting the p-value and confidence interval for mean difference are available (note that the confidence intervals for effect sizes can only be adjusted using the Bonferroni method):
- Tukey: Compare all possible pairs of group means. This correction can be used when the groups of the independent variable have an equal sample size and variance. This method is commonly used and is selected by default.
- Scheffe: Adjusting significance levels in a linear regression, to account for multiple comparisons. This method is considered to be quite conservative.
- Bonferroni: This correction is considered conservative. The risk of Type I error is reduced, however the statistical power decreases as well.
Expand Down
2 changes: 1 addition & 1 deletion inst/help/Anova.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ ANOVA allows the user to analyze the difference between multiple group means.
<img src="%HELP_FOLDER%/gif/labelediting.gif"/>
</details>

- Correction: To correct for multiple comparison testing and avoid Type I errors, different methods for correcting the p-value are available:
- Correction: To correct for multiple comparison testing and avoid Type I errors, different methods for correcting the p-value and confidence interval for mean difference are available (note that the confidence intervals for effect sizes can only be adjusted using the Bonferroni method):
- Tukey: Compare all possible pairs of group means. This correction can be used when the groups of the independent variable have an equal sample size and variance. This method is commonly used and is selected by default.
- Scheffe: Adjusting significance levels in a linear regression, to account for multiple comparisons. This method is considered to be quite conservative.
- Bonferroni: This correction is considered conservative. The risk of Type I error is reduced, however the statistical power decreases as well.
Expand Down
2 changes: 1 addition & 1 deletion inst/help/AnovaRepeatedMeasures.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ To perform a post hoc test, drag one or more factor names to the right column. S
- Effect size: By selecting this option, the effect size (i.e., the magnitude of the observed effect) will be displayed. The used measure for the effect size is Cohen's d. The effect size will only be displayed for the post hoc type `Standard`.
- Conditional comparisons for interactions: Instead of pairwise comparisons for all possible combination of cells in the interaction, list pairwise comparisons conditional on each of the interaction terms. This provides as many tables as there are terms in the interaction effect.
- Pool error term for follow-up tests: By selecting this option, the univariate linear model, rather than the multivariate model, will be used for follow-up tests (contrasts, post-hoc tests, marginal means). Caution: multivariate models (i.e., unpooled error terms) handle departures from sphericity better, since these models allow the standard errors to differ for each level of the repeated measure(s) factor(s).
- Correction: To correct for multiple comparison testing and avoid Type I errors, different methods for correcting the p-value are available:
- Correction: To correct for multiple comparison testing and avoid Type I errors, different methods for correcting the p-value are available (note that the confidence intervals can only be adjusted using the Bonferroni method):
- Tukey: Compare all possible pairs of group means. This correction can be used when the groups of the repeated measures have an equal sample size and variance. This method is commonly used and is selected by default.
- Scheffe: Adjusting significance levels in a linear regression, to account for multiple comparisons. This method is considered to be quite conservative.
- Bonferroni: This correction is considered conservative. The risk of Type I error is reduced, however the statistical power decreases as well.
Expand Down
Loading