apa_print.lm {papaja} | R Documentation |
Typeset Statistical Results from GLM
Description
These methods take (generalized) linear model objects to create formatted character strings to report the results in accordance with APA manuscript guidelines.
Usage
## S3 method for class 'lm'
apa_print(
x,
est_name = NULL,
standardized = FALSE,
conf.int = 0.95,
observed = TRUE,
in_paren = FALSE,
...
)
## S3 method for class 'glm'
apa_print(
x,
est_name = NULL,
standardized = FALSE,
conf.int = 0.95,
observed = TRUE,
in_paren = FALSE,
...
)
## S3 method for class 'summary.glm'
apa_print(x, ...)
## S3 method for class 'summary.lm'
apa_print(x, ...)
Arguments
x |
|
est_name |
Character. If |
standardized |
Logical. Indicates if coefficients were standardized
(e.g., using |
conf.int |
Numeric. Either a single value (range [0, 1]) giving the
confidence level or a two-column |
observed |
Logical. Indicates whether predictor variables were observed. See details. |
in_paren |
Logical. Whether the formatted string is to be reported in
parentheses. If |
... |
Arguments passed on to |
Details
The coefficient names are sanitized to facilitate their use as list names.
Parentheses are omitted and other non-word characters are replaced by _
(see sanitize_terms()
).
est_name
is placed in the output string and is then passed to pandoc or
LaTeX through knitr. Thus, to the extent it is supported by the
final document type, you can pass LaTeX-markup to format the final text
(e.g., "\\\\beta"
yields \beta
).
If standardized = TRUE
, scale()
is removed from coefficient names
(see examples). This option is currently ignored for glm
-objects.
If conf.int
is a single value, confidence intervals are calculated using
stats::confint()
.
If x
is an lm
object and the MBESS package is available,
confidence intervals for R^2
are computed using MBESS::ci.R2()
to
obtain a confidence region that corresponds to the \alpha
-level
chosen for the confidence intervals of regression coefficients (e.g.,
95% CI or \alpha = 0.05
for regression coefficients yields a 90% CI
for R^2
, see Steiger, 2004). If observed = FALSE
, it is assumed
that predictors are fixed variables, i.e., "the values of the
[predictors] were selected a priori as part of the research design"
(p. 15, Kelly, 2007); put differently, it is assumed that predictors are
not random.
Value
apa_print()
-methods return a named list of class apa_results
containing the following elements:
estimate |
One or more character strings giving point estimates, confidence intervals, and confidence level. A single string is returned in a vector; multiple strings are returned as a named list. If no estimate is available the element is |
statistic |
One or more character strings giving the test statistic, parameters (e.g., degrees of freedom), and p-value. A single string is returned in a vector; multiple strings are returned as a named list. If no estimate is available the element is |
full_result |
One or more character strings comprised 'estimate' and 'statistic'. A single string is returned in a vector; multiple strings are returned as a named list. |
table |
A |
Column names in apa_results_table
are standardized following the broom glossary (e.g., term
, estimate
conf.int
, statistic
, df
, df.residual
, p.value
). Additionally, each column is labelled (e.g., $\hat{\eta}^2_G$
or $t$
) using the tinylabels package and these labels are used as column names when an apa_results_table
is passed to apa_table()
.
References
Steiger (2004). Beyond the F Test: Effect Size Confidence Intervals and Tests of Close Fit in the Analysis of Variance and Contrast Analysis. Psychological Methods, 9(2), 164-182. doi: doi:10.1037/1082-989X.9.2.164
Kelley, K. (2007). Confidence intervals for standardized effect sizes: Theory, application, and implementation. Journal of Statistical Software, 20(8), 1-24. doi: doi:10.18637/jss.v020.i08
See Also
stats::confint()
, MBESS::ci.pvaf()
Other apa_print:
apa_print.BFBayesFactor()
,
apa_print.aov()
,
apa_print.emmGrid()
,
apa_print.glht()
,
apa_print.htest()
,
apa_print.list()
,
apa_print.lme()
,
apa_print.merMod()
,
apa_print()
Examples
# Data from Dobson (1990), p. 9.
ctl <- c(4.17, 5.58, 5.18, 6.11, 4.50, 4.61, 5.17, 4.53, 5.33, 5.14)
trt <- c(4.81, 4.17, 4.41, 3.59, 5.87, 3.83, 6.03, 4.89, 4.32, 4.69)
group <- gl(2, 10, 20, labels = c("Ctl", "Trt"))
weight <- c(ctl, trt)
lm_fit <- lm(weight ~ group)
apa_print(lm_fit)
trt <- rep(trt, 2) # More data is always better
ctl <- rep(ctl, 2)
lm_fit2 <- lm(scale(trt) ~ scale(ctl))
apa_print(lm_fit2, standardized = TRUE)
# It is possible to simplify the regression table with transmute_df_into_label():
transmute_df_into_label(apa_print(lm_fit2, standardized = TRUE))
# 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)
d.AD <- data.frame(treatment, outcome, counts)
glm.D93 <- glm(counts ~ outcome + treatment, family = poisson())
apa_print(glm.D93)