glue_apa_results {papaja}R Documentation

Create a New apa_results Object

Description

Typeset the contents of an object according to the specified expression strings and create a new or extend an existing apa_results object.

Usage

glue_apa_results(x = NULL, term_names = NULL, ...)

add_glue_to_apa_results(
  ...,
  est_glue,
  stat_glue,
  container,
  sublist = NULL,
  term_names = NULL,
  in_paren = FALSE,
  est_first = TRUE,
  simplify = TRUE
)

Arguments

x

An environment, list or data frame used to look up values for substitution.

term_names

Character. Used as names for the estimate-, statistics-, and full_result sub-lists, if multiple estimates or statistics are glued. Defaults to attr(x, "sanitized_term_names").

...

[expressions]
Unnamed arguments are taken to be expression string(s) to format. Multiple inputs are concatenated together before formatting. Named arguments are taken to be temporary variables available for substitution.

est_glue

Character. (Named vector of) expressions string(s) to format. Each string creates a new (named) element in the estimate sub-list.

stat_glue

Character. (Named vector of) expressions string(s) to format. Each string creates a new (named) element in the statistic sub-list.

container

List of class apa_results to add the glued results to.

sublist

Character. Name of (new) sub-list in estimate statistics, and full_result to append glued results to (e.g., modelfit).

in_paren

Logical. Whether the formatted string is to be reported in parentheses. If TRUE, parentheses in the formatted string (e.g., those enclosing degrees of freedom) are replaced with brackets.

est_first

Logical. Determines in which order estimate and statistic are glued together to full_result.

simplify

Logical. Determines whether the estimate, statistic, and full_result sub-lists should be simplified if only one term is available from the model object.

Value

Returns a list of class apa_results, see apa_print().

Examples

# Tidy and typeset output
iris_lm <- lm(Sepal.Length ~ Petal.Length + Petal.Width, iris)
tidy_iris_lm <- broom::tidy(iris_lm, conf.int = TRUE)
tidy_iris_lm$p.value <- apa_p(tidy_iris_lm$p.value)

glance_iris_lm <- broom::glance(iris_lm)
glance_iris_lm$p.value <- apa_p(glance_iris_lm$p.value, add_equals = TRUE)
glance_iris_lm$df <- apa_num(as.integer(glance_iris_lm$df))
glance_iris_lm$df.residual <- apa_num(as.integer(glance_iris_lm$df.residual))

# Create `apa_results`-list
lm_results <- glue_apa_results(
    x = tidy_iris_lm
    , df = glance_iris_lm$df.residual
    , est_glue = "$b = <<estimate>>, 95% CI $[<<conf.low>>,~<<conf.high>>]$"
    , stat_glue = "$t(<<df>>) = <<statistic>>$, $p <<p.value>>$"
    , term_names = make.names(names(coef(iris_lm)))
)

# Add modelfit information
add_glue_to_apa_results(
    .x = glance_iris_lm
    , container = lm_results
    , sublist = "modelfit"
    , est_glue = c(
        r2 = "$R^2 = <<r.squared>>$"
        , aic = ""
    )
    , stat_glue = c(
        r2 = "$F(<<df>>, <<df.residual>>) = <<statistic>>$, $p <<add_equals(p.value)>>$"
        , aic = "$\\mathrm{AIC} = <<AIC>>$"
    )
)

[Package papaja version 0.1.2 Index]