Learn R Programming

BayesianFirstAid (version 0.1)

bayes.cor.test: Bayesian First Aid Alternative to Pearson Correlation Test

Description

This is an implementation of an alternative to Person Correlation test as implemented by cor.test. It accepts the same arguments as cor.test. For more information regarding the model assumptions see: http://sumsar.net/blog/2014/03/bayesian-first-aid-pearson-correlation-test/

Usage

bayes.cor.test(x, ...)
"bayes.cor.test"(x, y, alternative = c("two.sided", "less", "greater"), method = c("pearson", "kendall", "spearman"), exact = NULL, cred.mass = 0.95, continuity = FALSE, n.iter = 15000, progress.bar = "text", conf.level, ...)
"bayes.cor.test"(formula, data, subset, na.action, ...)

Arguments

x,y
numeric vectors of data values. x and y must have the same length.
...
not used
alternative
ignored and is only retained in order to mantain compatibility with cor.test
method
ignored
exact
ignored
cred.mass
the amount of probability mass that will be contained in reported credible intervals. This argument fills a similar role as conf.level in cor.test.
continuity
ignored
n.iter
The number of iterations to run the MCMC sampling.
progress.bar
The type of progress bar. Possible values are "text", "gui", and "none".
formula
a formula of the form ~ u + v, where each of u and v are numeric variables giving the data values for one sample. The samples must be of the same length.
data
an optional matrix or data frame containing the variables in the formula formula. By default the variables are taken from environment(formula).
subset
an optional vector specifying a subset of observations to be used.
na.action
a function which indicates what should happen when the data contain NAs. Defaults to getOption("na.action").
conf.level
same as cred.mass and is only retained in order to mantain compatibility with cor.test.

Value

A list of class bayes_cor_test that contains information about the analysis. It can be further inspected using the functions summary, plot, diagnostics and model.code.

Examples

Run this code
# Data from Hollander & Wolfe (1973), p. 187f.
# This example is borrowed from the documentation for cor.test().

# Assessment of tuna quality.  We compare the Hunter L measure of
#  lightness to the averages of consumer panel scores (recoded as
#  integer values from 1 to 6 and averaged over 80 such values) in
#  9 lots of canned tuna.
x <- c(44.4, 45.9, 41.9, 53.3, 44.7, 44.1, 50.7, 45.2, 60.1)
y <- c( 2.6, 3.1, 2.5, 5.0, 3.6, 4.0, 5.2, 2.8, 3.8)

# First a classical correlation test:
cor.test(x, y)

# And here is the Bayesian first aid alternative:
bayes.cor.test(x, y)

# Save the output into a variable for easy plotting and further inspection:
fit <- bayes.cor.test(x, y)
plot(fit)
summary(fit)
model.code(fit)

Run the code above in your browser using DataLab