ci.rp: Compute confidence intervals for Pearson correlations.

View source: R/Correlation_Functions.R

ci.rpR Documentation

Compute confidence intervals for Pearson correlations.

Description

This function computes confidence intervals for Pearson correlations using the Fisher's z-transformation.

Usage

ci.rp(r, n, conf.level = 0.95, rn = NULL)

Arguments

r

A numeric value for the correlation coefficient (either a Pearson correlation, or a Spearman rho, which is just a Pearson correlation applied to rank-transformed variables).

n

A numeric value for the sample size.

conf.level

A numeric value for the confidence level of the returned confidence interval, restricted to values between 0 and 1. Defaults to 0.95.

rn

An optional character value to be used as a row name in the data frame returned by this function.

Details

=============================================================================

This function computes the upper and lower bounds of an approximate, two-sided confidence interval based on the z-distribution, with the p-value based on the t-test statistic. Additional statistics are also computed, namely the p-value, s-value, BFB, and posterior probability of H1.

Value

A data frame containing the correlation coefficient, standard error, confidence interval limits, t-statistic, p-value, s-value, BFB, and posterior probability of H1.

See Also

p2s for s-values, p2bfb for BFBs, and p2pp for posterior probabilities.

Examples

library(mvtnorm)
library(polycor)
set.seed(45284)
# Create a population correlation matrix.
R <- matrix(0, 4, 4)
R[upper.tri(R)] <- c(.2, .3, .4, .5, .6, .7)
diag(R) <- 1
R <- cov2cor(t(R) %*% R)
# Show population correlations.
round(R, 4)
# Simulate data with normal distributions and correlation structure R.
mydf <- rmvnorm(1000, mean = rep(0, 4), sigma = R)
mydf <- data.frame(mydf)
names(mydf) <- c("x1", "x2", "y1", "y2")
# Show sample correlations.
Rhat <- round(cor(mydf), 4)
Rhat
# Convert y1 & y2  into ordinal categorical variables.
mydf$y1 <- cut(mydf$y1, c(-Inf, .75, Inf))
mydf$y2 <- cut(mydf$y2, c(-Inf, -1, .5, 1.5, Inf))
# Pearson, polychoric, and polyserial correlations, ML estimates.
HC <- hetcor(mydf, ML = TRUE)
HC

# Pearson correlation, x1 & y1
ci.rp(r = HC$correlations[2,1], n = HC$n, rn = "x1 & x2")


sjpierce/piercer documentation built on Dec. 30, 2024, 3:28 p.m.