cocor {cocor} | R Documentation |
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 |
alternative |
A character string specifying whether the alternative hypothesis is two-sided (" |
test |
For the tests available, see cocor.indep.groups,
cocor.dep.groups.overlap,
and cocor.dep.groups.nonoverlap. Use |
na.action |
A function which handles missing data. Defaults to |
alpha |
A number defining the alpha level for the hypothesis test. The default value is |
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 |
null.value |
A number defining the hypothesized difference between the two correlations used for testing the null hypothesis. The default value is |
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 |
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
andb
before the "|
" character – must refer to columns in the data.frame/matrix of the first element in the list of thedata
object, whereas the variables of the second correlation –a
,b
,c
, andd
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
, andc
– must refer to columns in the data.frame/matrix of thedata
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
, andd
– must refer to columns in the data.frame/matrix of thedata
object.
Value
Returns an object of class 'cocor.indep.groups', 'cocor.dep.groups.overlap', or 'cocor.dep.groups.nonoverlap' depending on the invoked comparison function.
See Also
cocor.indep.groups, cocor.dep.groups.overlap, cocor.dep.groups.nonoverlap, as.htest
Examples
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)