cond_maha {unusualprofile}R Documentation

Calculate the conditional Mahalanobis distance for any variables.

Description

Calculate the conditional Mahalanobis distance for any variables.

Usage

cond_maha(
  data,
  R,
  v_dep,
  v_ind = NULL,
  v_ind_composites = NULL,
  mu = 0,
  sigma = 1,
  use_sample_stats = FALSE,
  label = NA
)

Arguments

data

Data.frame with the independent and dependent variables. Unless mu and sigma are specified, data are assumed to be z-scores.

R

Correlation among all variables.

v_dep

Vector of names of the dependent variables in your profile.

v_ind

Vector of names of independent variables you would like to control for.

v_ind_composites

Vector of names of independent variables that are composites of dependent variables

mu

A vector of means. A single value means that all variables have the same mean.

sigma

A vector of standard deviations. A single value means that all variables have the same standard deviation

use_sample_stats

If TRUE, estimate R, mu, and sigma from data. Only complete cases are used (i.e., no missing values in v_dep, v_ind, v_ind_composites).

label

optional tag for labeling output

Value

a list with the conditional Mahalanobis distance

Examples

library(unusualprofile)
library(simstandard)

m <- "
Gc =~ 0.85 * Gc1 + 0.68 * Gc2 + 0.8 * Gc3
Gf =~ 0.8 * Gf1 + 0.9 * Gf2 + 0.8 * Gf3
Gs =~ 0.7 * Gs1 + 0.8 * Gs2 + 0.8 * Gs3
Read =~ 0.66 * Read1 + 0.85 * Read2 + 0.91 * Read3
Math =~ 0.4 * Math1 + 0.9 * Math2 + 0.7 * Math3
Gc ~ 0.6 * Gf + 0.1 * Gs
Gf ~ 0.5 * Gs
Read ~ 0.4 * Gc + 0.1 * Gf
Math ~ 0.2 * Gc + 0.3 * Gf + 0.1 * Gs"
# Generate 10 cases
d_demo <- simstandard::sim_standardized(m = m, n = 10)

# Get model-implied correlation matrix
R_all <- simstandard::sim_standardized_matrices(m)$Correlations$R_all

cond_maha(data = d_demo,
          R = R_all,
          v_dep = c("Math", "Read"),
          v_ind = c("Gf", "Gs", "Gc"))

[Package unusualprofile version 0.1.4 Index]