library(dplyr)
library(parameters)
library(performance)
library(apa7)
library(psych)
library(survival)
apa7_defaults(font_family = "Open Sans", line_spacing = 1.5)The apa7 package is closely aligned with the easystats suite of packages for reporting statistical analyses. In most cases, it relies on easystats functions to do most of the hard work and then converts the output to APA style tables. For example, the easystats package parameters has a function model_parameters that takes regression fit objects and displays regression coefficient tables into a tibble that is displayed as a markdown table. The apa_parameters function converts the output of model_parameters into a tibble that is ready for apa_flextable to display as an APA-style table. The workflow has three steps:
- Make a regression model fit object with
lm,glm, or a similar function. -
apa_parametersconverts the fit object into a tibble using easystats functions. -
apa_flextableconverts the tibble into an APA-style table.
Because step 2 returns a tibble, you can post-process it with dplyr before step 3. In Quarto and R Markdown documents, however, the output of apa_parameters is displayed as an APA-style table automatically, so step 3 is only needed when you want to customize the table or save it.
Linear Regression
d <- sat.act |>
mutate(
gender = factor(
gender,
levels = 1:2,
labels = c("Male", "Female")
),
education = factor(
education,
levels = 0:5,
labels = c("None", "High School", "Some College", "Bachelor", "Master", "Doctorate")
)
) |>
tidyr::drop_na()
lm1 <- lm(ACT ~ age + gender, d)
lm2 <- update(lm1, . ~ . + education)
lm3 <- update(lm2, . ~ . + SATV + SATQ)In the console, apa_parameters prints as an ordinary tibble, so you can inspect it. Here as_tibble is used to show that tibble in this document.
Table 1
Regression of ACT Scores on Age and Gender as a Tibble
apa_parameters(lm1) |>
tibble::as_tibble()# A tibble: 3 × 6
Variable `*B*` `*SE*` `β` `*t*(684)` `*p*`
<chr> <chr> <chr> <chr> <chr> <chr>
1 Constant 27.35 0.59 .00 46.55 <.001
2 Age 0.06 0.02 .11 2.93 .004
3 Gender–Female −0.40 0.38 −.04 −1.03 .30
In a rendered document, the output of apa_parameters is displayed as a table without further processing.
apa_parameters(lm1)Table 2
Regression of ACT Scores on Age and Gender
Variable |
B |
SE |
β |
t(684) |
p |
|---|---|---|---|---|---|
Constant |
27.35 |
0.59 |
.00 |
46.55 |
<.001 |
Age |
0.06 |
0.02 |
.11 |
2.93 |
.004 |
Gender–Female |
−0.40 |
0.38 |
−.04 |
−1.03 |
.30 |
The output is still a tibble, so ordinary dplyr verbs work. Pass the result to apa_flextable to customize the table. For example, to drop the intercept:
apa_parameters(lm1) |>
filter(Variable != "Constant") Table 3
Regression of ACT Scores on Age and Gender Without the Constant
Variable |
B |
SE |
β |
t(684) |
p |
|---|---|---|---|---|---|
Age |
0.06 |
0.02 |
.11 |
2.93 |
.004 |
Gender–Female |
−0.40 |
0.38 |
−.04 |
−1.03 |
.30 |
To compare nested models, pass a list. As in many hierarchical regression tables, R2, its change, and the F test of the change go in rows below each model’s coefficients. The first model is tested against a model with only a constant, so its F is the overall test of the model, and the stars are on the F tests:
apa_parameters(list(lm1, lm2, lm3))Table 4
Hierarchical Regression of ACT Scores
Model |
Variable |
B |
SE |
β |
t |
df |
p |
|---|---|---|---|---|---|---|---|
Model 1 |
|||||||
Constant |
27.35 |
0.59 |
.00 |
46.55 |
684 |
<.001 |
|
Age |
0.06 |
0.02 |
.11 |
2.93 |
684 |
.004 |
|
Gender–Female |
−0.40 |
0.38 |
−.04 |
−1.03 |
684 |
.30 |
|
R2 |
.01 |
||||||
F(2, 684) |
4.90** |
||||||
Model 2 |
|||||||
Constant |
27.54 |
0.80 |
.00 |
34.47 |
679 |
<.001 |
|
Age |
0.02 |
0.03 |
.03 |
0.60 |
679 |
.55 |
|
Gender–Female |
−0.57 |
0.38 |
−.06 |
−1.49 |
679 |
.14 |
|
Education–High School |
−0.24 |
0.97 |
−.01 |
−0.25 |
679 |
.81 |
|
Education–Some College |
−0.78 |
1.00 |
−.04 |
−0.78 |
679 |
.44 |
|
Education–Bachelor |
0.86 |
0.71 |
.09 |
1.20 |
679 |
.23 |
|
Education–Master |
1.57 |
0.83 |
.13 |
1.89 |
679 |
.06 |
|
Education–Doctorate |
1.99 |
0.89 |
.17 |
2.25 |
679 |
.03 |
|
R2 |
.04 |
||||||
ΔR2 |
.02 |
||||||
F(5, 679) |
4.95*** |
||||||
Model 3 |
|||||||
Constant |
8.15 |
1.09 |
.00 |
7.46 |
677 |
<.001 |
|
Age |
0.05 |
0.02 |
.11 |
2.77 |
677 |
.006 |
|
Gender–Female |
0.23 |
0.30 |
.02 |
0.75 |
677 |
.45 |
|
Education–High School |
0.08 |
0.75 |
.00 |
0.10 |
677 |
.92 |
|
Education–Some College |
0.14 |
0.77 |
.01 |
0.18 |
677 |
.85 |
|
Education–Bachelor |
0.86 |
0.55 |
.09 |
1.57 |
677 |
.12 |
|
Education–Master |
1.12 |
0.64 |
.09 |
1.75 |
677 |
.08 |
|
Education–Doctorate |
1.05 |
0.69 |
.09 |
1.52 |
677 |
.13 |
|
SATV |
0.01 |
0.00 |
.31 |
8.01 |
677 |
<.001 |
|
SATQ |
0.02 |
0.00 |
.39 |
10.12 |
677 |
<.001 |
|
R2 |
.43 |
||||||
ΔR2 |
.39 |
||||||
F(2, 677) |
231.40*** |
With performance_layout = "columns", the model fit statistics go in columns instead, with their values on each model’s heading row:
apa_parameters(list(lm1, lm2, lm3), performance_layout = "columns")Table 5
Hierarchical Regression of ACT Scores With Model Fit in Columns
Model |
Variable |
B |
SE |
β |
t |
df |
p |
R2 |
ΔR2 |
|---|---|---|---|---|---|---|---|---|---|
Model 1 |
.01 |
||||||||
Constant |
27.35 |
0.59 |
.00 |
46.55 |
684 |
<.001 |
|||
Age |
0.06 |
0.02 |
.11 |
2.93 |
684 |
.004 |
|||
Gender–Female |
−0.40 |
0.38 |
−.04 |
−1.03 |
684 |
.30 |
|||
Model 2 |
.04 |
.02*** |
|||||||
Constant |
27.54 |
0.80 |
.00 |
34.47 |
679 |
<.001 |
|||
Age |
0.02 |
0.03 |
.03 |
0.60 |
679 |
.55 |
|||
Gender–Female |
−0.57 |
0.38 |
−.06 |
−1.49 |
679 |
.14 |
|||
Education–High School |
−0.24 |
0.97 |
−.01 |
−0.25 |
679 |
.81 |
|||
Education–Some College |
−0.78 |
1.00 |
−.04 |
−0.78 |
679 |
.44 |
|||
Education–Bachelor |
0.86 |
0.71 |
.09 |
1.20 |
679 |
.23 |
|||
Education–Master |
1.57 |
0.83 |
.13 |
1.89 |
679 |
.06 |
|||
Education–Doctorate |
1.99 |
0.89 |
.17 |
2.25 |
679 |
.03 |
|||
Model 3 |
.43 |
.39*** |
|||||||
Constant |
8.15 |
1.09 |
.00 |
7.46 |
677 |
<.001 |
|||
Age |
0.05 |
0.02 |
.11 |
2.77 |
677 |
.006 |
|||
Gender–Female |
0.23 |
0.30 |
.02 |
0.75 |
677 |
.45 |
|||
Education–High School |
0.08 |
0.75 |
.00 |
0.10 |
677 |
.92 |
|||
Education–Some College |
0.14 |
0.77 |
.01 |
0.18 |
677 |
.85 |
|||
Education–Bachelor |
0.86 |
0.55 |
.09 |
1.57 |
677 |
.12 |
|||
Education–Master |
1.12 |
0.64 |
.09 |
1.75 |
677 |
.08 |
|||
Education–Doctorate |
1.05 |
0.69 |
.09 |
1.52 |
677 |
.13 |
|||
SATV |
0.01 |
0.00 |
.31 |
8.01 |
677 |
<.001 |
|||
SATQ |
0.02 |
0.00 |
.39 |
10.12 |
677 |
<.001 |
A regression with several outcomes (lm(cbind(y1, y2) ~ x)) gets a block of coefficients for each outcome. See the multivariate analysis of variance section of the ANOVA article for an example, with multivariate tests of each predictor.
Binary Logistic Regression
apa_parameters also accepts glm objects. The table reports coefficients on the link scale (B), their standard errors, the exponentiated coefficient, and the test statistic. For logistic regression, the exponentiated coefficient is the odds ratio (OR), and the test statistic is z.
The Cowles data set in the carData package (Cowles & Davis, 1987) has the neuroticism and extraversion scores of 1,421 introductory psychology students and whether they volunteered to take part in psychological research. Here, the odds of volunteering depend on extraversion, neuroticism, and sex:
d_volunteer <- carData::Cowles |>
transmute(
Volunteered = factor(volunteer, levels = c("no", "yes"), labels = c("No", "Yes")),
Extraversion = extraversion,
Neuroticism = neuroticism,
Sex = factor(sex, levels = c("female", "male"), labels = c("Female", "Male"))
)
glm1 <- glm(
Volunteered ~ Extraversion + Neuroticism + Sex,
data = d_volunteer,
family = binomial
)
apa_parameters(glm1)Table 6
Logistic Regression of Volunteering on Personality and Sex
Variable |
B |
SE |
OR |
z |
p |
|---|---|---|---|---|---|
Constant |
−1.12 |
0.25 |
0.33 |
−4.48 |
<.001 |
Extraversion |
0.07 |
0.01 |
1.07 |
4.65 |
<.001 |
Neuroticism |
0.01 |
0.01 |
1.01 |
0.56 |
.57 |
Sex–Male |
−0.24 |
0.11 |
0.79 |
−2.12 |
.03 |
Exponentiated coefficients are added whenever the link function is logit or log. They are labeled OR for logit links, IRR (incidence rate ratio) for log links in count models, and RR (risk ratio) for log links in binomial models. Set exponentiate = FALSE to leave them out, or exponentiate = TRUE to add them for other links such as probit.
apa_parameters(glm1, exponentiate = FALSE)Table 7
Logistic Regression Coefficients on the Log-Odds Scale
Variable |
B |
SE |
z |
p |
|---|---|---|---|---|
Constant |
−1.12 |
0.25 |
−4.48 |
<.001 |
Extraversion |
0.07 |
0.01 |
4.65 |
<.001 |
Neuroticism |
0.01 |
0.01 |
0.56 |
.57 |
Sex–Male |
−0.24 |
0.11 |
−2.12 |
.03 |
To choose and order the columns, use predictor_parameters. Columns that the model does not report (for example, t for a model tested with z) are dropped silently.
apa_parameters(
glm1,
predictor_parameters = c("Parameter", "Exp_Coefficient", "z", "p")
)Table 8
Logistic Regression With Selected Columns
Variable |
OR |
z |
p |
|---|---|---|---|
Constant |
0.33 |
−4.48 |
<.001 |
Extraversion |
1.07 |
4.65 |
<.001 |
Neuroticism |
1.01 |
0.56 |
.57 |
Sex–Male |
0.79 |
−2.12 |
.03 |
As with lm, starred and bolded mark significant coefficients.
apa_parameters(glm1, starred = "Coefficient", bolded = "p")Table 9
Logistic Regression With Significance Stars and Bold p-Values
Variable |
B |
SE |
OR |
z |
p |
|---|---|---|---|---|---|
Constant |
−1.12*** |
0.25 |
0.33 |
−4.48 |
<.001 |
Extraversion |
0.07*** |
0.01 |
1.07 |
4.65 |
<.001 |
Neuroticism |
0.01 |
0.01 |
1.01 |
0.56 |
.57 |
Sex–Male |
−0.24* |
0.11 |
0.79 |
−2.12 |
.03 |
Comparing logistic regression models
A list of glm models is displayed with a pseudo-R2 (Tjur’s for logistic regression, as chosen by performance::r2) and a likelihood ratio test of the change, because the binomial family has a fixed dispersion parameter.
glm0 <- glm(Volunteered ~ Extraversion, data = d_volunteer, family = binomial)
apa_parameters(list(glm0, glm1))Table 10
Two Logistic Regression Models of Volunteering
Model |
Variable |
B |
SE |
OR |
z |
p |
|---|---|---|---|---|---|---|
Model 1 |
||||||
Constant |
−1.14 |
0.19 |
0.32 |
−6.15 |
<.001 |
|
Extraversion |
0.07 |
0.01 |
1.07 |
4.64 |
<.001 |
|
R2Tjur |
.02 |
|||||
χ2(1) |
22.02*** |
|||||
AIC |
1,915.48 |
|||||
Model 2 |
||||||
Constant |
−1.12 |
0.25 |
0.33 |
−4.48 |
<.001 |
|
Extraversion |
0.07 |
0.01 |
1.07 |
4.65 |
<.001 |
|
Neuroticism |
0.01 |
0.01 |
1.01 |
0.56 |
.57 |
|
Sex–Male |
−0.24 |
0.11 |
0.79 |
−2.12 |
.03 |
|
R2Tjur |
.02 |
|||||
χ2(2) |
5.42 |
|||||
AIC |
1,914.06 |
The model comparison can also be displayed separately with apa_performance_comparison.
apa_performance_comparison(list(glm0, glm1))Table 11
Comparison of Two Logistic Regression Models of Volunteering
Model |
R2Tjur |
ΔR2Tjur |
χ2 |
df |
p |
|---|---|---|---|---|---|
Model 1 |
.02 |
.02 |
|||
Model 2 |
.02 |
.00 |
5.42 |
2 |
.07 |
Multinomial Logistic Regression
When the outcome has more than two unordered categories, multinomial logistic regression (nnet::multinom) compares each category with a reference category, which is the first level of the outcome. The BEPS data set in the carData package (Fox & Andersen, 2006) has the votes of 1,525 people in the British Election Panel Study of 1997–2001 (Conservative, Labour, or Liberal Democrat), their attitudes toward European integration (from 1 to 11, with higher scores for more Eurosceptic attitudes), and their knowledge of the parties’ positions on European integration (from 0 to 3). Here, Conservative is the reference category:
d_vote <- carData::BEPS |>
transmute(
Vote = vote,
Euroscepticism = Europe,
Knowledge = political.knowledge
)
multinom1 <- nnet::multinom(
Vote ~ Euroscepticism + Knowledge,
data = d_vote,
trace = FALSE
)
apa_parameters(multinom1) |>
apa_flextable(note = TRUE)Table 12
Multinomial Logistic Regression of Vote on Euroscepticism and Political Knowledge
Variable |
B |
SE |
OR |
z |
p |
|---|---|---|---|---|---|
Labour vs. Conservative |
|||||
Constant |
3.80 |
0.24 |
44.75 |
15.82 |
<.001 |
Euroscepticism |
−0.35 |
0.02 |
0.71 |
−14.84 |
<.001 |
Knowledge |
−0.53 |
0.07 |
0.59 |
−8.13 |
<.001 |
Liberal Democrat vs. Conservative |
|||||
Constant |
2.24 |
0.26 |
9.39 |
8.49 |
<.001 |
Euroscepticism |
−0.29 |
0.03 |
0.75 |
−11.13 |
<.001 |
Knowledge |
−0.23 |
0.07 |
0.79 |
−3.12 |
.002 |
Note. Coefficients compare each category of Vote with the reference category (Conservative). N = 1,525. OR = odds ratio (relative to the reference category). | |||||
Each comparison gets a heading row with its coefficients indented below it, and the exponentiated coefficients are odds ratios relative to the reference category. More Eurosceptic voters had lower odds of voting Labour or Liberal Democrat rather than Conservative, and so did voters who knew more about the parties’ positions on Europe. To compare the categories with another reference, reorder the levels of the outcome (e.g., with relevel) before fitting the model. With category_headings = FALSE, each row is labeled with its category instead (e.g., “Labour: Constant”).
Lists of multinomial models are compared with McFadden’s pseudo-R2 and likelihood ratio tests:
multinom0 <- nnet::multinom(Vote ~ Euroscepticism, data = d_vote, trace = FALSE)
apa_performance_comparison(list(multinom0, multinom1))Table 13
Comparison of Multinomial Models of Vote
Model |
R2McFadden |
ΔR2McFadden |
χ2 |
df |
p |
|---|---|---|---|---|---|
Model 1 |
.08 |
.08 |
|||
Model 2 |
.10 |
.02 |
75.16 |
2 |
<.001 |
Count Regression
For Poisson and negative binomial regression, the exponentiated coefficients are incidence rate ratios (IRR). The quine data set in the MASS package (Venables & Ripley, 2002) has the number of days that 146 children in New South Wales, Australia, were absent from school in a year. Here, absences depend on the child’s sex and on whether the child was classified as an average or a slow learner:
d_absences <- MASS::quine |>
transmute(
Absences = Days,
Sex = factor(Sex, levels = c("F", "M"), labels = c("Female", "Male")),
Learner = factor(Lrn, levels = c("AL", "SL"), labels = c("Average", "Slow"))
)
glm_pois <- glm(Absences ~ Sex + Learner, data = d_absences, family = poisson)
apa_parameters(glm_pois)Table 14
Poisson Regression of School Absences on Sex and Learner Status
Variable |
B |
SE |
IRR |
z |
p |
|---|---|---|---|---|---|
Constant |
2.66 |
0.04 |
14.33 |
73.75 |
<.001 |
Sex–Male |
0.18 |
0.04 |
1.20 |
4.43 |
<.001 |
Learner–Slow |
0.12 |
0.04 |
1.12 |
2.84 |
.004 |
Quasi-families and other families with an estimated dispersion parameter are tested with t instead of z, and the degrees of freedom are shown in the column header. Nested models are compared with F tests instead of likelihood ratio tests. The absences vary much more than a Poisson model expects, so the quasi-Poisson standard errors are about four times as large, and neither predictor is significant.
glm_qpois <- glm(Absences ~ Sex + Learner, data = d_absences, family = quasipoisson)
apa_parameters(glm_qpois)Table 15
Quasi-Poisson Regression of School Absences on Sex and Learner Status
Variable |
B |
SE |
IRR |
t(143) |
p |
|---|---|---|---|---|---|
Constant |
2.66 |
0.14 |
14.33 |
18.50 |
<.001 |
Sex–Male |
0.18 |
0.16 |
1.20 |
1.11 |
.27 |
Learner–Slow |
0.12 |
0.17 |
1.12 |
0.71 |
.48 |
Zero-inflated and hurdle models
Counts often have more zeros than a Poisson or negative binomial model expects. A zero-inflated model (pscl::zeroinfl) adds a logistic model of excess zeros, which come from cases that could only be zero (e.g., people who would not have an affair under any circumstances). A hurdle model (pscl::hurdle) instead has a logistic model of whether the count is zero or positive, and a zero-truncated count model of the positive counts. Either way, apa_parameters puts each part under its own heading. Only the count model’s coefficients are exponentiated (IRR), because the zero model’s coefficients are log odds. The Affairs data set in the AER package, from a magazine survey analyzed by Fair (1978), has the number of extramarital affairs that 601 married people reported having in the past year. The counts were coded from response categories (0, 1, 2, and 3 times; 7 for 4 to 10 times; and 12 for monthly or more often), and 75% of them are zeros. Here, the number of affairs depends on how happy people rated their marriages (from 1, very unhappy, to 5, very happy) and how religious they were (from 1, anti-religious, to 5, very religious), and so does the probability of an excess zero:
data("Affairs", package = "AER")
d_affairs <- Affairs |>
transmute(
Affairs = affairs,
Happiness = rating,
Religiousness = religiousness
)
zinb <- pscl::zeroinfl(
Affairs ~ Happiness + Religiousness | Happiness + Religiousness,
data = d_affairs,
dist = "negbin"
)
apa_parameters(zinb) |>
apa_flextable(note = TRUE)Table 16
Zero-Inflated Negative Binomial Regression of Extramarital Affairs
Variable |
B |
SE |
IRR |
z |
p |
|---|---|---|---|---|---|
Count model |
|||||
Constant |
2.59 |
0.33 |
13.35 |
7.86 |
<.001 |
Happiness |
−0.18 |
0.07 |
0.84 |
−2.67 |
.007 |
Religiousness |
−0.13 |
0.07 |
0.87 |
−1.88 |
.06 |
Zero-inflation model |
|||||
Constant |
−1.78 |
0.48 |
−3.75 |
<.001 |
|
Happiness |
0.50 |
0.09 |
5.36 |
<.001 |
|
Religiousness |
0.25 |
0.09 |
2.74 |
.006 |
|
Note. The count model is negative binomial with dispersion parameter θ = 1.34, and its coefficients are on the log scale. Zero-inflation coefficients are log odds of an excess zero (a zero not produced by the count model). N = 601. IRR = incidence rate ratio. | |||||
People who were happier in their marriages or more religious were more likely to be among those who would not have an affair at all, and happier people who did have affairs had fewer of them. The note names the count distribution, gives the negative binomial dispersion parameter (θ), and explains the zero model. For a hurdle model, the zero model’s heading is “Zero hurdle model”, and its coefficients are the log odds of a count greater than zero:
pscl::hurdle(
Affairs ~ Happiness + Religiousness | Happiness + Religiousness,
data = d_affairs,
dist = "negbin"
) |>
apa_parameters() |>
apa_note()[1] "The count model is zero-truncated negative binomial with dispersion parameter *θ* = 1.35, and its coefficients are on the log scale. Zero hurdle coefficients are log odds of a count greater than zero. *N* = 601. *IRR* = incidence rate ratio."
apa_performance_comparison compares nested zero-inflated or hurdle models with likelihood ratio tests.
For nested counts, or counts with many zeros, negative binomial and zero-inflated mixed models fit with glmmTMB are described in the multilevel article.
Beta Regression
Proportions and rates, such as the proportion of items answered correctly, are bounded by 0 and 1, and their variability usually depends on their mean (scores near a bound vary less). Beta regression (betareg::betareg) models such outcomes with two parts: a mean model, with a logit link by default, and a precision model (φ), where higher precision means less variability around the mean (Cribari-Neto & Zeileis, 2010; Smithson & Verkuilen, 2006). The precision can be constant or have predictors of its own, written after a | in the formula. The ReadingSkills data set in the betareg package, analyzed by Smithson and Verkuilen (2006), has the reading accuracy of 44 children, 19 of them with dyslexia, and their nonverbal IQ (standardized, so 0 is the sample mean). Here, the mean accuracy depends on dyslexia, IQ, and their interaction, and the precision depends on dyslexia and IQ:
data("ReadingSkills", package = "betareg")
d_reading <- ReadingSkills |>
transmute(
Accuracy = accuracy,
Dyslexia = factor(dyslexia, levels = c("no", "yes"), labels = c("No", "Yes")),
IQ = iq
)
fit_beta <- betareg::betareg(
Accuracy ~ Dyslexia * IQ | Dyslexia + IQ,
data = d_reading
)
apa_parameters(fit_beta) |>
apa_flextable(note = TRUE)Table 17
Beta Regression of Reading Accuracy on Dyslexia and IQ
Variable |
B |
SE |
OR |
z |
p |
|---|---|---|---|---|---|
Mean model |
|||||
Constant |
1.86 |
0.28 |
6.46 |
6.61 |
<.001 |
Dyslexia–Yes |
−1.48 |
0.29 |
0.23 |
−5.20 |
<.001 |
IQ |
1.07 |
0.26 |
2.91 |
4.09 |
<.001 |
Dyslexia–Yes × IQ |
−1.16 |
0.27 |
0.31 |
−4.38 |
<.001 |
Precision model |
|||||
Constant |
1.56 |
0.32 |
4.88 |
<.001 |
|
Dyslexia–Yes |
3.49 |
0.52 |
6.66 |
<.001 |
|
IQ |
1.23 |
0.27 |
4.60 |
<.001 |
|
Note. Estimates are from a beta regression (Ferrari & Cribari-Neto, 2004; Smithson & Verkuilen, 2006) with a logit link for the mean. N = 44. Mean coefficients are log odds of the mean proportion. Higher precision (φ) means less variability around the mean. Precision coefficients are on the log scale. OR = odds ratio of the mean proportion. | |||||
The mean model’s coefficients are log odds of the mean proportion, and the exponentiated coefficients are odds ratios (OR). Children with dyslexia read less accurately, and IQ was related to accuracy only among children without dyslexia: the odds ratio of IQ for children with dyslexia, the product of the odds ratios of IQ and of the interaction, is about 0.91, so IQ made almost no difference for them. The precision model’s coefficients are on the log scale. Accuracy varied less among children with dyslexia and among children with higher IQs. A model without a precision part (Accuracy ~ Dyslexia * IQ) has a constant precision, shown as a single φ row without a test. Beta regressions fit with glmmTMB (family = glmmTMB::beta_family()), including mixed models, work as well; there, the precision model is called the dispersion model.
apa_performance gives the pseudo-R2 of Ferrari and Cribari-Neto (2004) and AIC, and nested models are compared with likelihood ratio tests. Here, the precision model improves on a constant precision:
fit_beta0 <- betareg::betareg(Accuracy ~ Dyslexia * IQ, data = d_reading)
apa_performance_comparison(list(
`Constant precision` = fit_beta0,
`Modeled precision` = fit_beta
))Table 18
Comparison of Beta Regressions of Reading Accuracy With Constant and Modeled Precision
Model |
R2pseudo |
ΔR2pseudo |
χ2 |
df |
p |
|---|---|---|---|---|---|
Constant precision |
.61 |
.61 |
|||
Modeled precision |
.58 |
−.03 |
29.10 |
2 |
<.001 |
The pseudo-R2 describes only the mean model, so it can go down, as it does here, when the precision model improves the fit.
The outcome must be strictly between 0 and 1. In ReadingSkills, perfect scores were recorded as .99. A common alternative for outcomes with exact 0s or 1s is the transformation of Smithson and Verkuilen (2006), (y(n − 1) + .5) / n, where n is the sample size.
Survival Analysis
Survival analysis models how long it takes for an event to happen. Cox proportional hazards models (survival::coxph) relate predictors to the hazard of the event: the rate at which it happens among the cases that have not had it yet. Cases that never have the event during the study are censored: their times count only up to the end of follow-up. The Rossi data set in the carData package (Rossi et al., 1980) follows 432 men for a year after their release from Maryland state prisons and records the week of their first arrest, if any. Half of the men received financial aid after their release. Here, the time to arrest depends on financial aid, age at release, and the number of prior convictions:
d_rearrest <- carData::Rossi |>
transmute(
Week = week,
Arrested = arrest,
`Financial Aid` = factor(fin, levels = c("no", "yes"), labels = c("No", "Yes")),
Age = age,
`Prior Convictions` = prio
)
fit_cox <- coxph(
Surv(Week, Arrested) ~ `Financial Aid` + Age + `Prior Convictions`,
data = d_rearrest
)
apa_parameters(fit_cox) |>
apa_flextable(note = TRUE)The coefficients are log hazard ratios, and the exponentiated coefficients are hazard ratios (HR). A hazard ratio below 1 means that the event happens more slowly: each year of age multiplied the hazard of arrest by about 0.94 (6% lower), and each prior conviction multiplied it by about 1.10 (10% higher). Men who received financial aid had a 29% lower hazard of arrest, a difference that is not quite significant. The note gives the number of cases and of events (arrests), which matters more than the number of cases for the precision of the estimates. Cox models have no constant.
apa_performance gives Nagelkerke’s pseudo-R2, the concordance index (C, the proportion of pairs of men in which the one with the higher predicted hazard was arrested sooner), and AIC:
apa_performance(fit_cox)Table 20
Fit of the Cox Regression of Time to Rearrest
R2Nagelkerke |
C |
AIC |
|---|---|---|
.07 |
.63 |
1,327.71 |
Nested Cox models are compared with likelihood ratio tests:
fit_cox0 <- coxph(Surv(Week, Arrested) ~ `Financial Aid`, data = d_rearrest)
apa_performance_comparison(list(fit_cox0, fit_cox))Table 21
Comparison of Cox Regressions of Time to Rearrest
Model |
R2Nagelkerke |
ΔR2Nagelkerke |
χ2 |
df |
p |
|---|---|---|---|---|---|
Model 1 |
.01 |
.01 |
|||
Model 2 |
.07 |
.06 |
25.21 |
2 |
<.001 |
Parametric survival models
Cox models leave the shape of the hazard over time unspecified. Parametric survival models (survival::survreg) assume a distribution of survival times instead, such as the Weibull distribution (the default), the exponential, the log-normal, or the log-logistic, and model log survival time directly. They are accelerated failure time models: a predictor stretches or shrinks the time until the event. Here is the same model of rearrest with a Weibull distribution:
fit_weibull <- survreg(
Surv(Week, Arrested) ~ `Financial Aid` + Age + `Prior Convictions`,
data = d_rearrest
)
apa_parameters(fit_weibull) |>
apa_flextable(note = TRUE)Table 22
Weibull Accelerated Failure Time Model of Time to Rearrest
Variable |
B |
SE |
TR |
z |
p |
|---|---|---|---|---|---|
Constant |
3.77 |
0.36 |
10.54 |
<.001 |
|
Financial Aid–Yes |
0.25 |
0.14 |
1.28 |
1.82 |
.07 |
Age |
0.05 |
0.02 |
1.05 |
3.11 |
.002 |
Prior Convictions |
−0.07 |
0.02 |
0.93 |
−3.47 |
<.001 |
Log(scale) |
−0.34 |
0.09 |
−3.77 |
<.001 |
|
Note. Estimates are from an accelerated failure time model (Wei, 1992) with a Weibull distribution. Coefficients are changes in log survival time. The test of Log(scale) is a test of the exponential model (scale = 1). N = 432, with 114 events. TR = time ratio. | |||||
The coefficients are changes in log survival time, and the exponentiated coefficients are time ratios (TR). A time ratio above 1 means a longer time to the event, so the signs are the reverse of those of the Cox model: each year of age stretched the time to arrest by about 5%, and each prior conviction shrank it by about 7%. Log(scale) is the log of the Weibull scale parameter. Its test is a test of the exponential model, which has a scale of 1 (a constant hazard). apa_performance and apa_performance_comparison work as for Cox models.
Generalized Additive Models
Generalized additive models (GAMs), fit with mgcv::gam, let a predictor’s effect be a smooth curve instead of a straight line. The Wong data set in the carData package (Wong et al., 2001) has the performance IQ of 200 patients tested after they woke from a coma caused by a traumatic brain injury, with the number of days in the coma and the number of days between waking and testing. Some patients were tested more than once, so only each patient’s first test is kept. Here, performance IQ depends on smooth functions of the length of the coma and the time since waking:
d_coma <- carData::Wong |>
arrange(id, days) |>
distinct(id, .keep_all = TRUE) |>
transmute(
IQ = piq,
Coma = duration,
Recovery = days
)
fit_gam <- mgcv::gam(
IQ ~ s(Coma) + s(Recovery),
data = d_coma,
method = "REML"
)
apa_parameters(fit_gam) |>
apa_flextable(note = TRUE)Table 23
Generalized Additive Model of Performance IQ After a Coma
Variable |
B |
SE |
t(195.33) |
edf |
F |
p |
|---|---|---|---|---|---|---|
Parametric terms |
||||||
Constant |
83.34 |
0.95 |
88.09 |
<.001 |
||
Smooth terms |
||||||
s(Coma) |
2.67 |
5.88 |
<.001 |
|||
s(Recovery) |
1.00 |
1.27 |
.26 |
|||
Note. Smoothing parameters were estimated by restricted maximum likelihood (REML). Smooth terms are tested with approximate F tests. N = 200. edf = effective degrees of freedom. | ||||||
The parametric terms (here, only the constant) have coefficients and t tests, as in other regression models. Each smooth term has its effective degrees of freedom (edf: 1 for a straight line, more for a curvier shape) and an approximate F test of whether the smooth differs from zero. Here, the smooth of the time since waking is nearly a straight line (edf close to 1), and the smooth of the coma’s length is curved: patients in longer comas had lower IQs, but the decline levels off after about two or three months of coma. For non-Gaussian families (e.g., family = binomial), the parametric terms are tested with z, the smooth terms with χ2, and exponentiated coefficients (e.g., OR) are added. Use terms = "parametric" or terms = "smooth" to show only one kind of term. Smooths of a factor-by variable (e.g., s(Coma, by = Sex)) get a row for each level.
apa_performance gives the adjusted R2 and the percentage of the deviance explained:
apa_performance(fit_gam)Table 24
Fit of the Generalized Additive Model
R2adj |
Deviance explained (%) |
AIC |
|---|---|---|
.08 |
9.8 |
1,612.78 |
The smooth terms are shrunk toward simpler shapes, so nested GAMs cannot be compared with the usual F or likelihood ratio tests. Lists of GAMs are compared by R2 and AIC instead.
Robust Regression
A few unusual cases can pull an ordinary regression line toward them. Robust regression gives each case a weight from 0 to 1 that shrinks as its residual grows, so that cases far from the rest have little influence. The Davis data set in the carData package, from a study of body image (Davis, 1990), has the measured and self-reported weights (in kilograms) of 183 men and women who exercise regularly. One woman’s measured weight is a data entry error: her weight and height were swapped, so her measured weight is 166 kg, though she reported 56 kg. Here, reported weight depends on measured weight and sex, fit by ordinary least squares (OLS) and by MM-estimation with robustbase::lmrob:
d_weight <- carData::Davis |>
transmute(
`Reported Weight` = repwt,
`Measured Weight` = weight,
Sex = factor(sex, levels = c("F", "M"), labels = c("Female", "Male"))
) |>
tidyr::drop_na()
fit_ols <- lm(`Reported Weight` ~ `Measured Weight` * Sex, data = d_weight)
fit_robust <- robustbase::lmrob(`Reported Weight` ~ `Measured Weight` * Sex, data = d_weight)
# The R2 of OLS and robust fits are different statistics, so they are left out
apa_parameters(list(OLS = fit_ols, Robust = fit_robust), performance_parameters = NA) |>
apa_flextable(row_title_column = Model, note = TRUE)Table 25
Ordinary and Robust Regressions of Reported Weight on Measured Weight and Sex
Variable |
B |
SE |
β |
t |
df |
p |
|---|---|---|---|---|---|---|
OLS | ||||||
Constant |
41.32 |
2.17 |
.00 |
19.06 |
179 |
<.001 |
Measured Weight |
0.26 |
0.04 |
.29 |
7.28 |
179 |
<.001 |
Sex–Male |
−39.96 |
3.93 |
−1.45 |
−10.17 |
179 |
<.001 |
Measured Weight × Sex–Male |
0.73 |
0.06 |
2.04 |
12.96 |
179 |
<.001 |
Robust | ||||||
Constant |
2.39 |
1.50 |
1.59 |
179 |
.11 |
|
Measured Weight |
0.95 |
0.03 |
35.66 |
179 |
<.001 |
|
Sex–Male |
3.03 |
2.13 |
1.43 |
179 |
.16 |
|
Measured Weight × Sex–Male |
−0.02 |
0.03 |
−0.59 |
179 |
.56 |
|
Note. N = 183. Estimates are from a robust regression using MM-estimation with bisquare weights (Yohai, 1987). Standard errors are robust estimates. N = 183. Cases with weights below .10 (n = 5) had almost no influence on the estimates. β = standardized coefficient. | ||||||
The one error ruins the OLS fit: women’s reported weights seem to rise by only 0.26 kg per kilogram of measured weight, and men’s seem to rise much faster, a large and significant interaction. The robust fit gives the case almost no weight and shows what the rest of the data say: reported weight rose by about 0.95 kg per kilogram for both sexes, with no interaction. The note names the estimator and says how many cases had almost no influence. Standardized coefficients are not shown for robust fits, because standardizing with the ordinary standard deviations does not match them.
MASS::rlm fits robust regressions as well, by M-estimation with Huber weights by default (or method = "MM"). apa_performance gives the robust R2 and residual scale of lmrob models (and the robust scale of rlm models), and nested lmrob models are compared with robust Wald tests. Robust regression does not fix the data: here, the better course is to correct the error, which gives nearly the same estimates as the robust fit. Robust regression protects against errors and unusual cases that cannot be found or fixed.
Quantile Regression
Ordinary regression models the mean of the outcome. Quantile regression (quantreg::rq) models a quantile instead, such as the median, which is less affected by outliers, or the lower and upper quartiles, which show whether predictors matter more for low or high scorers. Here, self-reported ACT scores in the sat.act data set (Revelle, 2026) depend on education (from 0, less than 12 years, to 5, a graduate degree) and gender, at the 25th, 50th, and 75th percentiles (tau = c(.25, .5, .75)):
d_act <- sat.act |>
transmute(
ACT,
Education = education,
Gender = factor(gender, levels = 1:2, labels = c("Male", "Female"))
)
fit_quantiles <- quantreg::rq(
ACT ~ Education + Gender,
tau = c(.25, .5, .75),
data = d_act
) |>
# ACT scores are whole numbers, so quantreg warns that the solution "may
# be nonunique": other coefficients can fit equally well
suppressWarnings()
apa_parameters(fit_quantiles) |>
apa_flextable(note = TRUE)Table 26
Quantile Regressions of ACT Scores on Education and Gender
Variable |
τ = .25 |
τ = .50 |
τ = .75 |
|||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
B |
SE |
t(697) |
p |
B |
SE |
t(697) |
p |
B |
SE |
t(697) |
p |
|||
Constant |
23.67 |
0.91 |
26.12 |
<.001 |
28.00 |
0.70 |
40.02 |
<.001 |
33.00 |
0.64 |
51.93 |
<.001 |
||
Education |
0.67 |
0.24 |
2.83 |
.005 |
0.60 |
0.18 |
3.29 |
.001 |
0.00 |
0.14 |
0.00 |
>.99 |
||
Gender–Female |
−0.67 |
0.69 |
−0.97 |
.33 |
−1.40 |
0.54 |
−2.57 |
.01 |
−1.00 |
0.30 |
−3.35 |
<.001 |
||
Note. Estimates are from quantile regressions (Koenker & Bassett, 1978) of ACT at τ = .25, .50, and .75. Standard errors are Hendricks–Koenker sandwich estimates (Hendricks & Koenker, 1992). N = 700. | ||||||||||||||
Each quantile’s estimates are under their own column spanner. A coefficient is the change in that quantile of ACT per unit of the predictor: education was related to the lower quartile and the median of ACT, but not to the upper quartile, and women’s scores were lower than men’s at the median and the upper quartile (and, not significantly, at the lower quartile). With quantiles = "rows", the quantiles are stacked under heading rows instead. A model with a single quantile (e.g., tau = .5) has a single set of columns.
Standard errors are Hendricks–Koenker sandwich estimates (se = "nid"), which allow the variability of the errors to differ across cases. Use se = "iid" for estimates that assume the same variability for every case, se = "ker" for Powell kernel estimates, or se = "boot" for bootstrap estimates. The note names the kind of standard errors.
apa_performance gives the Koenker–Machado R1 of each quantile, the quantile regression counterpart of R2 (usually smaller), and AIC:
apa_performance(fit_quantiles)Table 27
Fit of the Quantile Regressions of ACT Scores
Quantile |
R1 |
AIC |
|---|---|---|
.25 |
.02 |
4,422.18 |
.50 |
.02 |
4,253.28 |
.75 |
.00 |
4,204.82 |
Lists of quantile regression models are compared by R1 and AIC, without tests.
Collinearity
apa_collinearity reports the variance inflation factor (VIF) and tolerance of each predictor, as computed by performance::check_collinearity. In the third ACT model above, the two SAT scores are correlated, but not enough to inflate their standard errors much:
apa_collinearity(lm3) |>
apa_flextable(note = TRUE)Table 28
Collinearity Diagnostics of the Full Model of ACT Scores
Variable |
VIF |
95% CI for VIF |
Tolerance |
|---|---|---|---|
Age |
1.78 |
[1.61, 1.92] |
.56 |
Gender |
1.07 |
[1.03, 1.10] |
.93 |
Education |
1.84 |
[1.67, 2.00] |
.54 |
SATV |
1.74 |
[1.58, 1.88] |
.58 |
SATQ |
1.79 |
[1.62, 1.93] |
.56 |
Note. For Education, which has more than 1 df, VIF is the generalized VIF (Fox & Monette, 1992). Tolerance = 1/VIF, the proportion of a predictor’s variance not explained by the other predictors. VIF = variance inflation factor; CI = confidence interval. | |||
Education has more than 1 degree of freedom, so its VIF is the generalized VIF, and the note says so. Add "SE_factor" to columns for VIF1/(2df), which can be compared across terms with different degrees of freedom. To bold large VIFs, set flag to your cutoff (e.g., flag = 5 or flag = 10). In models with interactions, the VIFs of the interaction and its components are high in part because product terms are correlated with their components, and the note explains that this does not affect the test of the interaction.
lm(ACT ~ SATV * SATQ, data = d) |>
apa_collinearity(flag = 10) |>
apa_flextable(note = TRUE)Table 29
Collinearity Diagnostics With an Uncentered Interaction
Variable |
VIF |
95% CI for VIF |
Tolerance |
|---|---|---|---|
SATV |
18.20 |
[16.26, 20.09] |
.05 |
SATQ |
19.39 |
[17.32, 21.41] |
.05 |
SATV × SATQ |
57.17 |
[51.06, 63.12] |
.02 |
Note. The VIFs of interaction terms and their components are high partly because product terms are correlated with their components; this does not affect the tests of the interactions. Tolerance = 1/VIF, the proportion of a predictor’s variance not explained by the other predictors. VIF = variance inflation factor; CI = confidence interval. VIFs of 10 or more are bolded. | |||
With centered predictors, these VIFs are small, and the note leaves this out.
lm(ACT ~ SATV * SATQ, data = datawizard::center(d)) |>
apa_collinearity(flag = 10) |>
apa_flextable(note = TRUE)Table 30
Collinearity Diagnostics With a Centered Interaction
Variable |
VIF |
95% CI for VIF |
Tolerance |
|---|---|---|---|
SATV |
1.78 |
[1.63, 1.94] |
.56 |
SATQ |
1.76 |
[1.61, 1.92] |
.57 |
SATV × SATQ |
1.20 |
[1.13, 1.27] |
.84 |
Note. Tolerance = 1/VIF, the proportion of a predictor’s variance not explained by the other predictors. VIF = variance inflation factor; CI = confidence interval. | |||
Table Notes
A regression table often needs a note that defines its symbols and explains its stars. apa_parameters records how each table was made, and apa_note turns that record into note text. For the hierarchical regression above, the note defines the standardized coefficient, the change in R2, and the F tests, and it explains the stars:
tbl_lm <- apa_parameters(list(lm1, lm2, lm3))
apa_note(tbl_lm)[1] "*N* = 687. β = standardized coefficient; Δ*R*^2^ = change in *R*^2^; *F* = test of the change in fit from the previous model (for the first model, from a model with only a constant). ^\\* ^*p* ≤ .05. ^\\*\\* ^*p* ≤ .01. ^\\*\\*\\* ^*p* ≤ .001."
The note changes with the table. With robust standard errors (vcov) and confidence intervals, it says which standard errors were used and defines CI:
apa_parameters(
lm3,
predictor_parameters = c("Parameter", "Coefficient", "SE", "CI", "t", "df_error", "p"),
vcov = "HC3"
) |>
apa_note()[1] "Standard errors are heteroskedasticity-consistent (HC3). *N* = 687. CI = confidence interval."
For logistic regression, it defines the odds ratio. For count models, it defines the incidence rate ratio, and for ordinal models, it says that thresholds are not tested. For mixed models (lme4), it gives the method used to approximate the degrees of freedom of the t tests (Kenward–Roger by default).
apa_parameters(glm1, starred = "p") |>
apa_note()[1] "*N* = 1,421. *OR* = odds ratio. ^\\* ^*p* ≤ .05. ^\\*\\* ^*p* ≤ .01. ^\\*\\*\\* ^*p* ≤ .001."
The text is in markdown and does not start with “Note.” because apaquarto adds that. With apaquarto, use apa_note in the apa-note chunk option with !expr. Chunk options are evaluated before the chunk runs, so make the table in an earlier chunk (as tbl_lm was made above) and display it in the chunk with the note. Write it as apa7::apa_note, because in documents with cached chunks, chunk options can be evaluated before library(apa7) takes effect:
```{r}
#| label: tbl-lm-note
#| apa7-width: landscape
#| tbl-cap: Hierarchical Regression Predicting ACT Scores
#| apa-note: !expr apa7::apa_note(tbl_lm)
tbl_lm
```Table 31
Hierarchical Regression Predicting ACT Scores
Model |
Variable |
B |
SE |
β |
t |
df |
p |
|---|---|---|---|---|---|---|---|
Model 1 |
|||||||
Constant |
27.35 |
0.59 |
.00 |
46.55 |
684 |
<.001 |
|
Age |
0.06 |
0.02 |
.11 |
2.93 |
684 |
.004 |
|
Gender–Female |
−0.40 |
0.38 |
−.04 |
−1.03 |
684 |
.30 |
|
R2 |
.01 |
||||||
F(2, 684) |
4.90** |
||||||
Model 2 |
|||||||
Constant |
27.54 |
0.80 |
.00 |
34.47 |
679 |
<.001 |
|
Age |
0.02 |
0.03 |
.03 |
0.60 |
679 |
.55 |
|
Gender–Female |
−0.57 |
0.38 |
−.06 |
−1.49 |
679 |
.14 |
|
Education–High School |
−0.24 |
0.97 |
−.01 |
−0.25 |
679 |
.81 |
|
Education–Some College |
−0.78 |
1.00 |
−.04 |
−0.78 |
679 |
.44 |
|
Education–Bachelor |
0.86 |
0.71 |
.09 |
1.20 |
679 |
.23 |
|
Education–Master |
1.57 |
0.83 |
.13 |
1.89 |
679 |
.06 |
|
Education–Doctorate |
1.99 |
0.89 |
.17 |
2.25 |
679 |
.03 |
|
R2 |
.04 |
||||||
ΔR2 |
.02 |
||||||
F(5, 679) |
4.95*** |
||||||
Model 3 |
|||||||
Constant |
8.15 |
1.09 |
.00 |
7.46 |
677 |
<.001 |
|
Age |
0.05 |
0.02 |
.11 |
2.77 |
677 |
.006 |
|
Gender–Female |
0.23 |
0.30 |
.02 |
0.75 |
677 |
.45 |
|
Education–High School |
0.08 |
0.75 |
.00 |
0.10 |
677 |
.92 |
|
Education–Some College |
0.14 |
0.77 |
.01 |
0.18 |
677 |
.85 |
|
Education–Bachelor |
0.86 |
0.55 |
.09 |
1.57 |
677 |
.12 |
|
Education–Master |
1.12 |
0.64 |
.09 |
1.75 |
677 |
.08 |
|
Education–Doctorate |
1.05 |
0.69 |
.09 |
1.52 |
677 |
.13 |
|
SATV |
0.01 |
0.00 |
.31 |
8.01 |
677 |
<.001 |
|
SATQ |
0.02 |
0.00 |
.39 |
10.12 |
677 |
<.001 |
|
R2 |
.43 |
||||||
ΔR2 |
.39 |
||||||
F(2, 677) |
231.40*** |
Without apaquarto (e.g., in a plain Quarto or R Markdown document, or a table saved to Word with flextable::save_as_docx), apa_flextable can put the note below the table itself. With note = TRUE, it uses the note from apa_note; a character string is used as the note instead. The note is added after the column widths are set, so a long note does not stretch the table.
apa_parameters(glm1, starred = "p") |>
apa_flextable(note = TRUE)Table 32
Logistic Regression With a Generated Note
Variable |
B |
SE |
OR |
z |
p |
|---|---|---|---|---|---|
Constant |
−1.12 |
0.25 |
0.33 |
−4.48 |
<.001*** |
Extraversion |
0.07 |
0.01 |
1.07 |
4.65 |
<.001*** |
Neuroticism |
0.01 |
0.01 |
1.01 |
0.56 |
.57 |
Sex–Male |
−0.24 |
0.11 |
0.79 |
−2.12 |
.03 * |
Note. N = 1,421. OR = odds ratio. * p ≤ .05. ** p ≤ .01. *** p ≤ .001. | |||||
Do not use note with the apa-note chunk option, or the note will appear twice.
The definitions come from the abbreviation slot of each column’s format, so any column with a definition is defined in the note. Symbols such as SE and t have no definition by default. To add one, or to reword a definition, change the slot in the column_formats passed to apa_parameters (or set it for every table with apa7_defaults(column_formats = cf)):
cf <- column_formats()
cf$SE@abbreviation <- "standard error"
cf$Std_Coefficient@abbreviation <- "standardized regression coefficient"
apa_parameters(lm1, column_formats = cf) |>
apa_note()[1] "*N* = 687. *SE* = standard error; β = standardized regression coefficient."
The generated note is a starting point. Add to it with paste (e.g., paste(apa_note(tbl_lm), "Education was dummy coded with None as the reference group.")), or use collapse = NULL to get one sentence per element, so you can drop or reword sentences. apa_note reads an attribute of the table that dplyr functions such as mutate and filter keep but some operations (e.g., joins) drop, so call it on the table that apa_parameters returned.
Citations in notes
Some notes cite the articles that describe a method: for example, the notes of meta-analysis tables cite the articles on trim and fill and the multilevel I2, and the notes of lavaan model comparisons cite the article on the scaled χ2 difference test. In the console, and in documents without the references, the citations are written as text (e.g., “(Duval & Tweedie, 2000)”), which you would add to the reference list by hand.
To have the citations formatted and added to the reference list automatically, write the references that come with apa7 to the document’s folder in the setup chunk and list the file in the YAML header:
apa7::apa7_write_bib("apa7.bib")bibliography: [references.bib, apa7.bib]In a Quarto project, the bibliography can also be set for the whole project in _quarto.yml or for a folder in _metadata.yml, and apa7 finds it there.
When the document is rendered, apa_note writes each citation whose reference is in the document’s bibliography as a Pandoc citation key (e.g., [@duvalTrimFillSimple2000]), which Pandoc (or apaquarto) turns into a citation such as “(Duval & Tweedie, 2000)” and an entry in the reference list. This works for notes in the apa-note chunk option and from apa_flextable(note = TRUE). The keys are those that the Better BibTeX extension for Zotero makes, so references exported from Zotero work, too.
To choose the form yourself, use apa_note(tbl, citations = "keys") or citations = "text", or set it for all notes with options(apa7.citations = "keys"). Text is the right choice for tables saved directly to Word (e.g., with flextable::save_as_docx), because Pandoc never sees them.
Printing Options
The apa7.print option controls how the output of apa_parameters, apa_performance, and apa_performance_comparison is displayed.
-
"auto"(default): table in Quarto and R Markdown documents, tibble in the console. -
"flextable": table everywhere. -
"tibble": tibble everywhere.
options(apa7.print = "flextable")To get the table with non-default settings, pass the output to apa_flextable, which always returns a flextable.