View source: R/Correlation_Functions.R
ci.rpc | R Documentation |
This function compute confidence intervals for polychoric and polyserial correlations using the Fisher's z-transformation.
ci.rpc(r, se, conf.level = 0.95, rn = NULL)
r |
A numeric value for the correlation coefficient. |
se |
A numeric value for the standard error of the correlation coefficient. |
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 implements the computations suggested by Raykov and Marcoulides (2011, p. 112) to obtain the upper and lower bounds of the approximate confidence interval. These are two-sided confidence intervals based on the z-distribution, with the p-value also based on the z-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, z-statistic, p-value, s-value, BFB, and posterior probability of H1.
Raykov, T., & Marcoulides, G. A. (2011). Introduction to psychometric theory. New York, NY: Routledge.
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
# Polyserial correlation, x1 & y1
ci.rpc(r = HC$correlations[3,1], se = HC$std.errors[3,1], rn = "x1 & y1")
# Polychoric correlation, y1 & y2
ci.rpc(r = HC$correlations[4,3], se = HC$std.errors[4,3], rn = "y1 & y2")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.