Coder Social home page Coder Social logo

Comments (4)

sfcheung avatar sfcheung commented on August 25, 2024

Thanks a lot for your suggestion. I added preliminary support for exogenous variables to set_sem_layout() in version 0.2.9.5, which can be installed by

remotes::install_github("sfcheung/semptools")

Just include the observed exogenous variables as one-indicator factors in indicator_order and indicator_factor. They will be recognized as observed exogenous variables and can be positioned by factor_layout as if they are factors. Because they have no indicators, in factor_point_to, just use NA. This is an example:

library(lavaan)
#> This is lavaan 0.6-11
#> lavaan is FREE software! Please report any bugs.
library(semPlot)
library(semptools)
mod <-
  'f1 =~ x01 + x02 + x03
   f3 =~ x08 + x09 + x10
   f4 =~ x11 + x12 + x13 + x14
   f3 ~ f1 + x04
   f4 ~ f3 + x05'
fit_sem <- lavaan::sem(mod, sem_example)
p <- semPaths(fit_sem, whatLabels="est",
        sizeMan = 5,
        nCharNodes = 0, nCharEdges = 0,
        edge.width = 0.8, node.width = 0.7,
        edge.label.cex = 0.6,
        style = "ram", 
        mar = c(10,10,10,10),
        DoNotPlot = TRUE)
indicator_order  <- c("x04", "x05", "x01", "x02", "x03",
                      "x11", "x12", "x13", "x14", "x08", "x09", "x10")
indicator_factor <- c("x04", "x05", "f1",  "f1",  "f1",
                      "f4",  "f4",  "f4",  "f4",  "f3",  "f3",  "f3")
factor_layout <- matrix(c( "f1",  "f3", "f4",
                          "x04", "x05",  NA), byrow = TRUE, 2, 3)
factor_point_to <- matrix(c("up", "up", "up",
                             NA,   NA,      NA), byrow = TRUE, 2, 3)
indicator_push <- c(f3 = 2, f4 = 1.5)
indicator_spread <- c(f1 = 2, f4 = 1.5)
loading_position <- c(f3 = .8)
p2 <- set_sem_layout(p,
                    indicator_order = indicator_order,
                    indicator_factor = indicator_factor,
                    factor_layout = factor_layout,
                    factor_point_to = factor_point_to,
                    indicator_push = indicator_push,
                    indicator_spread = indicator_spread,
                    loading_position = loading_position)
plot(p2)

This is the plot:

image

There are still issues that I do not have solutions yet. For example, as shown in the figure above, the function still assumes that the observed exogenous variables have indicators and so reserves some space for them in the plot. I will think about a better solution to handle observed exogenous variables. I decided to push this change now because this version may already be good enough for some cases. (E.g., the empty space can be used to add information such as model fit measures).

If you do not mind doing things not officially supported, for an example like the one above, we can also manually change the margin to remove the empty area by setting $plotOptions$mar using a vector of four numbers (bottom, left, top, and right):

p2_fix <- p2
p2_fix$plotOptions$mar <- c(0, 1, 1, 1)
plot(p2_fix)

This is the result:

image

I have not tested models with observed endogenous variables affected by latent factors because it may not be easy to differentiate them from indicators. A tentative solution is to include them as one-indicator factors and fix the loadings to one and error variances to zero.

I will keep this issue open for now until I have a plan on how to provide better support for observed exogenous variables.

from semptools.

K4tana avatar K4tana commented on August 25, 2024

from semptools.

adamstefkovics avatar adamstefkovics commented on August 25, 2024

Hi, thanks for this issue, I'd love to see some support too, this could be a great package

from semptools.

sfcheung avatar sfcheung commented on August 25, 2024

Supported since 0.2.9.5.

from semptools.

Related Issues (20)

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.