milanwiedemann / lcsm Goto Github PK
View Code? Open in Web Editor NEWAn R package for latent change score modelling (LCSM)
Home Page: https://milanwiedemann.github.io/lcsm/
License: Other
An R package for latent change score modelling (LCSM)
Home Page: https://milanwiedemann.github.io/lcsm/
License: Other
see this paper for ideas and code published on osf Kievit, R. A., Brandmaier, A. M., Ziegler, G., van Harmelen, A.-L., de Mooij, S. M. M., Moutoussis, M., โฆ Dolan, R. J. (2018). Developmental cognitive neuroscience using latent change score models: A tutorial and applications. Developmental Cognitive Neuroscience, 33, 99โ117. https://doi.org/10.1016/j.dcn.2017.11.007
Dear Milan,
this is a great package that substantially speeds up the estimation of multiple LCSMs. However, I wonder how to calculate different LCSMs between groups. In lavaan, you would be able to specify "group" option.
In your "fit_uni_lcsm" and "fit_bi_lcsm" you can pass options to lavaan. I can also specify the "group" option and it provides distinct parameter estimates for each group.
However, these parameter estimates do not differ between groups. It always provides the same estimates for each group. Could this relate to an internal setting of the "group.equal" option that is fixed for all parameters across groups?
Thanks and Best,
Nico
i think theres an error here, only first variance defined, then 0s, see example in readme
see Wang, L., Zhang, Z., & Estabrook, R. (2009). Longitudinal mediation analysis of training intervention effects. In S.-M. Chow, E. Ferrer, & F. Hsieh (Eds.), Statistical methods for modeling human dynamics: An interdisciplinary dialogue (1st ed.). New York, NY: Taylor & Francis.
see how I did this here for shinygains milanwiedemann/suddengains@708d3b7
This came up during rev dep checks of lavaan: the example for 'extract_fit' results in the error:
Error in lavInspect(x, "converged") :
could not find function "lavInspect"
This is also shown on CRAN checks: https://cran.r-project.org/web/checks/check_results_lcsm.html
This is probably due to recent changes in broom.
Yves.
for example a lagged change to change relationship would need at least 3 repeated time points of two constructs
There are data of two time points: before and after the dietary intervention. Follow the following hypothesis; we have been planning to carry out latent change score analysis.
An example of our data has been attached, could you kindly provide the suggestion on model building for it? Both lavaan or openMx were good enough.
Thank you for your help!
meta_toy.zip
this currently doesnt seem to work because the seed = NULL
argument is part of the simulation function
this will be helpful if there are specific specifications needed for a particular model that cant be generated by the functions of this package
Thank you very much for developing this helpful package. I'm trying to create a plot of the path diagram of a bivariate latent change score model. I receive the following error when trying to plot the path diagram:
Error in lavParseModelString(model.syntax = model, warn = warn, debug = FALSE): lavaan ERROR: empty model syntax
Here is a reprex using the supplied examples from the documentation:
library("lavaan")
#> This is lavaan 0.6-12
#> lavaan is FREE software! Please report any bugs.
library("lcsm")
#> Warning: package 'lcsm' was built under R version 4.2.2
bivariateLCSM_syntax <- specify_bi_lcsm(
timepoints = 10,
var_x = "x",
model_x = list(
alpha_constant = TRUE,
beta = TRUE,
phi = TRUE),
var_y = "y",
model_y = list(
alpha_constant = TRUE,
beta = TRUE,
phi = TRUE),
coupling = list(
delta_lag_xy = TRUE,
delta_lag_yx = TRUE),
change_letter_x = "g",
change_letter_y = "j")
bivariateLCSM_fit <- fit_bi_lcsm(
data = data_bi_lcsm,
var_x = names(data_bi_lcsm)[2:4],
var_y = names(data_bi_lcsm)[12:14],
model_x = list(
alpha_constant = TRUE,
beta = TRUE,
phi = FALSE),
model_y = list(
alpha_constant = TRUE,
beta = TRUE,
phi = TRUE),
coupling = list(
delta_lag_xy = TRUE,
xi_lag_yx = TRUE)
)
#> Warning in lav_model_vcov(lavmodel = lavmodel, lavsamplestats = lavsamplestats, : lavaan WARNING:
#> The variance-covariance matrix of the estimated parameters (vcov)
#> does not appear to be positive definite! The smallest eigenvalue
#> (= 3.018389e-16) is close to zero. This may be a symptom that the
#> model is not identified.
plot_lcsm(bivariateLCSM_fit)
#> Error in lavParseModelString(model.syntax = model, warn = warn, debug = FALSE): lavaan ERROR: empty model syntax
sessionInfo()
#> R version 4.2.0 (2022-04-22 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19044)
#>
#> Matrix products: default
#>
#> locale:
#> [1] LC_COLLATE=English_United States.utf8
#> [2] LC_CTYPE=English_United States.utf8
#> [3] LC_MONETARY=English_United States.utf8
#> [4] LC_NUMERIC=C
#> [5] LC_TIME=English_United States.utf8
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] lcsm_0.1.2 lavaan_0.6-12
#>
#> loaded via a namespace (and not attached):
#> [1] compiler_4.2.0 pillar_1.8.1 highr_0.9 R.methodsS3_1.8.2
#> [5] R.utils_2.12.1 tools_4.2.0 digest_0.6.30 tibble_3.1.8
#> [9] evaluate_0.17 lifecycle_1.0.3 R.cache_0.16.0 pkgconfig_2.0.3
#> [13] rlang_1.0.6 reprex_2.0.2 DBI_1.1.3 cli_3.4.1
#> [17] rstudioapi_0.14 yaml_2.3.6 parallel_4.2.0 pbivnorm_0.6.0
#> [21] xfun_0.34 fastmap_1.1.0 withr_2.5.0 styler_1.8.0
#> [25] stringr_1.4.1 dplyr_1.0.10 knitr_1.40 generics_0.1.3
#> [29] fs_1.5.2 vctrs_0.5.0 tidyselect_1.2.0 stats4_4.2.0
#> [33] glue_1.6.2 R6_2.5.1 fansi_1.0.3 rmarkdown_2.17
#> [37] purrr_0.3.5 magrittr_2.0.3 htmltools_0.5.3 MASS_7.3-58.1
#> [41] assertthat_0.2.1 mnormt_2.1.1 utf8_1.2.2 stringi_1.7.8
#> [45] R.oo_1.25.0
Created on 2022-11-05 with reprex v2.0.2
Any help would be greatly appreciated. Thanks!
at the moment the matrix needs to be specified manually, see the following for a univariate an bivariate lcsm with seven time points.
# Create layout matrix for univariate LCSM without intercepts
layout_uni_lcsm <- matrix(
c(NA, "g2", NA, NA, NA, NA, NA,
NA, "dx2", "dx3", "dx4", "dx5", "dx6", "dx7",
"lx1", "lx2", "lx3", "lx4", "lx5", "lx6", "lx7",
"x1", "x2", "x3", "x4", "x5", "x6", "x7"),
4, byrow = TRUE)
# Create layout matrix for bivariate LCSM without intercepts
layout_bi_lcsm <- matrix(
c(NA, NA, "y1", "y2", "y3", "y4", "y5", "y6", "y7",
NA, NA, "ly1", "ly2", "ly3", "ly4", "ly5", "ly6", "ly7",
NA, NA, NA, "dy2", "dy3", "dy4", "dy5", "dy6", "dy7",
NA, "j2",NA,NA, NA, NA, NA, NA, NA,
NA, "g2", NA,NA, NA, NA, NA, NA, NA,
NA, NA, NA, "dx2", "dx3", "dx4", "dx5", "dx6", "dx7",
NA, NA, "lx1", "lx2", "lx3", "lx4", "lx5", "lx6", "lx7",
NA, NA, "x1", "x2", "x3", "x4", "x5", "x6", "x7"),
8, byrow = TRUE)
Dear Milan,
thank you very much for this very helpful package! I use it to analyse data of an intervention study with three measurement points. I have two different questions and would be very happy to hear your opinion about this:
My univariate LCSM is specified as follows:
uni_lcsm <- fit_uni_lcsm(data = Rohdaten_wide_final,
var = c("t1_hrw", "t2_hrw", "t3_hrw"),
model = list(
alpha_constant = T,
beta = T,
phi = T))
My bivariate LCSM is specified as follows:
bi_lcsm <- fit_bi_lcsm(data = Rohdaten_wide_final,
var_x = c("t1_hrw", "t2_hrw", "t3_hrw"),
var_y = c("t1_new_WLT_LS_g", "t2_new_WLT_LS_g", "t3_new_WLT_LS_g"),
model_x = list(
alpha_constant = T,
beta = T,
phi = T),
model_y = list(
alpha_constant = T,
beta = T,
phi = T),
coupling = list(
delta_lag_xy = T,
xi_lag_yx = T))
Any support is well appreciated
Sophie
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.