cocor | R Documentation |
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.
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 )
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 .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 |
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 |
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.
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.
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.
Returns an object of class 'cocor.indep.groups', 'cocor.dep.groups.overlap', or 'cocor.dep.groups.nonoverlap' depending on the invoked comparison function.
cocor.indep.groups, cocor.dep.groups.overlap, cocor.dep.groups.nonoverlap, as.htest
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.