Giter Club home page Giter Club logo

lavaan.bingof's People

Watchers

 avatar  avatar  avatar

lavaan.bingof's Issues

When to use Rao-Scott adjustment and when to use Moment Matching?

MOJ (2008): Two strategies exist to compute the GOF tests. Choose $W$ such that

  1. $X^2 = \mathbf e^\top \boldsymbol \Xi \mathbf e$ is computationally easy to obtain.
  2. $X^2= \mathbf e^\top \boldsymbol \Xi \mathbf e$ is asymptotically $\chi^2$.

Our tests that satisfy criteria 1:

  • Wald diagonal
  • RSS
  • Multinomial

Our tests that satisfy criteria 2:

  • Wald
  • Wald VCF
  • Pearson

Test statistics bottleneck

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

Compare other methods for obtaining approximate p-values

The Rao-Scott adjustment seems natural to use in the context of complex sampling. The problem is it requires a Choleski decomposition of $\boldsymbol\Omega_2$, whose estimate can be not full rank. Could we explore stable/modified Choleski decompositions and see how it affects the $p$-value calculations?

install.packages("Matrix")
library(Matrix)

# Create a non-positive definite matrix
A <- matrix(c(4, 2, 2, 2, 4, 2, 2, 2, 4), nrow = 3, ncol = 3)

# Find the nearest positive definite matrix
nearest_pd <- nearPD(A, corr = FALSE, do2eigen = TRUE, ensureSymmetry = TRUE)

# Perform Cholesky decomposition on the nearest positive definite matrix
L <- chol(nearest_pd$mat)

print(L)

Complete the articles

Need to also add the tests (that are commented out in the R files) as an article perhaps.

Add tests

Some of the R code in R/ folder contains tests which are commented. Nice to convert these to unit tests.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.