ci.rpc: Compute confidence intervals for polychoric and polyserial...

View source: R/Correlation_Functions.R

ci.rpcR Documentation

Compute confidence intervals for polychoric and polyserial correlations.

Description

This function compute confidence intervals for polychoric and polyserial correlations using the Fisher's z-transformation.

Usage

ci.rpc(r, se, conf.level = 0.95, rn = NULL)

Arguments

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.

Details

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.

Value

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

References

Raykov, T., & Marcoulides, G. A. (2011). Introduction to psychometric theory. New York, NY: Routledge.

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

# 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")


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