Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test statistics bottleneck #5

Open
haziqj opened this issue Apr 15, 2023 · 0 comments
Open

Test statistics bottleneck #5

haziqj opened this issue Apr 15, 2023 · 0 comments

Comments

@haziqj
Copy link
Owner

haziqj commented Apr 15, 2023

The current bottleneck in the test statistics calculation is the call to lav_model_vcov from the {lavaan} package. It is more apparent when $p$ is large (e.g. $p=15$ models).

get_sensitivity_inv_mat <- function(.lavobject, matrix_type = c("Sensitivity",
"Sandwich")) {
# Returns the matrix H^{-1}, the inverse of the sensitivity matrix
list2env(extract_lavaan_info(.lavobject), environment())
matrix_type <- match.arg(matrix_type, c("Sensitivity", "Sandwich"))
# This extracts the inverse of the observed sensitivity matrix H = E(nabla^2
# pl). It is stored as E.inv as part of the Godambe information matrix (E.inv
# %*% B0 %*% E.inv) because lavoptions has se = "robust.huber.white"
VCOV <- lav_model_vcov(lavmodel = lavmodel,
lavsamplestats = lavsamplestats,
lavoptions = lavoptions,
lavdata = lavdata,
lavpartable = lavpartable,
lavcache = lavcache)
# Note: VCOV here is (H %*% J^{-1} %*% H)^{-1} = H^{-1} %*% J %*% H^{-1} and
# it is the "full" information matrix. E.inv is therefore the unit information
# matrix, and J has the full information.
if (matrix_type == "Sensitivity") {
mat <- attr(VCOV, "E.inv") # not yet divided by sqrt n
} else if (matrix_type == "Sandwich") {
mat <- VCOV # already divided by sqrt n
}
tt <- sum(lavpartable$free != 0)
if (is.null(mat)) mat <- diag(tt)
mat
}

profvis results

Screenshot 2023-04-15 at 7 58 51 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant