It obtains the coefficients of correlation and p-value between all the variables of a data table. The methods to apply are Pearson, Spearman , Kendall and lin's concordance index. In case of not specifying the method, the Pearson method will be used. The results are similar to SAS.

correlation(
  x,
  y = NULL,
  method = c("pearson", "kendall", "spearman", "lin"),
  alternative = "two.sided"
)

Arguments

x

table, matrix or vector

y

table, matrix or vector

method

"pearson", "kendall", "spearman", "lin"

alternative

"two.sided", "less", "greater"

Value

The correlation matrix with its probability

Details

Parameters equal to function cor()

References

Lin LI. A concordance correlation coefficient to evaluate reproducibility. Biometrics. 1989; 45, 255-268.

See also

Examples

library(agricolae) data(soil) # example 1 analysis<-correlation(soil[,2:8],method="pearson") analysis
#> $correlation #> pH EC CaCO3 MO CIC P K #> pH 1.00 0.55 0.73 -0.33 0.26 0.14 0.59 #> EC 0.55 1.00 0.32 -0.39 0.00 0.46 0.57 #> CaCO3 0.73 0.32 1.00 -0.23 0.30 0.05 0.36 #> MO -0.33 -0.39 -0.23 1.00 0.53 0.56 0.23 #> CIC 0.26 0.00 0.30 0.53 1.00 0.55 0.47 #> P 0.14 0.46 0.05 0.56 0.55 1.00 0.62 #> K 0.59 0.57 0.36 0.23 0.47 0.62 1.00 #> #> $pvalue #> pH EC CaCO3 MO CIC P #> pH 1.000000000 0.0525330 0.004797027 0.27832165 0.38601765 0.65138915 #> EC 0.052532997 1.0000000 0.294159813 0.18740661 0.98782240 0.11113616 #> CaCO3 0.004797027 0.2941598 1.000000000 0.45551075 0.31509291 0.87385528 #> MO 0.278321645 0.1874066 0.455510753 1.00000000 0.06028063 0.04468908 #> CIC 0.386017651 0.9878224 0.315092905 0.06028063 1.00000000 0.05132886 #> P 0.651389152 0.1111362 0.873855279 0.04468908 0.05132886 1.00000000 #> K 0.034846847 0.0398372 0.227586184 0.44234137 0.10181733 0.02442050 #> K #> pH 0.03484685 #> EC 0.03983720 #> CaCO3 0.22758618 #> MO 0.44234137 #> CIC 0.10181733 #> P 0.02442050 #> K 1.00000000 #> #> $n.obs #> [1] 13 #>
# Example 2: correlation between pH, variable 2 and other elements from soil. analysis<-with(soil,correlation(pH,soil[,3:8],method="pearson",alternative="less")) analysis
#> $correlation #> EC CaCO3 MO CIC P K #> pH 0.55 0.73 -0.33 0.26 0.14 0.59 #> #> $pvalue #> EC CaCO3 MO CIC P K #> pH 0.9737 0.9976 0.8608 0.807 0.6743 0.9826 #> #> $n.obs #> [1] 13 #>
# Example 3: correlation between pH and clay method kendall. with(soil,correlation(pH,clay,method="kendall", alternative="two.sided"))
#> #> Kendall's rank correlation tau #> #> data: pH and clay #> z-norm = 3.31896 p-value = 0.0009035325 #> alternative hypothesis: true rho is not equal to 0 #> sample estimates: #> tau #> 0.7105263