Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find a way to reorganize the nodes in an semPath output #4

Closed
sfcheung opened this issue Jun 7, 2019 · 5 comments
Closed

Find a way to reorganize the nodes in an semPath output #4

sfcheung opened this issue Jun 7, 2019 · 5 comments
Labels
enhancement New feature or request

Comments

@sfcheung
Copy link
Owner

sfcheung commented Jun 7, 2019

This can be done manually using a layout matrix. However, it will be helpful to have function to do this in a user-friendly way.

One possible approach is to read the content of an semPath output and output the layout in a meaningful format. Users can then customize the layout using labels instead of numbers as in the layout argument.

Do this in its own branch:

https://github.com/sfcheung/semptools/tree/cfa_sem

@sfcheung sfcheung added the enhancement New feature or request label Jun 7, 2019
@sfcheung
Copy link
Owner Author

sfcheung commented Jun 7, 2019

Just found out that qgraph already support using labels to specify the matrix for layout:

http://sachaepskamp.com/qgraph/features/1.2.2#Grid_layout

Therefore, no need to write a function for this if the model is a path model that does not have a lot of variables. However, it would still be useful to write a function to easily specify the position of a CFA or SEM model with a lot of indicators.

@sfcheung
Copy link
Owner Author

I am still thinking about how to implement this.

The target users are those willing to use code to generate easily reproducible SEM diagrams. The target users are not those like drawing diagrams using programs like Amos and don't like to use code.

That said, being user friendly to this group of target users, in terms of writing or generating code, is still important.

Approach A:

Specify the latent variables layout as in path models.

layout = matrix(c("x1", NA, NA,
                    NA,"m","y",
                  "x2", NA, NA), byrow = TRUE, 3, 3))

Then just indicate the direction of the indicators for each latent, usually just "up", "right", "down", and "left," and the function will try to calculate the exact position. This will generate a typical SEM diagrams in psychology.

  • Pro:

    • Easy to specify.
  • Con:

    • The function can be a little bit complicate.

Approach B:

Use a shinyapp to specify the exact position. Start the app (call the function) with the semPath call and the data. The app will show the semPath call and the diagram, probably with sliders for each node. The users use the slider to specify the x- and y-positions of each node manually. The required layout, a k-by-2 matrix with the x- and y-positions for the nodes will be generated. Users can copy and paste it and use it as the value for the layout argument.

We can also add a few buttons to allow to automatically align the x or y position of selected nodes (e.g., make all indicators of a latent to have the same x-position).

  • Pros:

    • Full control of the layout.

    • The user can see immediately how semPath will position the nodes.

    • Easy to code because there is no need to compute the positions.

  • Con:

    • Maybe too complicated for some users.

Approach C:

Combing A and B. Use Approach A to generate the starting layout, and use Approach B to adjust the generated layout.

This is not really a third approach. If we decided to do both A and B, then C is subsequently available.

@sfcheung
Copy link
Owner Author

The functions for both CFA models and SEM models have been drafted. I will create a new branch and commit the functions soon.

@sfcheung
Copy link
Owner Author

Will use this branch:

https://github.com/sfcheung/semptools/tree/cfa_sem

@sfcheung
Copy link
Owner Author

set_cfa_position and set_sem_position have been added and tested. They have been merged to the devel and master branches, and the cfa_sem branch has been deleted. Vignettes will be written for them later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant