Skip to content

Commit

Permalink
work on apa_print() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusbarth committed Mar 15, 2024
1 parent c3e6834 commit e667def
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
17 changes: 12 additions & 5 deletions R/apa_print_anova.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#' Typeset Statistical Results from ANOVA
#' Typeset Statistical Results from Analysis of Variance (or Deviance)
#'
#' These methods take objects from various R functions that calculate ANOVA to
#' create formatted character strings to report the results in accordance with
#' APA manuscript guidelines. For `anova`-objects from model comparisons see
#' \code{\link{apa_print.list}}.
#' These methods take objects from various R functions that calculate analysis
#' of variance (i.e., ANOVA) or analysis of deviance. They create formatted
#' character strings to report the results in accordance with APA manuscript
#' guidelines. For `anova`-objects from model comparisons see
#' [apa_print.list()].
#'
#' @param x An object containing the results from an analysis of variance ANOVA
#' @param correction Character. For repeated-measures ANOVA, the type of
Expand Down Expand Up @@ -419,6 +420,12 @@ apa_print.anova <- function(
x$Term <-rownames(x)
y <- canonize(x)
y <- remove_residuals_row(y)
y$df.residual <- NULL
if(is.null(y$statistic)) {
y$statistic <- y$deviance
variable_label(y$statistic) <- "$\\chi^2$"
y$deviance <- NULL
}
y <- beautify(y, ...)
return(
glue_apa_results(
Expand Down
6 changes: 6 additions & 0 deletions R/lookup_tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ lookup_names <- c(
, "logbf01" = "statistic"
, "Bartlett.s.K.2" = "statistic"
, "Bartlett.s.K.squared" = "statistic"
, "Rao" = "statistic"
, "Cp" = "statistic"
# df, df.residual
, "multivariate.df1" = "multivariate.df"
, "multivariate.df2" = "multivariate.df.residual"
Expand All @@ -128,6 +130,7 @@ lookup_names <- c(
# p.value
, "p.value" = "p.value"
, "Pr..Chisq." = "p.value"
, "Pr..Chi." = "p.value"
, "Pr..F." = "p.value"
, "Pr..PB." = "p.value"
, "Pr...t.." = "p.value"
Expand Down Expand Up @@ -225,6 +228,8 @@ lookup_labels <- c(
, "logbf01" = "$\\log \\mathrm{BF}_{\\textrm{01}}$"
, "Bartlett.s.K.2" = "$K^2$"
, "Bartlett.s.K.squared" = "$K^2$"
, "Rao" = "$\\mathit{RS}$"
, "Cp" = "$C_p$"
# df, df.residual
, "multivariate.df" = "$\\mathit{df}$"
, "multivariate.df.residual" = "$\\mathit{df}_{\\mathrm{res}}$"
Expand Down Expand Up @@ -253,6 +258,7 @@ lookup_labels <- c(
, "Pr...z.." = "$p$"
, "pvalues" = "$p$"
, "Pr..Chisq." = "$p$"
, "Pr..Chi." = "$p$"
, "Pr..F." = "$p$"
, "Pr..PB." = "$p$"
, "adj.p.value" = "$p_\\mathrm{adj}$"
Expand Down
18 changes: 17 additions & 1 deletion tests/testthat/test_apa_print_anova.R
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,24 @@ test_that(
, p.value = "$p$"
)
)
}
)


test_that(
"Analysis of deviance from the stats package"
, {
# From stats::glm() examples section:
## Dobson (1990) Page 93: Randomized Controlled Trial :
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
data.frame(treatment, outcome, counts) # showing data
glm.D93 <- glm(counts ~ outcome + treatment, family = poisson())
apa_print(anova(glm.D93, test = "Chisq"))
apa_print(anova(glm.D93, test = "Cp"))
apa_print(anova(glm.D93, test = "LRT"))
apa_print(car::Anova(glm.D93, test.statistic = "LR"))
apa_print(anova(glm.D93, test = "Rao"))
}
)

Expand Down

0 comments on commit e667def

Please sign in to comment.