Skip to contents

infer_chisq() creates a tidy summary table for results of a chi-squared test. Alternatively, you can select to see expected counts (type = "expected") or observed counts (type = "observed").

Usage

infer_chisq(
  data,
  formula,
  type = c("test", "expected", "observed"),
  digits = 3,
  caption = NULL
)

Arguments

data

A data frame (or tibble).

formula

The variable to run the test on, in formula syntax, ~var.

type

The kind of output to receive. Valid options are either "test" (the default), "expected", or "observed".

digits

The number of digits to round table values to. Defaults to 3.

caption

An override to the table caption. A sensible default is provided.

Value

An object of class flextable.

Examples

suppressWarnings(infer_chisq(mtcars, cyl~gear))
#> Note: NAs always removed for chi squared tests.
#> This message is displayed once per session.
ꭓ² Analysis of cyl and gear
Total Observations: 32
Observations Used: 32

ꭓ²

p-value

df

18.036

0.00121

4

suppressWarnings(infer_chisq(mtcars, cyl~gear, type = "expected"))
Expected Counts for cyl and gear
Total Observations: 32
Observations Used: 32

gear

cyl

3

4

5

4

5.2

4.1

1.7

6

3.3

2.6

1.1

8

6.6

5.2

2.2

suppressWarnings(infer_chisq(mtcars, cyl~gear, type = "observed"))
Observed Counts for cyl and gear
Total Observations: 32
Observations Used: 32

gear

cyl

3

4

5

Total

4

1

8

2

11

6

2

4

1

7

8

12

0

2

14

Total

15

12

5

32