Descriptive Statistics Answer KEY Table

Description

Creates a flextable showing the correct Mean, SD, SEM, and interpretability for each variable. Used as a printable answer KEY for the worksheet (Word/PDF output). For the interactive HTML checker version, use create_stats_table() instead.

Usage

create_answer_table(
  vars,
  stats_data,
  label = NULL,
  quantitative = NULL,
  binary = NULL,
  multi_category = NULL,
  KEY = TRUE
)

Arguments

vars Character vector. Variable names to include, in display order.
stats_data A data frame with columns variable, mean, sd, and sem – typically the output of univariate_stats_answers().
label Character vector or NULL. Variables that are IDs/labels.
quantitative Character vector or NULL. Continuous variables.
binary Character vector or NULL. Dichotomous variables.
multi_category Character vector or NULL. Nominal variables (3+ levels).
KEY Logical. If TRUE (default), fill with computed values. If FALSE, create a blank template with empty cells.

Value

A flextable::flextable() object.

Examples

library("psych350lab")

data(superman, package = "psych350data")
library(dplyr)

my_data <- superman |>
  select(num, year, type, clark_height_in, clark_grp,
         height_diff, height_gap) |>
  filter(year > 1975)

stats <- univariate_stats_answers(my_data)

# Answer KEY
create_answer_table(
  vars = names(my_data), stats_data = stats,
  label = "num", binary = "clark_grp",
  multi_category = c("type", "height_gap")
)

Variable

Mean

SD

SEM

Interpretable?

num

6.000000

3.674235

1.2247449

No - this is a label, not a variable

year

2,001.555556

16.000868

5.3336227

Yes - this is a quantitative variable

type

No - this is a multiple-category variable

clark_height_in

73.446922

1.868635

0.6228785

Yes - this is a quantitative variable

clark_grp

Yes - this is a binary variable

height_diff

8.211457

2.645209

0.9997949

Yes - this is a quantitative variable

height_gap

No - this is a multiple-category variable

# Blank version
create_answer_table(
  vars = names(my_data), stats_data = stats, KEY = FALSE
)

Variable

Mean

SD

SEM

Interpretable?

num

year

type

clark_height_in

clark_grp

height_diff

height_gap