Get stats for x-y pairs in scatterplot matrix
Source:R/tm_g_scatterplotmatrix.R
get_scatterplotmatrix_stats.Rd
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()
.
Arguments
- x, y
(
numeric
) vectors of data values.x
andy
must have the same length.- .f
(
function
) function that accepts x and y as formula input~ x + y
. Defaultstats::cor.test
.- .f_args
(
list
) of arguments to be passed to.f
.- round_stat
(
integer(1)
) optional, number of decimal places to use when rounding the estimate.- round_pval
(
integer(1)
) optional, number of decimal places to use when rounding the p-value.
Value
Character with stats. For stats::cor.test()
correlation coefficient and p-value.
Details
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).
Examples
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"))
#> [1] "cor:0.11\nP:0.6255"
get_scatterplotmatrix_stats(x, y, .f = stats::cor.test, .f_args = list(
method = "pearson",
na.action = na.fail
))
#> [1] "NA"