paired_test: Simulation-based hypothesis test for a paired mean difference

View source: R/s216-applets.R

paired_testR Documentation

Simulation-based hypothesis test for a paired mean difference

Description

This function will run a simulation-based hypothesis test for a paired mean difference or paired median difference between two quantitative variables for matched pairs data.

Usage

paired_test(
  data,
  summary_measure = "mean",
  which_first = 1,
  shift = 0,
  as_extreme_as,
  direction = c("greater", "less", "two-sided"),
  number_repetitions = 1,
  add_normal = FALSE
)

Arguments

data

Vector of differences or a two- or three-column data frame with values for each group in last two columns.

summary_measure

Name of summary measure to return from simulations. Allowed values are "mean" for test of paired mean difference or "median" for test of paired median difference. Defaults to "mean".

which_first

Which column is first in order of subtraction? 1 if subtracting second column from first (1 - 2); 2 if subtracting first column from second (2 - 1). Defaults to 1.

shift

Amount to shift differences for bootstrapping of null distribution.

as_extreme_as

Value of observed paired mean difference.

direction

Direction of alternative hypothesis. Allowed values are "greater", "less", or "two-sided".

number_repetitions

Number of simulated samples.

add_normal

Logical value indicating whether to superimpose a normal curve on the histogram. Defaults to FALSE.

Value

Returns plot of distribution of simulated statistics, with values as or more extreme than specified value highlighted, and reports proportion of simulations as or more extreme than specified as subtitle on plot.

Examples

set.seed(117)
x <- rnorm(25)
y <- x + 1 + rnorm(25, 0, 1.8)
data <- data.frame(x, y)
obs_diff <- mean(x - y)
paired_test(data,
  which_first = 1,
  shift = -obs_diff,
  as_extreme_as = obs_diff,
  direction = "two-sided",
  number_repetitions = 1000
)

greenwood-stat/catstats documentation built on Dec. 14, 2024, 6:25 p.m.