
Last chance! 50% off unlimited learning
Sale ends in
Uses stats::cor.test()
per default for all numerical input variables and converts results
to character vector.
Could be extended if different stats for different variable types are needed.
Meant to be called from lattice::panel.text()
.
get_scatterplotmatrix_stats(
x,
y,
.f = stats::cor.test,
.f_args = list(),
round_stat = 2,
round_pval = 4
)
Character with stats. For stats::cor.test()
correlation coefficient and p-value.
(numeric
) vectors of data values. x
and y
must have the same length.
(function
) function that accepts x and y as formula input ~ x + y
.
Default stats::cor.test
.
(list
) of arguments to be passed to .f
.
(integer(1)
) optional, number of decimal places to use when rounding the estimate.
(integer(1)
) optional, number of decimal places to use when rounding the p-value.
Presently we need to use a formula input for stats::cor.test
because
na.fail
only gets evaluated when a formula is passed (see below).
x = c(1,3,5,7,NA)
y = c(3,6,7,8,1)
stats::cor.test(x, y, na.action = "na.fail")
stats::cor.test(~ x + y, na.action = "na.fail")
set.seed(1)
x <- runif(25, 0, 1)
y <- runif(25, 0, 1)
x[c(3, 10, 18)] <- NA
get_scatterplotmatrix_stats(x, y, .f = stats::cor.test, .f_args = list(method = "pearson"))
get_scatterplotmatrix_stats(x, y, .f = stats::cor.test, .f_args = list(
method = "pearson",
na.action = na.fail
))
Run the code above in your browser using DataLab