cor.test(x, y, alternative="two.sided", method="pearson")
x
and
y
must have the same length greater than 2.
Missing values (
NA
s) and
+-Inf
s
are allowed but ignored at calculation.
x
and
y
.
"two.sided"
(non-zero),
"greater"
(greater than 0), or
"less"
(less than 0).
"pearson"
,
"kendall"
, or
"spearman"
, depending on
what coefficient of correlation should be used in the test statistic. Only
the first character is necessary.
class "htest"
, containing the following components:
names
attribute.
statistic
containing
its degrees of freedom when
this is a t-distribution.
x
and
y
is zero.
names
attribute
which is either
"tau"
for
Kendall's statistic,
"cor"
for
Pearson's,
or
"rho"
for
Spearman's.
x
and
y
,
coef=0
.
"two.sided"
,
"greater"
, or
"less"
.
"Pearson\(aas product-moment correlation"
,
"Kendall\(aas rank correlation tau"
,
or
"Spearman\(aas rank correlation"
.
x
and
y
vectors.
x
and
y
are mutually uncorrelated.
When
method="pearson"
the data are assumed to come from a bivariate Normal
distribution.
If this is not the case, the other two methods offer
nonparametric alternatives.
If
method="pearson"
the (usual)
Pearson's product moment correlation
coefficient (
r <- cor(x,y)
) is computed, and divided by its standard error
to produce a t-statistic with n-2 degrees of freedom,
where n =
length(x)
=
length(y)
.
This statistic is given by
t <- (sqrt(n-2)*r) / sqrt(1-r2)
.
If
method="kendall"
then
Kendall's tau using ranks is computed.
If
method="spearman"
the rank correlation coefficient is used.
Conover, W. J. (1980). Practical Nonparametric Statistics. 2nd. ed. New York: Wiley.
murder <- state.x77[,"Murder"] illit <- state.x77[,"Illiteracy"] cor.test(murder,illit,method="k") # Transformations can be used cor.test(log(x),log(y),alt="gr")