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

[WIP] apa_print()-methods for metafor #299

Open
wants to merge 6 commits into
base: devel
Choose a base branch
from
Open

Conversation

ekothe
Copy link

@ekothe ekothe commented Jul 8, 2019

This is the first attempt at adding a apa_print function for metafor (rma) objects. This will handle both univariate meta-analysis and meta-regression models.

The formatting of the output and documentations needs improvement but this should give you an idea of where we're up to after the hackathon at SIPS2019.

Copy link
Owner

@crsh crsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting this started, Emily. It's a great start! I'll add a couple of comments, know that this is work in progress. Let me know if you want to continue work on this.

#' }
#' @family apa_print
#'
apa_print.metafor <- function(
Copy link
Owner

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 general rma depending on how general this method should be. Right?


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"]]), "]$")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of a general workflow I try to assemble the table element first and build the rest from it. Do you think this could be a sensible approach here too? It may simplify maintenance and may expose commonalities among functions that could be used further reuse code across methods.

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"]]), "]$")
apa_res$estimate <- setNames(apa_res$estimate, row.names(x$beta))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I never use setNames() but really should.

Copy link
Author

Choose a reason for hiding this comment

The 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$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$")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a nice next step would be to add variable labels using variable_labels().

@crsh crsh changed the title Metafor [WIP] apa_print()-methods for metafor Jul 22, 2019
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

Successfully merging this pull request may close these issues.

2 participants