daob / lavaan.survey Goto Github PK
View Code? Open in Web Editor NEWComplex sampling analysis of structural equation models
Complex sampling analysis of structural equation models
Hi.
I am having difficulty using the lavaan.survey function. It seems that it is using a deprecated lavaan function, so I'm getting an error when I run it.
Warning message:
'lavaan::duplicationMatrix' is deprecated.
Use 'lav_matrix_duplication' instead.
See help("Deprecated") and help("lavaan-deprecated").
More information is in the Lavaan Google Group: https://groups.google.com/forum/#!topic/lavaan/yEUcJEWAPq4
Because I need to fit multiple SEMs with weights, I decided to make a convenience function for this. However, it seems that lavaan.survey()
fails to work inside a function environment. My function:
sem_weights = function(model_str, data, weights) {
#fit without weights
fit = sem(model_str, data = data)
#with weights
design = svydesign(ids = ~1,
data = data,
weights = weights)
fit_wtd = lavaan.survey(fit, design)
fit_wtd
}
Calling this with the appropriate parameters:
mod = "Sepal.Length ~ Sepal.Width"
fit = sem_weights(model_str = mod, data = iris, weights = runif(n = nrow(iris), min = 1, max = 2))
Gives a not found error:
Error in lavaan::lavaan(model = model_str, model.type = "sem", int.ov.free = TRUE, :
object 'model_str' not found
I have tried renaming the object but that didn't help. My guess is that lavaan
is searching for the model object in the wrong environment.
Running the same code not using the function works fine:
#fit without weights
fit = sem(model = mod, data = iris)
#with weights
design = svydesign(ids = ~1,
data = iris,
weights = runif(n = nrow(iris), min = 1, max = 2))
fit_wtd = lavaan.survey(fit, design)
#no errors
One can also make the function work by making sure that the model object exists under that name in the global environment, but that defeats the purpose of using a function.
Ideas?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.