cocor (version 1.1-3)

cocor: Compare two correlations based on either dependent or independent groups

Description

Performs a test of significance for the difference between two correlations based on either dependent or independent groups. Dependent correlations can be either overlapping (they share a variable) or nonoverlapping (they have no variable in common). The function expects raw data input from which the correlations are calculated.

Usage

cocor(formula, data, alternative = "two.sided", test = "all", na.action = getOption("na.action"), alpha = 0.05, conf.level = 0.95, null.value = 0, return.htest = FALSE)

Arguments

formula
A formula specifying the correlations and their underlying variables (See details).
data
A list holding two data.frames/matrices for independent groups or a single data.frame/matrix for dependent groups that contain the variables specified in formula as columns.
alternative
A character string specifying whether the alternative hypothesis is two-sided ("two.sided"; default) or one-sided ( "greater" or "less", depending on the direction). Optionally, the initial letter of the character strings ("t", "g", and "l)" can be used.
test
For the tests available, see cocor.indep.groups, cocor.dep.groups.overlap, and cocor.dep.groups.nonoverlap. Use all to apply all tests (default).
na.action
A function which handles missing data. Defaults to getOption("na.action"). See na.omit for more options.
alpha
A number defining the alpha level for the hypothesis test. The default value is $.05$.
conf.level
A number defining the level of confidence for the confidence interval (if a test is used that calculates confidence intervals). The default value is $.95$.
null.value
A number defining the hypothesized difference between the two correlations used for testing the null hypothesis. The default value is $0$. If the value is other than $0$, only the test zou2007 that uses a confidence interval is available.
return.htest
A logical indicating whether the result should be returned as a list containing a list of class 'htest' for each test. The default value is FALSE.

Value

Returns an object of class 'cocor.indep.groups', 'cocor.dep.groups.overlap', or 'cocor.dep.groups.nonoverlap' depending on the invoked comparison function.

Details

Comparison of two correlations based on independent groups
The formula parameter for the comparison of two correlations based on independent groups can either be ~a + b | a + b, ~a + b | a + c, or ~a + b | c + d. The variables of the first correlation -- a and b before the "|" character -- must refer to columns in the data.frame/matrix of the first element in the list of the data object, whereas the variables of the second correlation -- a, b, c, and d after the "|" character -- must refer to columns in the data.frame/matrix of the second element in the list.

Comparison of two overlapping correlations based on dependent groups
The formula parameterfor correlations based on dependent groups with overlapping variables must follow the pattern ~a + b | a + c. The variables of the two correlation -- a, b, and c -- must refer to columns in the data.frame/matrix of the data object.

Comparison of two nonoverlapping correlations based on dependent groups
The formula for correlations based on dependent groups with nonoverlapping variables must have the form ~a + b | c + d. The variables of the two correlation -- a, b, c, and d -- must refer to columns in the data.frame/matrix of the data object.

See Also

cocor.indep.groups, cocor.dep.groups.overlap, cocor.dep.groups.nonoverlap, as.htest

Examples

Run this code
data("aptitude")

# Compare two correlations based on two independet groups
cocor(~logic + intelligence.a | logic + intelligence.a, aptitude)

# Compare two correlations based on two depenendent groups
# The correlations are overlapping
cocor(~knowledge + intelligence.a | logic + intelligence.a, aptitude$sample1)
cocor(~knowledge + intelligence.a | logic + intelligence.a, aptitude$sample2)
# The correlations are nonoverlapping
cocor(~logic + intelligence.b | knowledge + intelligence.a, aptitude$sample1)
cocor(~logic + intelligence.b | knowledge + intelligence.a, aptitude$sample2)

# Return result as a list of class 'htest'
cocor(~knowledge + intelligence.b | logic + intelligence.a, aptitude$sample1,
      return.htest=TRUE)

Run the code above in your browser using DataLab