ggstatsplot (version 0.0.12)

subtitle_contingency_tab: Subtitle for categorical tests

Description

Making text subtitle for contingency analysis (Pearson's chi-square test for independence for between-subjects design or McNemar's test for within-subjects design) or goodness of fit test for a single categorical variable.

Usage

subtitle_contingency_tab(data, main, condition = NULL, counts = NULL,
  ratio = NULL, nboot = 100, paired = FALSE, stat.title = NULL,
  legend.title = NULL, conf.level = 0.95, conf.type = "norm",
  simulate.p.value = FALSE, B = 2000, bias.correct = FALSE, k = 2,
  messages = TRUE, ...)

subtitle_onesample_proptest(data, main, condition = NULL, counts = NULL, ratio = NULL, nboot = 100, paired = FALSE, stat.title = NULL, legend.title = NULL, conf.level = 0.95, conf.type = "norm", simulate.p.value = FALSE, B = 2000, bias.correct = FALSE, k = 2, messages = TRUE, ...)

Arguments

data

A dataframe (or a tibble) from which variables specified are to be taken. A matrix or tables will not be accepted.

main

The variable to use as the rows in the contingency table.

condition

The variable to use as the columns in the contingency table. Default is NULL. If NULL, one-sample proportion test (a goodness of fit test) will be run for the main variable. Otherwise an appropriate association test will be run.

counts

A string naming a variable in data containing counts, or NULL if each row represents a single observation (Default).

ratio

A vector of proportions: the expected proportions for the proportion test (should sum to 1). Default is NULL, which means the null is equal theoretical proportions across the levels of the nominal variable. This means if there are two levels this will be ratio = c(0.5,0.5) or if there are four levels this will be ratio = c(0.25,0.25,0.25,0.25), etc.

nboot

Number of bootstrap samples for computing confidence interval for the effect size (Default: 100).

paired

Logical indicating whether data came from a within-subjects or repeated measures design study (Default: FALSE). If TRUE, McNemar's test subtitle will be returned. If FALSE, Pearson's chi-square test will be returned.

stat.title

Title for the effect being investigated with the chi-square test. The default is NULL, i.e. no title will be added to describe the effect being shown. An example of a stat.title argument will be something like "main x condition" or "interaction".

legend.title

Title text for the legend.

conf.level

Scalar between 0 and 1. If unspecified, the defaults return 95% lower and upper confidence intervals (0.95).

conf.type

A vector of character strings representing the type of intervals required. The value should be any subset of the values "norm", "basic", "perc", "bca". For more, see ?boot::boot.ci.

simulate.p.value

a logical indicating whether to compute p-values by Monte Carlo simulation.

B

an integer specifying the number of replicates used in the Monte Carlo test.

bias.correct

If TRUE, a bias correction will be applied to Cramer's V.

k

Number of digits after decimal point (should be an integer) (Default: k = 2).

messages

Decides whether messages references, notes, and warnings are to be displayed (Default: TRUE).

...

Additional arguments (currently ignored).

Details

For more details about how the effect sizes and their confidence intervals were computed, see documentation in ?rcompanion::cramerV, ?rcompanion::cramerVFit, and ?rcompanion::cohenG.

See Also

ggpiestats

Examples

Run this code
# NOT RUN {
# ------------------------ association tests -----------------------------

set.seed(123)

# without counts data
ggstatsplot::subtitle_contingency_tab(
  data = mtcars,
  main = am,
  condition = cyl,
  nboot = 15
)

# with counts data
# in case of no variation, a `NULL` will be returned.
library(jmv)

as.data.frame(HairEyeColor) %>%
  dplyr::filter(.data = ., Sex == "Male") %>%
  subtitle_contingency_tab(
    data = .,
    main = Hair,
    condition = Sex,
    counts = Freq
  )

# ------------------------ goodness of fit tests ---------------------------

# for reproducibility
set.seed(123)

# with counts
subtitle_contingency_tab(
  data = as.data.frame(HairEyeColor),
  main = Eye,
  counts = Freq,
  ratio = c(0.2, 0.2, 0.3, 0.3)
)

# in case of no variation, only sample size will be shown
subtitle_contingency_tab(
  data = cbind.data.frame(x = rep("a", 10)),
  main = x
)
# }

Run the code above in your browser using DataLab