Giter Site home page Giter Site logo

lavaan.survey's People

Contributors

daob avatar skolenik avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

lavaan.survey's Issues

model not found: using lavaan.survey() inside a function environment

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?

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.