sign_test_b: Paired sign test

View source: R/sign_test_b.R

sign_test_bR Documentation

Paired sign test

Description

Sign test for paired data.

Usage

sign_test_b(
  x,
  y,
  p0 = 0.5,
  prior = "jeffreys",
  prior_shapes,
  ROPE,
  CI_level = 0.95,
  plot = TRUE
)

Arguments

x

Either numeric vector or binary vector. If the former, z_i = 1_{[x_i > y_i]} if y is supplied, else z_i = 1_{[x_i > 0]}. If the latter, then z_i = x_i.

y

Optional numeric vector to pair with x.

p0

sign_test_b will return the posterior probability that p < p0. Defaults to 0.5, as is most typical in the sign test.

prior

Either "jeffreys" (Beta(1/2,1/2)) or "uniform" (Beta(1,1)). This is ignored if prior_shapes is provided.

prior_shapes

Vector of length two, giving the shape parameters for the beta distribution that will act as the prior on the probability that z_i = 1.

ROPE

positive numeric of length 1 or 2. If of length 1, then ROPE is taken to be p0\pm ROPE. Defaults to \pm 0.05.

CI_level

The posterior probability to be contained in the credible interval for p.

plot

logical. Should a plot be shown?

Details

The sign test looks at z_i:= 1_{[x_i > y_i]} rather than trying to model the distribution of (x_i,y_i). sign_test_b then uses the fact that

z_i \overset{iid}{\sim} Bernoulli(p)

and then makes inference on p. The prior on p is

p \sim Beta(a,b),

where a and b are given by the argument prior_shapes. If prior_shapes is missing and prior = "jeffreys", then a Jeffreys prior will be used (Beta(1/2,1/2)), and if prior = "uniform", then a uniform prior will be used (Beta(1,1)).

Value

(returned invisible) A list with the following:

  • posterior_mean: Posterior mean of the median difference

  • CI: Credible interval for the median difference

  • Pr_less_than_p: Posterior probability that the proportion of differences that are positive is less than the argument p0.

  • ROPE_bounds: ROPE bounds for the proportion of differences that are positive

  • ROPE: Posterior probability that the proportion of differences which are positive falls in the ROPE

  • prop_plot: Prior and posterior plot

  • posterior_parameters: Posterior beta shape parameters for the proportion of differences which are positive

Examples


# Single population
sign_test_b(x = rnorm(50))

## Change ROPE
sign_test_b(x = rnorm(50),
            ROPE = 0.1)

## Change the prior
sign_test_b(x = rnorm(50),
            prior = "uniform")
sign_test_b(x = rnorm(50),
            prior_shapes = c(2,2))

## Two populations
sign_test_b(x = rnorm(50,1),
            y = rnorm(50,0))

## Change reference probability
sign_test_b(x = rnorm(50,1),
            y = rnorm(50,0),
            p0 = 0.7)



bayesics documentation built on March 11, 2026, 5:07 p.m.