Learn R Programming

polycor (version 0.5)

hetcor: Heterogeneous Correlation Matrix

Description

Compute a heterogenous correlation matrix, consisting of Pearson product-moment correlations between numeric variables, polyserial correlations between numeric and ordinal variables, and polychoric correlations between ordinal variables.

Usage

hetcor(data, ..., ML = FALSE)
## S3 method for class 'data.frame':
hetcor(data, ML = FALSE, use = c("complete.obs", "pairwise.complete.obs"), ...)
## S3 method for class 'default':
hetcor(data, ..., ML = FALSE)
## S3 method for class 'hetcor':
print(x, digits = max(3, getOption("digits") - 3), ...)

Arguments

data
a data frame consisting of factors and/or numeric variables, or the first of several variables.
...
variables and/or arguments to be passed down.
ML
if TRUE compute maximum-likelihood estimates and their standard errors; if FALSE, compute quick two-step estimates.
use
if "complete.obs", remove observations with any missing data; if "pairwise.complete.obs", compute each correlation using all observations with valid data for that pair of variables.
x
an object of class "hetcor" to be printed.
digits
number of significant digits.

Value

  • Returns an object of class "hetcor" with the following components:
  • correlationsthe correlation matrix.
  • typethe type of each correlation: "Pearson", "Polychoric", or "Polyserial".
  • std.errorsthe standard errors of the correlations, if estimated by ML.
  • nthe number (or numbers) of observations on which the correlations are based.
  • NA.methodthe method by which any missing data were handled: "complete.obs" or "pairwise.complete.obs".

References

Drasgow, F. (1986) Polychoric and polyserial correlations. Pp. 68-74 in S. Kotz and N. Johnson, eds., The Encyclopedia of Statistics, Volume 7. Wiley. Olsson, U. (1979) Maximum likelihood estimation of the polychoric correlation coefficient. Psychometrika 44, 443-460. Rodriguez, R.N. (1982) Correlation. Pp. 193-204 in S. Kotz and N. Johnson, eds., The Encyclopedia of Statistics, Volume 2. Wiley. Ghosh, B.K. (1966) Asymptotic expansion for the moments of the distribution of correlation coefficient. Biometrika 53, 258-262. Olkin, I., and Pratt, J.W. (1958) Unbiased estimation of certain correlation coefficients. Annals of Mathematical Statistics 29, 201-211.

See Also

polychor, polyserial

Examples

Run this code
R <- matrix(0, 4, 4)
R[upper.tri(R)] <- runif(6)
diag(R) <- 1
R <- cov2cor(t(R) %*% R)
round(R, 4)  # population correlations
data <- rmvnorm(1000, rep(0, 4), R)
round(cor(data), 4)   # sample correlations
x1 <- data[,1]
x2 <- data[,2]
y1 <- cut(data[,3], c(-Inf, .75, Inf))
y2 <- cut(data[,4], c(-Inf, -1, .5, 1.5, Inf))
data <- data.frame(x1, x2, y1, y2)
hetcor(data)  # Pearson, polychoric, and polyserial correlations, 2-step est.
hetcor(x1, x2, y1, y2, ML=TRUE) # Pearson, polychoric, polyserial correlations, ML est.

Run the code above in your browser using DataLab