Comments (4)
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:
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:
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.
from semptools.
Hi, thanks for this issue, I'd love to see some support too, this could be a great package
from semptools.
Supported since 0.2.9.5.
from semptools.
Related Issues (20)
- Add support for 2nd order factors in `set_sem_layout()` HOT 1
- `set_sem_layout()`: Add an argument to shift the indicators to left/right or up/down
- `factor_point_to`: Use named vector to set the argument HOT 1
- `set_cfa_layout()`: Cannot handle a CFA plot with no factor covariances HOT 1
- `set_curve()`: Bug fix: Failed to work for some bidirecational edges
- Updat r-lib GitHub actions HOT 1
- `set_cfa_layout()`: Add support for models with factor covariances fixed to zero HOT 2
- Update the help page of `set_sem_layout()` on manifest vars and 2nd-order factors HOT 1
- When setting curve, positive means outward and negative means inward
- set_cfa_layout() HOT 4
- Remark that it only officially supports RAM-style plots HOT 1
- `set_edge_label_position()` does not work on factor loadings
- Find a better way to handle CFA models with items loading on more than one factor HOT 1
- CRAN 0.2.9.11
- Update articles HOT 1
- Revise the internal workflow
- Add more informative error and warning messages for `set_cfa_layout()` and `set_sem_layout()` HOT 1
- Reusing pipes
- A function to "expand" or "contract" a diagram
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from semptools.