This functions calculates the correlation coefficient of the input vectors, matrix or data frame. By default, the correlation coefficient of pearson is computed.
ds.correlation(x, y=NULL, cor.method="pearson", tojson=FALSE)
x | A numeric vector, matrix or data frame |
---|---|
y | A vector, matrix or data frame with same dimension as x. By default it is equal with NULL. |
cor.method | The correlation coefficient method to compute: "pearson" (default), "kendall" or "spearman". |
tojson | If TRUE the results are returned in json format, default returns a data frame |
This function returns an upper triangle matrix with the correlation coefficients of the input data. The correlation coefficient of pearson is computed, by default. Other options are "kendall" or "spearman".
# with data frame as an input and the default parameters data <- iris ds.correlation(data, cor.method = "pearson", tojson=FALSE)#> Sepal.Length Sepal.Width Petal.Length Petal.Width #> Sepal.Length 1 -0.12 0.87 0.82 #> Sepal.Width 0 1.00 -0.43 -0.37 #> Petal.Length 0 0.00 1.00 0.96 #> Petal.Width 0 0.00 0.00 1.00# with matrix as an input , different parameters and json output Matrix <- cbind(Uni05 = (1:200)/21, Norm = rnorm(200), `5T` = rt(200, df = 5), Gam2 = rgamma(200, shape = 2)) ds.correlation(Matrix, cor.method = "kendall", tojson=TRUE)#> [{"Uni05":1,"Norm":0.08,"X5T":0,"Gam2":0.05,"_row":"Uni05"},{"Uni05":0,"Norm":1,"X5T":-0.01,"Gam2":0.05,"_row":"Norm"},{"Uni05":0,"Norm":0,"X5T":1,"Gam2":-0.05,"_row":"5T"},{"Uni05":0,"Norm":0,"X5T":0,"Gam2":1,"_row":"Gam2"}]