View source: R/Correlation_Functions.R
r.ps | R Documentation |
This function computes confidence intervals for polyserial correlations obtained from a hetcor object.
r.ps(x, cont, ord, digits = NULL, pdigits = NULL)
x |
A hetcor object produced by hetcor(). |
cont |
A character vector of names for continuous variables. |
ord |
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. |
=============================================================================
This function applies ci.pc() to all the polyserial correlations in the hetcor object supplied by the user that are associated with the combinations of variables specified in cont and ord. You can extract a subset of the polyserial correlations from the hetcor object fed to this function by specifying a cont and/or ord argument shorter than used to create the hetcor object.
A data frame containing the results.
Raykov, T., & Marcoulides, G. A. (2011). Introduction to psychometric theory. New York, NY: Routledge.
ci.rpc
for the function used to get the CIs,
p2s
for s-values, p2bfb
for BFBs, and
p2pp
for posterior probabilities.
library(mvtnorm)
library(polycor)
set.seed(63247)
# 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, x2 & y2
r.ps(x = HC, cont = "x2", ord = "y2")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.