r.p: Compute confidence intervals for a set of Pearson...

View source: R/Correlation_Functions.R

r.pR Documentation

Compute confidence intervals for a set of Pearson correlations.

Description

This function computes confidence intervals for Pearson correlations obtained from a hetcor object.

Usage

r.p(x, cont, digits = NULL, pdigits = NULL)

Arguments

x

A hetcor object produced by hetcor().

cont

A character vector of names for ordinal variables.

digits

An integer specifying the number of decimal places to used when rounding the correlation, SE, CI bounds, z-statistic, s-value, BFB, and posterior probability. Defaults to NULL, which does not round the result.

pdigits

An integer specifying the number of decimal places to used when rounding the p-value. Defaults to NULL, which does not round the result.

Details

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

This function applies ci.rp() to all the Pearson correlations in the hetcor object supplied by the user.

Value

A data frame containing the results.

See Also

ci.rp for the function used to get the CIs, p2s for s-values, p2bfb for BFBs, and p2pp for posterior probabilities.

Examples

library(mvtnorm)
library(polycor)
set.seed(12475)
# 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 & x2
r.p(x = HC, cont = c("x1", "x2"))


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