gCD: Generalized Cook's Distance

View source: R/gCD.R

gCDR Documentation

Generalized Cook's Distance

Description

Compute generalize Cook's distances (gCD's) for exploratory and confirmatory FA. Can return DFBETA matrix if requested. If mirt is used, then the values will be associated with the unique response patterns instead.

Usage

gCD(data, model, vcov_drop = FALSE, progress = TRUE, ...)

## S3 method for class 'gCD'
print(x, ncases = 10, DFBETAS = FALSE, ...)

## S3 method for class 'gCD'
plot(
  x,
  y = NULL,
  main = "Generalized Cook Distance",
  type = c("p", "h"),
  ylab = "gCD",
  ...
)

Arguments

data

matrix or data.frame

model

if a single numeric number declares number of factors to extract in exploratory factor analysis (requires complete dataset, i.e., no missing). If class(model) is a sem (semmod), or lavaan (character), then a confirmatory approach is performed instead

vcov_drop

logical; should the variance-covariance matrix of the parameter estimates be based on the unique data[-i, ] models (Pek and MacCallum, 2011) or original data?

progress

logical; display the progress of the computations in the console?

...

additional parameters to be passed

x

an object of class gCD

ncases

number of extreme cases to display

DFBETAS

logical; return DFBETA matrix in addition to gCD? If TRUE, a list is returned

y

a NULL value ignored by the plotting function

main

the main title of the plot

type

type of plot to use, default displays points and lines

ylab

the y label of the plot

Details

Note that gCD is not limited to confirmatory factor analysis and can apply to nearly any model being studied where detection of influential observations is important.

Author(s)

Phil Chalmers rphilip.chalmers@gmail.com

References

Chalmers, R. P. & Flora, D. B. (2015). faoutlier: An R Package for Detecting Influential Cases in Exploratory and Confirmatory Factor Analysis. Applied Psychological Measurement, 39, 573-574. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1177/0146621615597894")}

Flora, D. B., LaBrish, C. & Chalmers, R. P. (2012). Old and new ideas for data screening and assumption testing for exploratory and confirmatory factor analysis. Frontiers in Psychology, 3, 1-21. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.3389/fpsyg.2012.00055")}

Pek, J. & MacCallum, R. C. (2011). Sensitivity Analysis in Structural Equation Models: Cases and Their Influence. Multivariate Behavioral Research, 46(2), 202-228.

See Also

LD, obs.resid, robustMD, setCluster

Examples


## Not run: 

#run all gCD functions using multiple cores
setCluster()

#Exploratory
nfact <- 3
(gCDresult <- gCD(holzinger, nfact))
(gCDresult.outlier <- gCD(holzinger.outlier, nfact))
plot(gCDresult)
plot(gCDresult.outlier)

#-------------------------------------------------------------------
#Confirmatory with sem
model <- sem::specifyModel()
   F1 -> Remndrs,    lam11
	  F1 -> SntComp,    lam21
	  F1 -> WrdMean,    lam31
	  F2 -> MissNum,    lam41
	  F2 -> MxdArit,    lam52
	  F2 -> OddWrds,    lam62
	  F3 -> Boots,      lam73
  F3 -> Gloves,     lam83
	  F3 -> Hatchts,    lam93
	  F1 <-> F1,   NA,     1
	  F2 <-> F2,   NA,     1
	  F3 <-> F3,   NA,     1

(gCDresult2 <- gCD(holzinger, model))
(gCDresult2.outlier <- gCD(holzinger.outlier, model))
plot(gCDresult2)
plot(gCDresult2.outlier)

#-------------------------------------------------------------------
#Confirmatory with lavaan
model <- 'F1 =~  Remndrs + SntComp + WrdMean
F2 =~ MissNum + MxdArit + OddWrds
F3 =~ Boots + Gloves + Hatchts'

(gCDresult2 <- gCD(holzinger, model, orthogonal=TRUE))
(gCDresult2.outlier <- gCD(holzinger.outlier, model, orthogonal=TRUE))
plot(gCDresult2)
plot(gCDresult2.outlier)

# categorical data with mirt
library(mirt)
data(LSAT7)
dat <- expand.table(LSAT7)
model <- mirt.model('F = 1-5')
result <- gCD(dat, model)
plot(result)

mod <- mirt(dat, model)
res <- mirt::residuals(mod, type = 'exp')
cbind(res, gCD=round(result$gCD, 3))


## End(Not run)

philchalmers/faoutlier documentation built on Aug. 22, 2023, 8:55 p.m.