Learn R Programming

bayesics (version 2.1.0)

t_test_b: t-test

Description

One and two sample t-tests on vectors of data

Usage

t_test_b(
  x,
  y,
  mu,
  paired = FALSE,
  data,
  heteroscedastic = TRUE,
  prior_mean_mu,
  prior_mean_nu = 0.001,
  prior_var_shape = 0.001,
  prior_var_rate = 0.001,
  CI_level = 0.95,
  ROPE = 0.1,
  improper = FALSE,
  plot = TRUE,
  seed = 1,
  mc_error = 0.002
)

Value

Either an aov_b object, if two samples are being compared, or a list with the following elements:

  • Variable

  • Post Mean

  • Lower (bound of credible interval)

  • Upper (bound of credible interval)

  • Prob Dir (Probability of Direction)

Arguments

x

Either a (non-empty) numeric vector of data values, or a formula of the form outcome ~ grouping variable.

y

an optional (non-empty) numeric vector of data values

mu

optional. If supplied, t_test_b will return the posterior probabilty that the population mean (ignored in 2 sample inference) is less than this value.

paired

logical. If TRUE, provide both x and y as vectors.

data

logical. Only used if x is a formula.

heteroscedastic

logical. Set to FALSE to assume all groups have equal variance.

prior_mean_mu

numeric. Hyperparameter for the a priori mean of the group means.

prior_mean_nu

numeric. Hyperparameter which scales the precision of the group means.

prior_var_shape

numeric. Twice the shape parameter for the inverse gamma prior on the residual variance(s). I.e., \(\sigma^2\sim IG\)(prior_var_shape/2,prior_var_rate/2).

prior_var_rate

numeric. Twice the rate parameter for the inverse gamma prior on the residual variance(s). I.e., \(\sigma^2\sim IG\)(prior_var_shape/2,prior_var_rate/2).

CI_level

numeric. Credible interval level.

ROPE

numeric. Used to compute posterior probability that Cohen's D +/- ROPE

improper

logical. Should we use an improper prior that is proportional to the inverse of the variance?

plot

logical. Should the resulting inverse gamma distribution be plotted?

seed

integer. Always set your seed!!!

mc_error

The number of posterior draws will ensure that with 99% probability the bounds of the credible intervals will be within \(\pm\) mc_error\(\times 4s_y\), that is, within 100mc_error% of the trimmed range of y. (Ignored for single population inference.)

Details

A one and two sample t-test is nothing more than a special case of one-way anova. See aov_b for details.

Examples

Run this code
# \donttest{
# Single population
t_test_b(rnorm(50))
# or an alternative input format
t_test_b(outcome ~ 1,
         data = data.frame(outcome = rnorm(50)))

# Two populations
t_test_b(rnorm(50),
         rnorm(15,1))

# or an alternative input format
t_test_b(outcome ~ group_variable,
         data = 
           data.frame(outcome = c(rnorm(50),
                                  rnorm(15,1)),
                      group_variable = rep(c("a","b"),
                                           c(50,15))))
# }


Run the code above in your browser using DataLab