View source: R/Correlation_Functions.R
ci.rp | R Documentation |
This function computes confidence intervals for Pearson correlations using the Fisher's z-transformation.
ci.rp(r, n, conf.level = 0.95, rn = NULL)
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. |
=============================================================================
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.
A data frame containing the correlation coefficient, standard error, confidence interval limits, t-statistic, p-value, s-value, BFB, and posterior probability of H1.
p2s
for s-values, p2bfb
for BFBs, and
p2pp
for posterior probabilities.
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.