yrosseel / lavaan

an R package for structural equation modeling and more
http://lavaan.org
435 stars 99 forks source link

allow header/footer printing for vector/matrix #262

Closed TDJorgensen closed 1 year ago

TDJorgensen commented 1 year ago

Would you be opposed to this feature? I would find it useful for both lavaan.mi and lavaan.srm, so adding it here would save me the trouble of writing separate print() methods for each. I basically just copied your code in print.lavaan.list(), but use attributes() rather than attr() to simultaneous delete both header and footer from the copy y <- x.

TDJorgensen commented 1 year ago

Whoops, I didn't make a fork because I forgot this PR was still open. Just added another commit to resolve #266

M <- matrix(c(1, 0.7, 0.7, 0.5, 0.7, 1, 0.95, 0.3, 0.7, 0.95, 1, 0.3, 0.5, 0.3, 0.3, 1),
            nrow=4, ncol=4)
set.seed(1901)
data_small <- as.data.frame(MASS::mvrnorm(n = 30, mu = rep(0,4), Sigma = M))
data_small$weights <- c(rep(0.3, 15), rep(100000,15))
lavCor(data_small, estimator = "ML", output = "cov", sampling.weights = "weights")

That output matches the one estimated using weights in my lavaan-forum response:

https://groups.google.com/g/lavaan/c/qdwWEzJb_Qc/m/hArsqyE2BAAJ