Skip to contents

Returns a function that takes x and y and returns a formatted output to describe the correlation of x and y

Usage

FormatCorrelation(
  method = "pearson",
  n.format = NULL,
  coeff.format = "%.2f",
  p.format = "%.2g",
  slope.format = NULL,
  rmsd.format = NULL
)

Arguments

method

how to compute correlation coefficients (can be pearson, spearman or kendall)

n.format

format string for the number of data points (see sprintf); can be NULL (don't output the number of data points)

coeff.format

format string for the correlation coefficient (see sprintf); can be NULL (don't output the correlation coefficient)

p.format

format string for the P value (see sprintf); can be NULL (don't output the P value)

slope.format

format string for the slope (see sprintf); can be NULL (don't output the slope)

rmsd.format

format string for the root mean square deviation (see sprintf); can be NULL (don't output the rmsd)

Value

a function

Details

Use this for the correlation parameter of PlotScatter

The slope is computed via a principal component analysis and *not* by linear regression

Examples


set.seed(42)
data <- data.frame(u=runif(500))  # generate some correlated data
data$x <- rnorm(500,mean=data$u)
data$y <- rnorm(500,mean=data$u)

fun <- FormatCorrelation()
fun(data$x,data$y)
#> [1] "R=0.10\np=0.032"

fun <- FormatCorrelation(method="spearman",p.format="%.4g")
fun(data$x,data$y)
#> [1] "ρ=0.09\np=0.05028"