wtdHetcor: Weighted heterogeneous correlation matrix.

Description Usage Arguments Details Value Examples

Description

Computes a weighted heterogeneous 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

1
2
3
4
5
6
wtdHetcor(
  dataFrame,
  vars = NULL,
  weights = NULL,
  out = c("wide", "long", "both")
)

Arguments

dataFrame

a data.frame containing all variables

vars

character or numeric vector indicating the variables for which a correlation table should be computed. If NULL, all variables in the data.frame will be used.

weights

Numeric vector of non-negative weights. If NULL, equally weighted cases are assumed, i.e. all weights are defaulted to 1.

out

Specifies the output format. "wide" gives a classical correlation matrix, "long" gives a long format table which includes the type of correlation.

Details

Variables in the data.frame should be accordingly classified as numeric or factor variables. Function resembles the hetcor function from the polycor package, but allows for incorporating weights. For this purpose, the function makes use of the weightedCorr function from the wCorr package.

Value

a correlation table or a list

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
data(mtcars)
# create arbitrary weights
mtcars[,"weight"] <- abs(rnorm(nrow(mtcars), 10,5))
# choose variables
vars <- c("mpg", "cyl", "hp")
# inappropriate classes: variables which are inherently ordinal, have the 'wrong'
# class 'numeric'. (We use only the first imputation of the data set.)
sapply(mtcars[,vars], class)
mtcars[,"cyl"] <- as.factor(mtcars[,"cyl"])
wtdHetcor(mtcars, vars = vars, out = "long")
wtdHetcor(mtcars, vars = vars, weights = "weight", out = "long")

beckerbenj/eatWtd documentation built on Aug. 22, 2020, 9:43 p.m.