cor.test(x, ...) ## Default S3 method: cor.test(x, y, alternative = c("two.sided", "less", "greater"), method = c("pearson", "kendall", "spearman"), exact = NULL, conf.level = 0.95, continuity = FALSE, ...) ## S3 method for class 'formula': cor.test(formula, data, subset, na.action, ...)
x, y | numeric vectors of the same length that contain the sample values. The length of the vectors must be greater than two for the "pearson" method and greater than one for the "kendall" and "spearman" methods. Missing (NAs) and infinite values (Inf, -Infs) are ignored. | ||||||
alternative |
a character string that specifies the alternative hypothesis
for the test of correlation between x and y.
Acceptable values are:
| ||||||
method |
a character string that specifies the correlation coefficient that
is used in the test statistic.
Acceptable values are:
| ||||||
exact |
a logical flag to indicate if an exact p-value should be computed.
It is used only with
Kendall's tau-statistic or Spearman's rank correlation, and
only when there are no tie cases.
If exact=NULL (the default), an exact test is used if the observation size is less than 50 for Kendall's tau-statistic or if less than 1291 observations for Spearman's rank correlation. Otherwise an approximation method is used. | ||||||
conf.level |
a numeric value in the range [0, 1] that specifies the confidence level
for the returned confidence interval.
conf.level is used only in Pearson's product moment correlation coefficient and when the number of observations is greater than 3. | ||||||
continuity | a logical scalar. If TRUE, a continuity correction is used for Kendall's tau-statistic or Spearman's rho-statistic when an exact p-value is not computed. Default value is FALSE. | ||||||
formula | a formula to specify which variables to use in the computations. The formula follows the pattern ~ a + b to compute and test the correlation of a and b. | ||||||
data | a data frame or a matrix that contains the objects named in formula. By default, this argument reads in values from the environment. | ||||||
subset | a vector that specifies a subset from the data frame (data) to use in formula. | ||||||
na.action | a character string that specifies how missing values (NAs) are handled. By default, an error is returned. | ||||||
... | any other arguments that are appropriate for the particular call. |
statistic | the value of the test statistic, a t-statistic, or a normalized z-statistic with a names attribute. |
parameter | the degrees of freedom of the null distribution that is associated with statistic when this is a t-distribution. |
p.value | the p-value under the null hypothesis that the correlation between x and y is zero. |
estimate |
the correlation coefficient with one of the following names attributes.
|
null.value |
the hypothesized value for the correlation between x and y,
always 0 with anames attribute which is one of the following.
|
alternative | character string that returns the alternative hypothesis ("two.sided", "greater", or "less") as specified in the alternative argument. |
method |
a string containing the name of the estimator used
for the correlation coefficient. One of the following.
|
data.name | a character string containing the actual names of the x and y vectors. |
conf.int | confidence intervals for the correlation between x and y. Currently, it is only computed for the Pearson's correlation coefficient and only when the number of observations is greater than 3. The confidence level is recorded in the attribute conf.level. |
murder <- Sdatasets::state.x77[, "Murder"] illit <- Sdatasets::state.x77[, "Illiteracy"] cor.test(murder, illit, method="k")x <- rnorm(20, 7, 0.5) y <- rnorm(20, 13, 0.7) cor.test(x, y) cor.test(x, y, conf.level=0.9) cor.test(x, y, method="spearman", alternative="less") cor.test(x, y, method="kendall", exact=FALSE, alternative="greater", continuity=TRUE)
# Transformations can be used cor.test(log(x), log(y), alt="gr")
# With a formula cor.test(~ Fuel + Weight, data=Sdatasets::fuel.frame, subset=(Disp. > 152))