-
Notifications
You must be signed in to change notification settings - Fork 135
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
[WIP] apa_print()-methods for metafor #299
base: devel
Are you sure you want to change the base?
Changes from all commits
92632a3
5d2a8e8
ff914df
f08d46a
4a951d5
20476ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#' Format statistics (APA 6th edition) | ||
#' | ||
#' These methods take \code{rma} objects to create formatted character | ||
#' strings to report the results in accordance with APA manuscript guidelines. | ||
#' | ||
#' | ||
#' @return | ||
#' \code{apa_print.metafor} returns a list containing the following components according to the input: | ||
#' | ||
#' \describe{ | ||
#' \item{\code{statistic}}{A named list of character strings giving the test statistic (z), and | ||
#' \emph{p} value for each term.} | ||
#' \item{\code{estimate}}{A named list of character strings giving the descriptive estimates and confidence intervals | ||
#' for each term.} | ||
#' \item{\code{full_result}}{A named list of character strings comprised of \code{estimate} and \code{statistic} for each term.} | ||
#' \item{\code{table$estimate}}{A data.frame containing the study label, estimate, standard error, test statistic for each observed study and the overall meta-analytic estimate with standard error, test statistic, and p value. This table can be passed to \code{\link{apa_table}}.} | ||
#' } | ||
#' #' \item{\code{table$heterogeneity}}{A data.frame containing the number of observations, measure and method employed in the analysis as well as the I^2, Tau^2 Tau^2 standard error and results of Cochran test of heterogeneity. This table can be passed to \code{\link{apa_table}}.} | ||
#' } | ||
#' @family apa_print | ||
#' | ||
apa_print.metafor <- function( | ||
x | ||
, est_name = NULL | ||
, ci = 0.95 | ||
, in_paren = FALSE | ||
, ... | ||
){ | ||
|
||
if(!is(x, "rma")) stop("Object is not an rma object") | ||
if(!is.null(est_name)) papaja:::validate(est_name, check_class = "character", check_length = 1) | ||
if(is.null(est_name)) est_name <- "b" | ||
|
||
|
||
apa_res <- papaja:::apa_print_container() | ||
|
||
apa_res$estimate <- paste0("$", est_name, "$ = ", round(x$b, x$digits[["est"]]), " $95\\% CI$ = $[", round(x$ci.lb, digits = x$digits[["ci"]]), "$, $", round(x$ci.ub, digits = x$digits[["ci"]]), "]$") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In terms of a general workflow I try to assemble the |
||
apa_res$estimate <- setNames(apa_res$estimate, row.names(x$beta)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, I never use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be honest it's just copied from how the variable names are set in metafor itself. |
||
|
||
apa_res$statistic <- paste0("$z$ = ", round(x$zval, digits = x$digits[["test"]]), ", $p$ = ", printp(x$pval)) | ||
apa_res$statistic <- setNames(apa_res$statistic, row.names(x$beta)) | ||
|
||
apa_res$full_result <- paste(apa_res$estimate, apa_res$statistic) | ||
apa_res$full_result <- setNames(apa_res$full_result, row.names(x$beta)) | ||
|
||
apa_res$table$estimate <- broom::tidy(x) | ||
|
||
apa_res$table$heterogeneity <- broom::glance(x) | ||
names(apa_res$table$heterogeneity) <- c("k", "measure", "method", "I$^2$", "H$^2$", "$\\tau^2$", "$\\tau^2$ se", "Cochran Q$_e$", "Cochran Q$_e$ $p$", "Cochran Q$_m$", "Cochran Q$_m$ $p$") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a nice next step would be to add variable labels using |
||
|
||
apa_res | ||
} | ||
|
||
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I'm missing something, for S3-method dispatch to work this functions needs to be named after the S3 class it is ment to operate on. In this case, I think, it should be either the specific
rma.uni
or more generalrma
depending on how general this method should be. Right?