Giter VIP home page Giter VIP logo

lcsm's People

Contributors

milanwiedemann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

lcsm's Issues

group variable not considered

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

add contemporaneous coupling effects

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.

two time points latent change score analysis

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
meta_toyh

Improve documentation of plot_lcsm function

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!

add function to automatically define layout matrix for semPlot

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)

Covariates & Multiple Imputation

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:

  1. Is it possible to include covariates like gender or age in the lcsm and how would it be done in the functions fit_uni_lcsm/ fit_bi_lcsm?
  2. In my final analysis I am working with multiple imputed datasets. Can I run the lcsm with imputed data and the final resuls will automatically be pooled like for example the growth.mi function does?

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

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.