Skip to content

Commit

Permalink
pre-compute some terms
Browse files Browse the repository at this point in the history
  • Loading branch information
philchalmers committed Jun 8, 2020
1 parent 06a280f commit e86267a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions R/gCD.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@
#' plot(gCDresult)
#' plot(gCDresult.outlier)
#'
#' ## include a progress bar
#' gCDresult <- gCD(holzinger, nfact, progress = TRUE)
#'
#' #-------------------------------------------------------------------
#' #Confirmatory with sem
#' model <- sem::specifyModel()
Expand Down Expand Up @@ -97,26 +94,28 @@ gCD <- function(data, model, progress = TRUE, ...)
tmp1 <- cor(data[-ind,])
tmp2 <- mlfact(tmp1, model)
h2 <- tmp2$par
vcovmat <- solve(tmp2$hessian)
inv_vcovmat <- tmp2$hessian
vcovmat <- solve(inv_vcovmat)
DFBETA <- (theta - h2)/sqrt(diag(vcovmat))
gCD <- t(theta - h2) %*% vcovmat %*% (theta - h2)
gCD <- t(theta - h2) %*% inv_vcovmat %*% (theta - h2)
list(dfbeta = DFBETA, gCD = gCD)
}
f_sem <- function(ind, data, model, objective, theta, ...){
tmp2 <- sem::sem(model, data=data[-ind, ], objective=objective, ...)
h2 <- tmp2$coeff
vcovmat <- tmp2$vcov
inv_vcovmat <- solve(vcovmat)
DFBETA <- (theta - h2)/sqrt(diag(vcovmat))
gCD <- t(theta - h2) %*% vcovmat %*% (theta - h2)
gCD <- t(theta - h2) %*% inv_vcovmat %*% (theta - h2)
list(dfbeta = DFBETA, gCD = gCD)
}
f_lavaan <- function(ind, data, model, theta, ...){
tmp <- lavaan::sem(model, data[-ind, ], ...)
h2 <- lavaan::coef(tmp)
vcovmat <- lavaan::vcov(tmp)
inv_vcovmat <- solve(vcovmat)
DFBETA <- (theta - h2)/sqrt(diag(vcovmat))
gCD <- t(theta - h2) %*% vcovmat %*% (theta - h2)
if(gCD > 1000) browser()
gCD <- t(theta - h2) %*% inv_vcovmat %*% (theta - h2)
list(dfbeta = DFBETA, gCD = gCD)
}
f_mirt <- function(ind, data, large, model, theta, sv, ...){
Expand All @@ -125,8 +124,9 @@ gCD <- function(data, model, progress = TRUE, ...)
pars=sv, verbose=FALSE, ...)
h2 <- mirt::extract.mirt(tmp, 'parvec')
vcovmat <- mirt::vcov(tmp)
inv_vcovmat <- solve(vcovmat)
DFBETA <- (theta - h2)/sqrt(diag(vcovmat))
gCD <- t(theta - h2) %*% vcovmat %*% (theta - h2)
gCD <- t(theta - h2) %*% inv_vcovmat %*% (theta - h2)
list(dfbeta = DFBETA, gCD = gCD)
}

Expand Down

0 comments on commit e86267a

Please sign in to comment.