├── .Rbuildignore
├── .github
├── .gitignore
└── workflows
│ ├── R-CMD-check.yaml
│ ├── check-no-suggests.yaml
│ ├── pkgdown.yaml
│ └── rhub.yaml
├── .gitignore
├── CODE_OF_CONDUCT.md
├── DESCRIPTION
├── NAMESPACE
├── R
├── alkema_microplastics.R
├── blrt.R
├── dagitty.R
├── data-data_mix_ordinal.R
├── data-mac.R
├── data_types.md
├── descriptives.R
├── empathy.R
├── ic_weights.R
├── igraph.R
├── lr_vml.R
├── maene_identity.R
├── mixture-3step.R
├── mixture-pseudo_class.R
├── mixture_gradient.R
├── mixture_predict.R
├── mixture_summaries.R
├── motley_functions.R
├── mplus_functions.R
├── mx_dummies.R
├── mx_fixed_pars.R
├── mx_mixture.R
├── mx_simple_thresholds.R
├── mx_switch_labels.R
├── mx_temp_start.R
├── openmx_functions.R
├── place_variances.R
├── plas_depression.R
├── plot-attributes.R
├── plot-bivariate.R
├── plot-correlation_curves.R
├── plot-generate_layout.R
├── plot-mixture_densities.R
├── plot-plot_sem.R
├── plot-profiles.R
├── plot-thresholds.R
├── plot.R
├── plot_ellipses.R
├── plot_fit.R
├── plot_growth.R
├── plot_merge.R
├── print.R
├── print_layout.R
├── results-mx_ordinal.R
├── results-table_fit.R
├── results-table_results.R
├── results-table_results_mx_model.R
├── select_rows.R
├── skip.R
├── syntax-add_paths.R
├── syntax-as_syntax.R
├── syntax-attributes.R
├── syntax-cfa.R
├── syntax-cors.R
├── syntax-create_scales.R
├── syntax-estimate.R
├── syntax-get_data.R
├── syntax-run.R
├── syntax-utils.R
├── syntax_data_dictionary.R
├── syntax_factor.R
├── syntax_make_constraints.R
├── table_results_lavaan.R
├── utilities.R
├── wald_test.R
├── zegwaard_carecompass.R
└── zzz.R
├── README.Rmd
├── README.md
├── _pkgdown.yml
├── badge.ai
├── codecov.yml
├── cran-comments.md
├── data
├── alkema_microplastics.rda
├── curry_mac.csv
├── data_mix_ordinal.rda
├── empathy.csv
├── maene_identity.rda
├── plas_depression.rda
└── zegwaard_carecompass.rda
├── dev
├── blrt_faster.R
├── check_smart_checklist.R
├── control variable.R
├── lazy_bootstrap.R
├── lca_res.RData
├── local_density_correlations.R
├── prepare_maes_identity.R
├── prepare_welzijnsmeter_data.R
├── res_gmm_nopca.RData
└── try_ic.R
├── docs
├── 404.html
├── CODE_OF_CONDUCT.html
├── articles
│ ├── Generating_syntax.html
│ ├── Generating_syntax_files
│ │ ├── accessible-code-block-0.0.1
│ │ │ └── empty-anchor.js
│ │ └── header-attrs-2.9
│ │ │ └── header-attrs.js
│ ├── LCGA.html
│ ├── Plotting_graphs.html
│ ├── Plotting_graphs_files
│ │ ├── accessible-code-block-0.0.1
│ │ │ └── empty-anchor.js
│ │ ├── figure-html
│ │ │ ├── unnamed-chunk-10-1.png
│ │ │ ├── unnamed-chunk-16-1.png
│ │ │ ├── unnamed-chunk-17-1.png
│ │ │ ├── unnamed-chunk-18-1.png
│ │ │ ├── unnamed-chunk-19-1.png
│ │ │ ├── unnamed-chunk-20-1.png
│ │ │ ├── unnamed-chunk-24-1.png
│ │ │ ├── unnamed-chunk-25-1.png
│ │ │ ├── unnamed-chunk-26-1.png
│ │ │ ├── unnamed-chunk-27-1.png
│ │ │ ├── unnamed-chunk-28-1.png
│ │ │ ├── unnamed-chunk-29-1.png
│ │ │ ├── unnamed-chunk-30-1.png
│ │ │ ├── unnamed-chunk-31-1.png
│ │ │ ├── unnamed-chunk-45-1.png
│ │ │ ├── unnamed-chunk-46-1.png
│ │ │ ├── unnamed-chunk-47-1.png
│ │ │ ├── unnamed-chunk-50-1.png
│ │ │ ├── unnamed-chunk-51-1.png
│ │ │ └── unnamed-chunk-52-1.png
│ │ └── header-attrs-2.9
│ │ │ └── header-attrs.js
│ ├── SMART_LCA_checklist.html
│ ├── Tabulating_results.html
│ ├── Tabulating_results_files
│ │ ├── accessible-code-block-0.0.1
│ │ │ └── empty-anchor.js
│ │ └── header-attrs-2.9
│ │ │ └── header-attrs.js
│ ├── arrow.png
│ ├── arrow.svg
│ ├── curve.png
│ ├── curve.svg
│ ├── error.png
│ ├── error.svg
│ ├── gmm.html
│ ├── gmm_bivariate_bic.png
│ ├── gmm_plotfit.png
│ ├── index.html
│ ├── lca_confirmatory.html
│ ├── lca_confirmatory_files
│ │ └── figure-html
│ │ │ ├── unnamed-chunk-18-1.png
│ │ │ ├── unnamed-chunk-21-1.png
│ │ │ └── unnamed-chunk-21-2.png
│ ├── lca_exploratory.html
│ ├── lca_exploratory_files
│ │ └── figure-html
│ │ │ └── unnamed-chunk-20-1.png
│ ├── lca_lcga.html
│ ├── lca_ordinal.html
│ ├── lca_plot_desc.png
│ ├── lca_prob.png
│ ├── lcga_plot_fit.png
│ ├── lpa.html
│ ├── lpa_bivariate.png
│ ├── lpa_confiratory.html
│ ├── lpa_exploratory.html
│ ├── lpa_profiles.png
│ ├── mod_meas.png
│ ├── mod_meas.svg
│ ├── mod_reg.png
│ ├── mod_reg.svg
│ ├── mod_sem1.png
│ ├── mod_sem1.svg
│ ├── mod_sem2.png
│ ├── mod_sem2.svg
│ ├── pgfig1.png
│ ├── pgfig1.svg
│ ├── pgfig10.png
│ ├── pgfig11.png
│ ├── pgfig2.png
│ ├── pgfig2.svg
│ ├── pgfig2_1.png
│ ├── pgfig2_1.svg
│ ├── pgfig3.png
│ ├── pgfig3.svg
│ ├── pgfig4.png
│ ├── pgfig4.svg
│ ├── pgfig5.png
│ ├── pgfig5.svg
│ ├── pgfig6.png
│ ├── pgfig6.svg
│ ├── pgfig7.png
│ ├── pgfig7.svg
│ ├── pgfig8.png
│ ├── pgfig9.png
│ ├── plot_dist.png
│ ├── plot_fit.png
│ ├── plot_gmm_desc.png
│ ├── plot_gmm_desc_log.png
│ ├── plot_gmm_scatter.png
│ ├── plot_lpa_desc.png
│ ├── plot_traj.png
│ ├── plot_trans.png
│ ├── sem_graph.html
│ ├── sem_graph_files
│ │ ├── accessible-code-block-0.0.1
│ │ │ └── empty-anchor.js
│ │ └── header-attrs-2.9
│ │ │ └── header-attrs.js
│ ├── spreadsheet.png
│ ├── spreadsheet2.png
│ ├── var_lat.png
│ ├── var_lat.svg
│ ├── var_obs.png
│ └── var_obs.svg
├── authors.html
├── badge.png
├── bootstrap-toc.css
├── bootstrap-toc.js
├── docsearch.css
├── docsearch.js
├── index.html
├── link.svg
├── news.html
├── news
│ └── index.html
├── pkgdown.css
├── pkgdown.js
├── pkgdown.yml
├── reference
│ ├── BCH.html
│ ├── BLRT.html
│ ├── Rplot001.png
│ ├── Rplot002.png
│ ├── SBChisquare.html
│ ├── SB_chisq_Pvalues.html
│ ├── add_paths.html
│ ├── alkema_microplastics.html
│ ├── all_fun.html
│ ├── append_class_draws.html
│ ├── as.lavaan.html
│ ├── as.layout.html
│ ├── as.mplus.html
│ ├── as_lavaan.html
│ ├── as_mplus.html
│ ├── as_ram.html
│ ├── chisq_sb.html
│ ├── class_prob.html
│ ├── conf_int.html
│ ├── cors.html
│ ├── create_scales.html
│ ├── curry_mac.html
│ ├── data_mix_ordinal.html
│ ├── descriptives.html
│ ├── dictionary.html
│ ├── edges.html
│ ├── edit_graph-1.png
│ ├── edit_graph.html
│ ├── empathy.html
│ ├── est_sig.html
│ ├── estimate_lavaan.html
│ ├── estimate_mplus.html
│ ├── estimate_mx.html
│ ├── filter_graph.html
│ ├── format_numeric.html
│ ├── get_data.html
│ ├── get_dict.html
│ ├── get_dictionary.html
│ ├── get_edges.html
│ ├── get_fit.html
│ ├── get_layout.html
│ ├── get_nodes.html
│ ├── graph.html
│ ├── graph_sem-1.png
│ ├── graph_sem.html
│ ├── ic_weights.html
│ ├── if_edit.html
│ ├── index.html
│ ├── layout.html
│ ├── lcs.html
│ ├── lr_lmr.html
│ ├── lr_test.html
│ ├── lsub.html
│ ├── maene_identity.html
│ ├── measurement.html
│ ├── mixture_starts.html
│ ├── mplus_expand_names.html
│ ├── mx_dummies.html
│ ├── mx_growth_mixture.html
│ ├── mx_lca.html
│ ├── mx_mixture.html
│ ├── mx_profiles.html
│ ├── mx_switch_labels.html
│ ├── nodes.html
│ ├── param_label.html
│ ├── paste2.html
│ ├── plas_depression.html
│ ├── plot_bivariate-1.png
│ ├── plot_bivariate.html
│ ├── plot_density.html
│ ├── plot_growth.html
│ ├── plot_prob-1.png
│ ├── plot_prob.html
│ ├── plot_profiles-1.png
│ ├── plot_profiles.html
│ ├── poms.html
│ ├── prepare_graph.html
│ ├── pseudo_class.html
│ ├── rbind_tables.html
│ ├── report.html
│ ├── report_columns.html
│ ├── run_lavaan.html
│ ├── run_mx.html
│ ├── skew_kurtosis.html
│ ├── syntax.html
│ ├── table_cor.html
│ ├── table_cors.html
│ ├── table_fit.html
│ ├── table_prob.html
│ ├── table_results.html
│ ├── tidy_sem.html
│ ├── wald_test.html
│ └── zegwaard_carecompass.html
└── sitemap.xml
├── man
├── BCH.Rd
├── BLRT.Rd
├── add_paths.Rd
├── alkema_microplastics.Rd
├── append_class_draws.Rd
├── as_lavaan.Rd
├── as_mplus.Rd
├── as_ram.Rd
├── chisq_sb.Rd
├── class_prob.Rd
├── conf_int.Rd
├── cors.Rd
├── create_scales.Rd
├── curry_mac.Rd
├── data_mix_ordinal.Rd
├── descriptives.Rd
├── dictionary.Rd
├── edges.Rd
├── edit_graph.Rd
├── empathy.Rd
├── est_sig.Rd
├── estimate_lavaan.Rd
├── estimate_mplus.Rd
├── estimate_mx.Rd
├── get_data.Rd
├── get_edges.Rd
├── get_fit.Rd
├── get_layout.Rd
├── get_nodes.Rd
├── graph_sem.Rd
├── ic_weights.Rd
├── if_edit.Rd
├── lr_lmr.Rd
├── lr_test.Rd
├── lsub.Rd
├── maene_identity.Rd
├── measurement.Rd
├── mixture_starts.Rd
├── mplus_expand_names.Rd
├── mx_dummies.Rd
├── mx_growth_mixture.Rd
├── mx_lca.Rd
├── mx_mixture.Rd
├── mx_profiles.Rd
├── mx_switch_labels.Rd
├── nodes.Rd
├── paste2.Rd
├── plas_depression.Rd
├── plot_bivariate.Rd
├── plot_density.Rd
├── plot_growth.Rd
├── plot_prob.Rd
├── plot_profiles.Rd
├── poms.Rd
├── prepare_graph.Rd
├── pseudo_class.Rd
├── report.Rd
├── run_lavaan.Rd
├── run_mx.Rd
├── skew_kurtosis.Rd
├── syntax.Rd
├── table_cors.Rd
├── table_fit.Rd
├── table_prob.Rd
├── table_results.Rd
├── tidy_sem.Rd
├── wald_test.Rd
└── zegwaard_carecompass.Rd
├── news.md
├── tests
├── testdata
│ └── galo.csv
├── testthat.R
└── testthat
│ ├── Rplots.pdf
│ ├── test-BLRT_lr_lmr.R
│ ├── test-a-namespaces.R
│ ├── test-dagitty_nodes_edges.R
│ ├── test-get_edges_columns.R
│ ├── test-get_nodes_label.R
│ ├── test-get_nodes_multigroup_label.R
│ ├── test-graph_sem_flip.R
│ ├── test-graph_sem_label.R
│ ├── test-lr_test_negative_df.R
│ ├── test-lrt_bch.R
│ ├── test-lrt_multigroup.R
│ ├── test-minimal_plot.R
│ ├── test-multigroup_mx.R
│ ├── test-mx_profiles_dataframe.R
│ ├── test-namespace_checks_dominique.R
│ ├── test-openmx_binary.R
│ ├── test-openmx_ordinal.R
│ ├── test-openmx_ordinal_and_cont.R
│ ├── test-openmx_ordinal_methods.R
│ ├── test-openmx_ordinal_thresh_constraints.R
│ ├── test-plot_color_argument.R
│ ├── test-plot_digits.R
│ ├── test-plot_group_labels.R
│ ├── test-plot_growth_model.R
│ ├── test-plot_if_edit.R
│ ├── test-plot_if_edit_overwrite_aes.R
│ ├── test-plot_igraph.R
│ ├── test-plot_lav_cfa.R
│ ├── test-plot_multigroup_multilevel.R
│ ├── test-plot_openmx.R
│ ├── test-plot_plot_prob.R
│ ├── test-plot_profiles_varyingcov.R
│ ├── test-plot_sem.R
│ ├── test-pseudo_class_technique.R
│ ├── test-results_digits.R
│ ├── test-results_has_pval.R
│ ├── test-results_labels.R
│ ├── test-syntax_categorical.R
│ ├── test-syntax_cfa_mplus_lavaan.R
│ ├── test-syntax_same_sem_addpaths.R
│ ├── test-tidyLPA_and_SEM_coexist.R
│ └── test-tidy_sem_lavaan_cfa_same.R
├── tidySEM.Rproj
└── vignettes
├── .gitignore
├── Generating_syntax.Rmd
├── Plotting_graphs.Rmd
├── SMART_LCA_checklist.Rmd
├── Tabulating_results.Rmd
├── appendixbresblrt.csv
├── gmm_aux_pt.RData
├── gmm_bivariate_bic.png
├── gmm_plotfit.png
├── gmm_results.csv
├── gmm_tabfit.csv
├── lca_confirmatory.Rmd
├── lca_desc.csv
├── lca_exploratory.Rmd
├── lca_fit.csv
├── lca_lcga.Rmd
├── lca_ordinal.Rmd
├── lca_plot_desc.png
├── lca_prob.png
├── lca_res.RData
├── lca_tab_prob.csv
├── lcga_fit.csv
├── lcga_plot_fit.png
├── lcga_tab_res.csv
├── lcga_wald_tests.csv
├── lpa_aux_model.RData
├── lpa_aux_sex.RData
├── lpa_bivariate.png
├── lpa_fit_compare.csv
├── lpa_profiles.png
├── lpa_tab_res.csv
├── lpatabfit.csv
├── lpatablmr.csv
├── mplusfit.R
├── pkgdown.txt
├── plot_dist.png
├── plot_fit.png
├── plot_gmm_desc.png
├── plot_gmm_desc_log.png
├── plot_gmm_scatter.png
├── plot_lpa_desc.png
├── plot_traj.png
├── plot_trans.png
├── res_gmm.RData
├── res_lpa.RData
├── res_step.RData
├── run_everything.txt
├── sem_graph.Rmd
└── spreadsheet.png
/.Rbuildignore:
--------------------------------------------------------------------------------
1 | ^.*\.Rproj$
2 | ^\.Rproj\.user$
3 | ^galo\.csv$
4 | ^README\.Rmd$
5 | ^doc$
6 | ^Meta$
7 | ^data_types\.md$
8 | dev/
9 | ^.*\.RData$
10 | ^docs$
11 | ^_pkgdown\.yml$
12 | R/data_types\.md
13 | ^.*\.psd$
14 | ^badge\.png$
15 | ^.*\.dat$
16 | ^.*\.txt$
17 | ^.*\.inp$
18 | ^.*\.out$
19 | ^.*\.log$
20 | ^.*\.dgm$
21 | ^.*.ai$
22 | ^CRAN-RELEASE$
23 | ^cran-comments\.md$
24 | ^news\.md$
25 | ^\.github$
26 | CODE_OF_CONDUCT.md
27 | ^CRAN-SUBMISSION$
28 | ^vignettes/*\.svg$
29 | ^codecov\.yml$
30 | ^vignettes/plot_traj.png$
31 | ^vignettes/lpa_bivariate.png$
32 | ^vignettes/plot_lpa_desc.png$
33 | ^vignettes/res_lpa.RData$
34 | ^vignettes/lpatabfit.csv$
35 | ^vignettes/appendixbresblrt.csv$
36 | ^vignettes/lpa_fit_compare.csv$
37 | ^vignettes/lpa_tab_res.csv$
38 | ^vignettes/lpa_bivariate.png$
39 | ^vignettes/lpa_profiles.png$
40 | ^vignettes/lpa_aux_sex.RData$
41 | ^vignettes/lpa_aux_model.RData$
42 | ^vignettes/plot_gmm_desc.png$
43 | ^vignettes/plot_gmm_desc_log.png$
44 | ^vignettes/plot_gmm_scatter.png$
45 | ^vignettes/res_gmm.RData$
46 | ^vignettes/gmm_tabfit.csv$
47 | ^vignettes/gmm_plotfit.png$
48 | ^vignettes/gmm_results.csv$
49 | ^vignettes/gmm_bivariate_bic.png$
50 | ^vignettes/gmm_aux_pt.RData$
51 | ^vignettes/plot_dist.png$
52 | ^vignettes/plot_trans.png$
53 | ^vignettes/res_step.RData$
54 | ^vignettes/lcga_fit.csv$
55 | ^vignettes/lcga_plot_fit.png$
56 | ^vignettes/lcga_tab_res.csv$
57 | ^vignettes/lcga_wald_tests.csv$
58 | ^vignettes/plot_traj.png$
59 | ^vignettes/lca_desc.csv$
60 | ^vignettes/lca_plot_desc.png$
61 | ^vignettes/lca_res.RData$
62 | ^vignettes/lca_fit.csv$
63 | ^vignettes/lca_tab_prob.csv$
64 | ^vignettes/lca_prob.png$
65 | ^vignettes/lca_aux_dep.RData$
66 | ^vignettes/lca_aux_model.RData$
67 | ^pkgdown$
68 |
--------------------------------------------------------------------------------
/.github/.gitignore:
--------------------------------------------------------------------------------
1 | *.html
2 |
--------------------------------------------------------------------------------
/.github/workflows/R-CMD-check.yaml:
--------------------------------------------------------------------------------
1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
3 | on:
4 | push:
5 | branches: [main, master]
6 | pull_request:
7 | branches: [main, master]
8 |
9 | name: R-CMD-check
10 |
11 | jobs:
12 | R-CMD-check:
13 | runs-on: ${{ matrix.config.os }}
14 |
15 | name: ${{ matrix.config.os }} (${{ matrix.config.r }})
16 |
17 | strategy:
18 | fail-fast: false
19 | matrix:
20 | config:
21 | - {os: macos-latest, r: 'release'}
22 | - {os: windows-latest, r: 'release'}
23 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
24 | - {os: ubuntu-latest, r: 'release'}
25 | - {os: ubuntu-latest, r: 'oldrel-1'}
26 |
27 | env:
28 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
29 | R_KEEP_PKG_SOURCE: yes
30 |
31 | steps:
32 | - uses: actions/checkout@v3
33 |
34 | - uses: r-lib/actions/setup-pandoc@v2
35 |
36 | - uses: r-lib/actions/setup-r@v2
37 | with:
38 | r-version: ${{ matrix.config.r }}
39 | http-user-agent: ${{ matrix.config.http-user-agent }}
40 | use-public-rspm: true
41 |
42 | - uses: r-lib/actions/setup-r-dependencies@v2
43 | with:
44 | extra-packages: any::rcmdcheck
45 | needs: check
46 |
47 | - uses: r-lib/actions/check-r-package@v2
48 | with:
49 | upload-snapshots: true
50 |
--------------------------------------------------------------------------------
/.github/workflows/check-no-suggests.yaml:
--------------------------------------------------------------------------------
1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
3 | #
4 | # NOTE: This workflow only directly installs "hard" dependencies, i.e. Depends,
5 | # Imports, and LinkingTo dependencies. Notably, Suggests dependencies are never
6 | # installed, with the exception of testthat, knitr, and rmarkdown. The cache is
7 | # never used to avoid accidentally restoring a cache containing a suggested
8 | # dependency.
9 | on:
10 | push:
11 | branches: [main, master]
12 | pull_request:
13 |
14 | name: check-no-suggests.yaml
15 |
16 | permissions: read-all
17 |
18 | jobs:
19 | check-no-suggests:
20 | runs-on: ${{ matrix.config.os }}
21 |
22 | name: ${{ matrix.config.os }} (${{ matrix.config.r }})
23 |
24 | strategy:
25 | fail-fast: false
26 | matrix:
27 | config:
28 | - {os: ubuntu-latest, r: 'release'}
29 |
30 | env:
31 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
32 | R_KEEP_PKG_SOURCE: yes
33 |
34 | steps:
35 | - uses: actions/checkout@v4
36 |
37 | - uses: r-lib/actions/setup-pandoc@v2
38 |
39 | - uses: r-lib/actions/setup-r@v2
40 | with:
41 | r-version: ${{ matrix.config.r }}
42 | http-user-agent: ${{ matrix.config.http-user-agent }}
43 | use-public-rspm: true
44 |
45 | - uses: r-lib/actions/setup-r-dependencies@v2
46 | with:
47 | dependencies: '"hard"'
48 | cache: false
49 | extra-packages: |
50 | any::rcmdcheck
51 | any::testthat
52 | any::knitr
53 | any::rmarkdown
54 | needs: check
55 |
56 | - uses: r-lib/actions/check-r-package@v2
57 | with:
58 | upload-snapshots: true
59 | build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
60 |
--------------------------------------------------------------------------------
/.github/workflows/pkgdown.yaml:
--------------------------------------------------------------------------------
1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
3 | on:
4 | push:
5 | branches: [main, master]
6 | pull_request:
7 | release:
8 | types: [published]
9 | workflow_dispatch:
10 |
11 | name: pkgdown.yaml
12 |
13 | permissions: read-all
14 |
15 | jobs:
16 | pkgdown:
17 | runs-on: ubuntu-latest
18 | # Only restrict concurrency for non-PR jobs
19 | concurrency:
20 | group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
21 | env:
22 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
23 | permissions:
24 | contents: write
25 | steps:
26 | - uses: actions/checkout@v4
27 |
28 | - uses: r-lib/actions/setup-pandoc@v2
29 |
30 | - uses: r-lib/actions/setup-r@v2
31 | with:
32 | use-public-rspm: true
33 |
34 | - uses: r-lib/actions/setup-r-dependencies@v2
35 | with:
36 | extra-packages: any::pkgdown, local::.
37 | needs: website
38 |
39 | - name: Build site
40 | run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
41 | shell: Rscript {0}
42 |
43 | - name: Deploy to GitHub pages 🚀
44 | if: github.event_name != 'pull_request'
45 | uses: JamesIves/github-pages-deploy-action@v4.5.0
46 | with:
47 | clean: false
48 | branch: gh-pages
49 | folder: docs
50 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .Rproj.user
2 | .Rhistory
3 | .RData
4 | .Ruserdata
5 | *ellipse.R
6 | *ellipse.R
7 | inst/doc
8 | doc
9 | Meta
10 | *.RData
11 | tests/test_local.R
12 | *.psd
13 | CRAN-RELEASE
14 | *.out
15 | *.inp
16 | *.dat
17 | *.log
18 | *.dgm
19 | /doc/
20 | /Meta/
21 | *.dgm]
22 | *.txt
23 | tests/test_local.txt
24 | !dev/lca_res.rdata
25 | !dev/res_gmm_nopca.RData
26 | !vignettes/*.RData
27 | docs
28 |
--------------------------------------------------------------------------------
/DESCRIPTION:
--------------------------------------------------------------------------------
1 | Package: tidySEM
2 | Type: Package
3 | Title: Tidy Structural Equation Modeling
4 | Version: 0.2.9.2
5 | Authors@R:
6 | c(person(given = c("Caspar", "J."),
7 | family = "van Lissa",
8 | role = c("aut", "cre"),
9 | email = "c.j.vanlissa@tilburguniversity.edu",
10 | comment = c(ORCID = "0000-0002-0808-5024")),
11 | person(given = c("Mauricio"),
12 | family = "Garnier-Villarreal",
13 | role = c("ctb"),
14 | email = "mgv@pm.me",
15 | comment = c(ORCID = "0000-0002-2951-6647")),
16 | person(given = c("Frank", "C"),
17 | family = "Gootjes",
18 | role = c("ctb"),
19 | email = "f.c.gootjes@uu.nl",
20 | comment = c(ORCID = "0000-0002-0639-1001")) )
21 | Description: A tidy workflow for generating, estimating, reporting,
22 | and plotting structural equation models using 'lavaan', 'OpenMx', or
23 | 'Mplus'. Throughout this workflow, elements of syntax, results, and graphs
24 | are represented as 'tidy' data, making them easy to customize.
25 | Includes functionality to estimate latent class analyses, and to plot
26 | 'dagitty' and 'igraph' objects.
27 | License: GPL (>= 3)
28 | URL: https://cjvanlissa.github.io/tidySEM/
29 | BugReports: https://github.com/cjvanlissa/tidySEM/issues
30 | Depends:
31 | R (>= 4.0.0),
32 | stats,
33 | utils
34 | Imports:
35 | ggplot2 (>= 3.4.2),
36 | lavaan,
37 | blavaan,
38 | MplusAutomation,
39 | igraph (>= 2.0.0),
40 | psych,
41 | methods,
42 | gtable,
43 | dbscan,
44 | RANN,
45 | Matrix,
46 | bain,
47 | car,
48 | future.apply,
49 | progressr,
50 | nonnest2 (>= 0.5.6)
51 | Suggests:
52 | testthat,
53 | knitr,
54 | dplyr,
55 | stringr,
56 | covr,
57 | tidyLPA,
58 | poLCA,
59 | umx,
60 | mclust,
61 | MASS,
62 | scales,
63 | yaml,
64 | formatR,
65 | dagitty,
66 | mice,
67 | ggraph,
68 | OpenMx,
69 | rmarkdown
70 | VignetteBuilder:
71 | knitr
72 | Encoding: UTF-8
73 | RoxygenNote: 7.3.2
74 | LazyData: true
75 | Roxygen: list(markdown = TRUE)
76 |
--------------------------------------------------------------------------------
/R/alkema_microplastics.R:
--------------------------------------------------------------------------------
1 | #' Ocean Microplastics Data
2 | #'
3 | #' These data were collected by Alkema during a cruise from 04/2018 to
4 | #' 06/2018 traversing the Atlantic Ocean from South Africa to Norway.
5 | #' A 500 micrometer meshed Manta Trawl was towed outside the
6 | #' wake of the ship for 1 h
7 | #' each day. Length, width, height and polymer type of 6.942 particles
8 | #' were measured using infrared spectroscopy and image analysis.
9 | #'
10 | #' \tabular{lll}{
11 | #' \strong{current} \tab \code{factor} \tab Which ocean current the sample was taken from\cr
12 | #' \strong{sample} \tab \code{integer} \tab Sample ID\cr
13 | #' \strong{length} \tab \code{numeric} \tab Particle length in mm\cr
14 | #' \strong{width} \tab \code{numeric} \tab Particle width in mm\cr
15 | #' \strong{height_est} \tab \code{numeric} \tab Estimated particle height in mm\cr
16 | #' \strong{height_obs} \tab \code{numeric} \tab Observed particle height in mm. Height was only measured for large particles\cr
17 | #' \strong{category} \tab \code{factor} \tab Particle category based on visual inspection\cr
18 | #' \strong{poly_type} \tab \code{factor} \tab Polymer type as determined by near infrared spectroscopy (NIR)\cr
19 | #' \strong{two_dim} \tab \code{logical} \tab Whether or not the particle can be treated as two-dimensional\cr
20 | #' \strong{film} \tab \code{logical} \tab Whether or not the particle appears to be a film\cr
21 | #' \strong{line} \tab \code{logical} \tab Whether or not the particle appears to be a line
22 | #' }
23 | #' @docType data
24 | #' @keywords datasets
25 | #' @name alkema_microplastics
26 | #' @usage data(alkema_microplastics)
27 | #' @references Alkema, L. M., Van Lissa, C. J., Kooi, M., & Koelmans, A. A. (2022).
28 | #' Maximizing Realism: Mapping Plastic Particles at the Ocean Surface Using
29 | #' Mixtures of Normal Distributions. Environmental Science & Technology,
30 | #' 56(22), 15552-15562.
31 | #' \doi{10.1021/acs.est.2c03559}
32 | #' @format A data frame with 6942 rows and 11 variables.
33 | NULL
34 |
--------------------------------------------------------------------------------
/R/data-data_mix_ordinal.R:
--------------------------------------------------------------------------------
1 | #' Simulated data for mixture model with ordinal indicators
2 | #'
3 | #' This simulated dataset, based on the 'Mplus' User's Guide example 7.6,
4 | #' contains four columns of integer data that should be treated as ordinal.
5 | #'
6 | #' \tabular{lll}{
7 | #' \strong{u1} \tab \code{integer} \tab Indicator 1, should be treated as
8 | #' ordinal.\cr
9 | #' \strong{u2} \tab \code{integer} \tab Indicator 2, should be treated as
10 | #' ordinal.\cr
11 | #' \strong{u3} \tab \code{integer} \tab Indicator 3, should be treated as
12 | #' ordinal.\cr
13 | #' \strong{u4} \tab \code{integer} \tab Indicator 4, should be treated as
14 | #' ordinal.
15 | #' }
16 | #' @docType data
17 | #' @keywords datasets
18 | #' @name data_mix_ordinal
19 | #' @usage data(data_mix_ordinal)
20 | #' @references Muthén, L.K. and Muthén, B.O. (1998-2017). Mplus User's Guide.
21 | #' Eighth Edition. Los Angeles, CA: Muthén & Muthén
22 | #' @format A data frame with 5000 rows and 4 variables.
23 | NULL
24 |
--------------------------------------------------------------------------------
/R/data-mac.R:
--------------------------------------------------------------------------------
1 | #' Simulated MAC data
2 | #'
3 | #' This simulated dataset, based on Curry et al., 2019, contains data on moral
4 | #' relevance and judgment across the seven domains of the Morality As
5 | #' Cooperation scale.
6 | #'
7 | #' \tabular{lll}{
8 | #' \strong{sex} \tab \code{factor} \tab Self-identified sex of participants, Male, Female, or Transgendered.\cr
9 | #' \strong{age_years} \tab \code{numeric} \tab Participants' age in years.\cr
10 | #' \strong{KinshipR} \tab \code{numeric} \tab Mean score of moral relevance, kinship subscale.\cr
11 | #' \strong{MutualismR} \tab \code{numeric} \tab Mean score of moral relevance, mutualism subscale.\cr
12 | #' \strong{ExchangeR} \tab \code{numeric} \tab Mean score of moral relevance, exchange subscale.\cr
13 | #' \strong{HawkR} \tab \code{numeric} \tab Mean score of moral relevance, hawk subscale.\cr
14 | #' \strong{DoveR} \tab \code{numeric} \tab Mean score of moral relevance, dove subscale.\cr
15 | #' \strong{DivisionR} \tab \code{numeric} \tab Mean score of moral relevance, division subscale.\cr
16 | #' \strong{PossessionR} \tab \code{numeric} \tab Mean score of moral relevance, possession subscale.\cr
17 | #' \strong{KinshipJ} \tab \code{numeric} \tab Mean score of moral judgment, kinship subscale.\cr
18 | #' \strong{MutualismJ} \tab \code{numeric} \tab Mean score of moral judgment, mutualism subscale.\cr
19 | #' \strong{ExchangeJ} \tab \code{numeric} \tab Mean score of moral judgment, exchange subscale.\cr
20 | #' \strong{HawkJ} \tab \code{numeric} \tab Mean score of moral judgment, hawk subscale.\cr
21 | #' \strong{DoveJ} \tab \code{numeric} \tab Mean score of moral judgment, dove subscale.\cr
22 | #' \strong{DivisionJ} \tab \code{numeric} \tab Mean score of moral judgment, division subscale.\cr
23 | #' \strong{PossessionJ} \tab \code{numeric} \tab Mean score of moral judgment, possession subscale.
24 | #' }
25 | #' @docType data
26 | #' @keywords datasets
27 | #' @name curry_mac
28 | #' @usage data(curry_mac)
29 | #' @references Curry, O. S., Jones Chesters, M., & Van Lissa, C. J. (2019). Mapping morality with a compass: Testing the theory of ‘morality-as-cooperation’ with a new questionnaire. Journal of Research in Personality, 78, 106–124.
30 | #' \doi{10.1016/j.jrp.2018.10.008}
31 | #' @format A data.frame with 1392 rows and 42 variables.
32 | NULL
33 |
--------------------------------------------------------------------------------
/R/data_types.md:
--------------------------------------------------------------------------------
1 | # tidy_sem
2 |
3 | ## $dictionary
4 |
5 | A data_dict: data.frame with columns
6 | * name variable name as listed in data
7 | * scale which scale the name belongs to
8 | * item [TODO] possibly redundant
9 | * label Which label to use for this variable
10 | * type observed, indicator (observed that is indicator for latent) or latent
11 | * measurement [TODO] Level of measurement: Categorical, ordinal, binary
12 | * Wave [TODO] Measurement wave for wide format
13 |
14 |
15 | ## $data
16 |
17 | The observed data
18 |
19 | ## $syntax
20 |
21 | A character vector with syntax elements
22 |
23 |
24 | # Syntax (based on lavaanify)
25 |
26 | c("lhs", "op", "rhs", "mod.idx", "block", "fixed", "start", "lower", "upper", "label", "prior", "efa")
27 |
--------------------------------------------------------------------------------
/R/empathy.R:
--------------------------------------------------------------------------------
1 | #' Simulated empathy data
2 | #'
3 | #' This simulated dataset, based on Van Lissa et al., 2014, contains six annual
4 | #' assessments of adolescents' mean scores on the empathic concern and
5 | #' perspective taking subscales of the Interpersonal Reactivity Index
6 | #' (Davis, 1983). The first measurement wave occurred when adolescents were, on
7 | #' average, 13 years old, and the last one when they were 18 years old.
8 | #'
9 | #' \tabular{lll}{
10 | #' \strong{ec1} \tab \code{numeric} \tab Mean score of empathic concern in
11 | #' wave 1\cr
12 | #' \strong{ec2} \tab \code{numeric} \tab Mean score of empathic concern in
13 | #' wave 2\cr
14 | #' \strong{ec3} \tab \code{numeric} \tab Mean score of empathic concern in
15 | #' wave 3\cr
16 | #' \strong{ec4} \tab \code{numeric} \tab Mean score of empathic concern in
17 | #' wave 4\cr
18 | #' \strong{ec5} \tab \code{numeric} \tab Mean score of empathic concern in
19 | #' wave 5\cr
20 | #' \strong{ec6} \tab \code{numeric} \tab Mean score of empathic concern in
21 | #' wave 6\cr
22 | #' \strong{pt1} \tab \code{numeric} \tab Mean score of perspective taking in
23 | #' wave 1\cr
24 | #' \strong{pt2} \tab \code{numeric} \tab Mean score of perspective taking in
25 | #' wave 2\cr
26 | #' \strong{pt3} \tab \code{numeric} \tab Mean score of perspective taking in
27 | #' wave 3\cr
28 | #' \strong{pt4} \tab \code{numeric} \tab Mean score of perspective taking in
29 | #' wave 4\cr
30 | #' \strong{pt5} \tab \code{numeric} \tab Mean score of perspective taking in
31 | #' wave 5\cr
32 | #' \strong{pt6} \tab \code{numeric} \tab Mean score of perspective taking in
33 | #' wave 6\cr
34 | #' \strong{sex} \tab \code{factor} \tab Adolescent sex; M = male, F = female.
35 | #' }
36 | #' @docType data
37 | #' @keywords datasets
38 | #' @name empathy
39 | #' @usage data(empathy)
40 | #' @references Van Lissa, C. J., Hawk, S. T., Branje, S. J., Koot, H. M.,
41 | #' Van Lier, P. A., & Meeus, W. H. (2014). Divergence Between Adolescent and
42 | #' Parental Perceptions of Conflict in Relationship to Adolescent Empathy
43 | #' Development. Journal of Youth and Adolescence, (Journal Article), 1–14.
44 | #' \doi{10.1007/s10964-014-0152-5}
45 | #' @format A data frame with 467 rows and 13 variables.
46 | NULL
47 |
--------------------------------------------------------------------------------
/R/ic_weights.R:
--------------------------------------------------------------------------------
1 | #' Compare Information Criteria
2 | #'
3 | #' IC weights quantify the evidence in favor of different models in a set.
4 | #' This function normalizes the IC values to obtain IC weights, which sum to 1.
5 | #' The model with the highest weight is most supported by the data.
6 | #' The ratio of different weights gives the relative support in favor of one
7 | #' model over another.
8 | #' @param x An object for which a method exists.
9 | #' @param ... Additional arguments.
10 | #' @return A `list` of class `ic_weights` with elements `$weights`, which
11 | #' contains the model weights, and `$comparison`, which contains the relative
12 | #' support in favor of each model over the others.
13 | #' @export
14 | #' @examples
15 | #' ics <- c(100, 200, 102, 300)
16 | #' ic_weights(ics)
17 | #' @references Wagenmakers, E. J., & Farrell, S. (2004). AIC model selection
18 | #' using Akaike weights. Psychonomic bulletin & review, 11(1), 192-196.
19 | #' \doi{10.3758/BF03206482}
20 | ic_weights <- function(x, ...){
21 | UseMethod("ic_weights", x)
22 | }
23 |
24 | #' @method ic_weights tidy_fit
25 | #' @export
26 | ic_weights.tidy_fit <- function(x, ic = "BIC", ...){
27 | if(!ic %in% names(x)){
28 | stop("The 'ic = ", ic, "' was not found in the tidy_fit table.")
29 | }
30 | x <- x[!is.na(x[[ic]]), , drop = FALSE]
31 | if(nrow(x) < 2){
32 | stop("Fewer than two models with valid ", ic, ". Could not calculate weights.")
33 | }
34 | out <- x[[ic]]
35 | if("Name" %in% names(x)) names(out) <- x[["Name"]]
36 | ic_weights(out)
37 | }
38 |
39 | #' @method ic_weights default
40 | #' @export
41 | ic_weights.default <- function(x, ...){
42 | if(!all(x > 0)) message("Negative IC values found; this may indicate a problem.")
43 | if(is.null(names(x))) names(x) <- paste0("Model ", 1:length(x))
44 | ic_min <- min(x)
45 | ic_diff <- x - ic_min
46 | rel_likelihood <- exp(-0.5*ic_diff)
47 | weights <- rel_likelihood / sum(rel_likelihood)
48 | comparison <- outer(weights, 1/weights)
49 | out <- list(weights = weights, comparison = comparison)
50 | class(out) <- c("ic_weights", class(out))
51 | return(out)
52 | }
53 |
54 |
--------------------------------------------------------------------------------
/R/igraph.R:
--------------------------------------------------------------------------------
1 | #' @method get_nodes igraph
2 | #' @importFrom igraph V as_data_frame
3 | #' @export
4 | get_nodes.igraph <- function(x, label = name, ...){
5 | label <- substitute(label)
6 | nod <- igraph::as_data_frame(x, what = "vertices")
7 | if(ncol(nod) == 0){
8 | nod <- data.frame(name = as.character(unclass(igraph::V(x))))
9 | }
10 | # att_nams <- vertex_attr_names(x)
11 | if(is.null(nod[["shape"]])) nod[["shape"]] <- "none"
12 | if(is.null(nod[["label"]])) nod[["label"]] <- eval(label, envir = nod)
13 |
14 | class(nod) <- c("tidy_nodes", class(nod))
15 | return(nod)
16 | }
17 |
18 | #' @method get_edges igraph
19 | #' @importFrom igraph as_data_frame
20 | #' @export
21 | get_edges.igraph <- function(x, label = NULL, ...){
22 | label <- substitute(label)
23 | edg <- igraph::as_data_frame(x, "edges")
24 | edg$arrow <- tryCatch({c("none", "last")[unclass(x)[[2]]+1L]}, error = function(e){
25 | message("Could not identify edge direction from object of class `igraph`.")
26 | "none"})
27 |
28 | if(is.null(edg$label)){
29 | edg[["label"]] <- eval(label, envir = edg)
30 | }
31 | class(edg) <- c("tidy_edges", class(edg))
32 | return(edg)
33 | }
34 |
35 | #' @method get_layout igraph
36 | #' @export
37 | get_layout.igraph <- function(x, ..., layout_algorithm = "layout_nicely"){
38 | Args <- list("graph" = x, "dim" = 2)
39 | layout_algorithm <- paste0("igraph::", layout_algorithm)
40 | lo <- data.frame(do.call(eval(parse(text=layout_algorithm)), Args))
41 | names(lo) <- c("x", "y")
42 | nod <- get_nodes(x)
43 | lo$name <- nod$name
44 | class(lo) <- c("tidy_layout", class(lo))
45 | return(lo)
46 | }
47 |
48 | #' @method prepare_graph igraph
49 | #' @export
50 | prepare_graph.igraph <- function(model, ...){
51 | cl <- match.call()
52 | if(!"edges" %in% names(cl)) cl[["edges"]] <- get_edges(model)
53 | if(!"nodes" %in% names(cl)) cl[["nodes"]] <- get_nodes(model)
54 | if(!"layout" %in% names(cl)) cl[["layout"]] <- get_layout(model)
55 | cl[["model"]] <- NULL
56 | cl[[1]] <- str2lang("tidySEM::prepare_graph")
57 | eval.parent(cl)
58 | }
59 |
60 |
--------------------------------------------------------------------------------
/R/mixture_gradient.R:
--------------------------------------------------------------------------------
1 | # df <- iris[, 1:2]
2 | # names(df) <- c("x", "y")
3 | # set.seed(1)
4 | # mix <- mx_profiles(df, classes = 2)
5 |
6 | mx_mixture_gradients <- function(x, ...){
7 | paramLabels <- names(OpenMx::omxGetParameters(x))
8 | numParam <- length(paramLabels)
9 | custom.compute <- OpenMx::mxComputeSequence(list(OpenMx::mxComputeNumericDeriv(checkGradient = FALSE,
10 | hessian = FALSE), OpenMx::mxComputeReportDeriv()))
11 | do.call(rbind, lapply(1:nrow(x@data$observed), function(i) {
12 | tryCatch({
13 | OpenMx::mxRun(OpenMx::mxModel(
14 | x, custom.compute, OpenMx::mxData(x@data$observed[i, , drop = FALSE], "raw")
15 | ), silent = TRUE)$output$gradient
16 | },
17 | error = function(e) {
18 | rep(NA, length(numParam))
19 | })
20 | }))
21 | }
22 | # #x <- mix
23 | # model <- x
24 | # cprobs <- class_prob(x)
25 | # Hmat <- cprobs$mostlikely.class
26 | # Hmatinv <- solve(Hmat)
27 | # mostlikely <- cprobs$individual[,"predicted"]
28 | # bchweights <- data.frame(Hmatinv[mostlikely, ])
29 | # names(bchweights) <- paste0("w", cprobs$sum.posterior$class)
30 | # df <- cbind(x@data$observed, bchweights)
31 | # grp_names <- cprobs$sum.posterior$class
32 | # grps <- lapply(1:ncol(bchweights), function(i){
33 | # mxModel(model[[grp_names[i]]],
34 | # name = grp_names[i],
35 | # data = mxData(observed = df, type = "raw", weight = names(bchweights)[i]),
36 | # fitfunction = mxFitFunctionML())
37 | # })
38 | # grps <- do.call(mxModel, c(list(model = "mg", mxFitFunctionMultigroup(grp_names), grps)))
39 | #
40 | # out <- try(run_mx(grps), silent = TRUE)
41 | # attr(out, "tidySEM") <- "BCH"
42 | # if(!inherits(out, "try-error")){
43 | # return(out)
44 | # }
45 | # NULL
46 | # }
47 | # }
48 | #
49 | #
50 | #
51 | #
52 |
--------------------------------------------------------------------------------
/R/mixture_predict.R:
--------------------------------------------------------------------------------
1 | #' @method predict MxModel
2 | #' @export
3 | predict.MxModel <- function(object,
4 | newdata,
5 | ...){
6 | cl <- match.call()
7 | cl[[1L]] <- str2lang("OpenMx:::predict.MxModel")
8 | if(!is.null(attr(object, "tidySEM"))){
9 | if("mixture" %in% attr(object, "tidySEM")){
10 | cl[[1L]] <- str2lang("tidySEM:::predict_mxmodel_mixture")
11 | }
12 | }
13 | eval.parent(cl)
14 | }
15 |
16 | predict_mxmodel_mixture <- function(object, newdata = NULL, ...){
17 | if(is.null(newdata)){
18 | return(class_prob(object, "individual")[[1]][,"predicted"])
19 | } else {
20 | mod_fix <- object
21 | for(c in names(object@submodels)){
22 | for(m in names(object[[c]]@matrices)){
23 | mod_fix[[c]][[m]]$free[,] <- FALSE
24 | }
25 | }
26 | mod_fix$data$observed <- rbind(newdata, mod_fix$data$observed)
27 | mod_fix@matrices$weights$free[,] <- FALSE
28 | mod_fix <- OpenMx::mxRun(mod_fix)
29 | return(class_prob(mod_fix, "individual")[[1]][1:nrow(newdata), , drop = FALSE])
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/R/mplus_functions.R:
--------------------------------------------------------------------------------
1 | #' @importFrom MplusAutomation mplusObject
2 | drop_mplusObject <- function(x){
3 | UseMethod("drop_mplusObject", x)
4 | }
5 |
6 | #' @export
7 | drop_mplusObject.mplusObject <- function(x){
8 | x$results
9 | }
10 |
11 |
12 | #' @importFrom stats dnorm
13 | #' @importFrom ggplot2 stat_function
14 | plot_thresholds <- function(x){
15 | thresholds <- x$parameters$unstandardized[x$parameters$unstandardized$paramHeader == "Thresholds", ]
16 | thresholds$Variable <- gsub("\\$.*$", "", thresholds$param)
17 | thresholds$Scale <- gsub("\\d\\$.*$", "", thresholds$param)
18 | thresholds$Item <- gsub("^.+?(\\d)\\$.*$", "\\1", thresholds$param)
19 | thresholds$Threshold <- gsub("^.+?\\$", "", thresholds$param)
20 |
21 | #thresholds <- thresholds[1:3, ]
22 | ggplot(data = data.frame(x = c(-3, 3)), aes(x = .data[["x"]])) +
23 | stat_function(fun = dnorm, n = 101, args = list(mean = 0, sd = 1)) +
24 | geom_vline(data = thresholds, mapping = aes(xintercept = .data[["est"]])) +
25 | facet_grid(Scale ~ Item) +
26 | theme_bw() +
27 | labs(x = NULL, y = NULL)
28 | }
29 |
30 | # cut_data <- function(x){
31 | # x <- mplus_data
32 | # sum(is.na(x))
33 | # x[x<4] <- 1
34 | #
35 | # }
36 |
37 | calc_omega <- function(loadings, residuals){
38 | sum(loadings)^2/(sum(loadings)^2+sum(residuals))
39 | }
40 |
41 | get_omegas <- function(x){
42 | x$results$parameters$unstandardized
43 | get_loadings(x)
44 | }
45 |
46 | get_loadings <- function(x, std = "stdyx.standardized"){
47 | UseMethod("get_loadings", x)
48 | }
49 |
50 | #' @export
51 | get_loadings.mplusObject <- function(x, std = "stdyx.standardized"){
52 | get_loadings(drop_mplusObject(x))
53 | }
54 | #' @export
55 | get_loadings.mplus.model <- function(x, std = "stdyx.standardized"){
56 | x$parameters[[std]][grepl("\\.BY", x$parameters[[std]]$paramHeader), ]
57 | }
58 |
--------------------------------------------------------------------------------
/R/mx_fixed_pars.R:
--------------------------------------------------------------------------------
1 | .mxfixedpars <- function(x){
2 | submods <- names(x@submodels)
3 | out <- NULL
4 | if(!is.null(submods)){
5 | out <- lapply(submods, function(themod){
6 | tmp <- .mxfixedpars(x[[themod]])
7 | if(is.null(tmp)) return(NULL)
8 | tmp$matrix <- paste0(themod, ".", tmp$matrix)
9 | tmp
10 | })
11 | }
12 | mats <- x@matrices
13 | if(length(mats) > 0){
14 | out <- c(out,
15 | lapply(names(mats)[!names(mats) %in% c("F")], function(thism){
16 | tmp <- as.data.frame.table(x[[thism]][["values"]])
17 | if(is.null(rownames(x[[thism]][["values"]]))){
18 | levels(tmp$Var1) <- 1:length(levels(tmp$Var1))
19 | }
20 | names(tmp)[3] <- "Estimate"
21 | tmp$name <- paste0(x$name, ".", thism, "[", as.integer(tmp$Var1), ",", as.integer(tmp$Var2), "]")
22 | tmp$matrix <- thism
23 | tmp$row <- as.character(tmp$Var1)
24 | tmp$col <- as.character(tmp$Var2)
25 | isfree <- as.vector(x[[thism]][["free"]])
26 | tmp[!isfree & !tmp$Estimate == 0, c("name", "matrix", "row", "col", "Estimate"), drop = FALSE]
27 | }))
28 | }
29 | out <- bind_list(out)
30 | if(is.null(out)) return(NULL)
31 | if(nrow(out) == 0) return(NULL)
32 | return(out)
33 | }
34 |
--------------------------------------------------------------------------------
/R/plas_depression.R:
--------------------------------------------------------------------------------
1 | #' Simulated depression data
2 | #'
3 | #' This simulated dataset, based on work
4 | #' in progress by Plas and colleagues,
5 | #' contains six repeated measurements
6 | #' of the Depression subscale of the
7 | #' Symptom Checklist-90 (SCL-90).
8 | #'
9 | #' These data are inspired by the
10 | #' *Prospection in Stress-related Military Research (PRISMO)* study,
11 | #' which examined of psychological problems
12 | #' after deployment in more than 1,000 Dutch
13 | #' military personnel who were deployed to Afghanistan, from 2005-2019.
14 | #'
15 | #' \tabular{lll}{
16 | #' \strong{scl.1} \tab \code{integer} \tab Sum score of SCL90 depression pre-deployment\cr
17 | #' \strong{scl.2} \tab \code{integer} \tab Sum score of SCL90 depression 1 month post-deployment\cr
18 | #' \strong{scl.3} \tab \code{integer} \tab Sum score of SCL90 depression 6 months post-deployment\cr
19 | #' \strong{scl.4} \tab \code{integer} \tab Sum score of SCL90 depression 1 year post-deployment\cr
20 | #' \strong{scl.5} \tab \code{integer} \tab Sum score of SCL90 depression 2 years post-deployment\cr
21 | #' \strong{scl.6} \tab \code{integer} \tab Sum score of SCL90 depression 10 years post-deployment
22 | #' }
23 | #' @docType data
24 | #' @keywords datasets
25 | #' @name plas_depression
26 | #' @usage data(plas_depression)
27 | #' @references van der Wal, S. J., Gorter, R., Reijnen, A., Geuze, E., & Vermetten, E. (2019). Cohort profile: The Prospective Research In Stress-Related Military Operations (PRISMO) study in the Dutch Armed Forces. BMJ Open, 9(3), e026670.
28 | #' \doi{10.1136/bmjopen-2018-026670}
29 | #' @format A data frame with 978 rows and 6 variables.
30 | NULL
31 |
--------------------------------------------------------------------------------
/R/plot_ellipses.R:
--------------------------------------------------------------------------------
1 | .error_arrow <- function(p, x, y, diameter, orientation, npoints = 20){
2 | radius <- diameter / 2
3 | switch(orientation,
4 | "up" = {
5 | xmean = x
6 | ymean = y + radius
7 | offset = 1.5
8 | },
9 | "down" = {
10 | xmean = x
11 | ymean = y - radius
12 | offset = .5
13 | },
14 | "left" = {
15 | xmean = x+ radius
16 | ymean = y
17 | offset = 0
18 | },
19 | "right" = {
20 | xmean = x- radius
21 | ymean = y
22 | offset = 1
23 | })
24 |
25 | point_seq <- seq((offset*pi),(2+offset)*pi,length.out = npoints) %% (2*pi)
26 |
27 | df_ellipse <- data.frame(matrix(
28 | c(xmean + radius * cos(point_seq), ymean + radius * sin(point_seq)),
29 | nrow = npoints, ncol = 2, dimnames = list(NULL, c("x", "y"))
30 | )
31 | )
32 | p + geom_path(data = df_ellipse, aes(x = .data[["x"]], y = .data[["y"]]), linetype = 1, arrow = ggplot2::arrow(angle = 25, length = unit(.1, "inches"), ends = "both", type = "closed"))
33 | }
34 |
35 | #' @importFrom ggplot2 geom_path geom_polygon
36 | .oval_node <- function(p, df, oval_width, oval_height, npoints = 80){
37 | x <- df$x
38 | y <- df$y
39 | point_seq <- seq(0, 2*pi,length.out = npoints)
40 |
41 | df_ellipse <- matrix(
42 | c((.5*oval_width) * cos(point_seq), (.5*oval_height) * sin(point_seq)),
43 | nrow = npoints, ncol = 2)
44 |
45 | df_ellipse <- mapply(function(x, y){
46 | t(t(df_ellipse) + c(x, y))
47 | }, x = x, y = y, SIMPLIFY = FALSE)
48 | df_ellipse <- data.frame(do.call(rbind, df_ellipse))
49 | df_ellipse$grp <- rep(paste0("g", 1:length(x)), each = npoints)
50 | df$grp <- paste0("g", 1:length(x))
51 | df_ellipse <- merge(df_ellipse, df, by = "grp", all.y = TRUE)
52 | Args <- c("linetype", "size", "colour", "fill", "alpha", "linewidth")
53 | Args <- as.list(df_ellipse[which(names(df_ellipse) %in% Args)])
54 |
55 | Args <- c(list(
56 | data = df_ellipse,
57 | mapping = aes(x= .data[["X1"]], y= .data[["X2"]], group = .data[["grp"]])), Args)
58 |
59 | p + do.call(geom_polygon, Args)
60 | }
61 |
62 | #p <- ggplot(data = NULL)
63 | #oval_node(p, x = c(0, 0), y = c(0, 3), oval_width = 2, oval_height = 1)
64 |
--------------------------------------------------------------------------------
/R/plot_merge.R:
--------------------------------------------------------------------------------
1 | #' @export
2 | merge.sem_graph <- function(..., nrow = NULL, ncol = NULL, distance_x = 1, distance_y = 1){
3 | dots <- list(...)
4 | n <- length(dots)
5 | if(is.null(nrow) & is.null(ncol)){
6 | ncol <- ceiling(sqrt(n))
7 | nrow <- ceiling(n/ncol)
8 | } else {
9 | if(is.null(nrow)){
10 | nrow <- ceiling(n/ncol)
11 | }
12 | if(is.null(ncol)){
13 | ncol <- ceiling(n/nrow)
14 | }
15 | }
16 | if(!(nrow*ncol)>=n) stop("Specify nrow and/or ncol.")
17 | m <- matrix(nrow = nrow, ncol = ncol)
18 | m[1:n] <- 1:n
19 | edges <- dots[[1]]$edges
20 | nodes <- dots[[1]]$nodes
21 | xwidths <- apply(m, 2, function(x){
22 | max(unlist(lapply(dots[as.vector(x)], function(d){d$nodes$node_xmax})))
23 | })
24 | yheights <- apply(m, 1, function(x){
25 | max(unlist(lapply(dots[as.vector(x)], function(d){d$nodes$node_ymax})))
26 | })
27 |
28 | for(i in 2:n){
29 | if(any(dots[[i]]$nodes$name %in% dots[[1]]$nodes$name)){
30 | repthese <- dots[[i]]$nodes$name[dots[[i]]$nodes$name %in% dots[[1]]$nodes$name]
31 | names(repthese) <- repthese
32 | repthese[] <- paste0(repthese, ".", i)
33 | dots[[i]]$nodes$name[dots[[i]]$nodes$name %in% names(repthese)] <- repthese[dots[[i]]$nodes$name[dots[[i]]$nodes$name %in% names(repthese)]]
34 | dots[[i]]$edges$from[dots[[i]]$edges$from %in% names(repthese)] <- repthese[dots[[i]]$edges$from[dots[[i]]$edges$from %in% names(repthese)]]
35 | dots[[i]]$edges$to[dots[[i]]$edges$to %in% names(repthese)] <- repthese[dots[[i]]$edges$to[dots[[i]]$edges$to %in% names(repthese)]]
36 | }
37 | thisrow <- which(apply(m, 1, function(x){any(x==i)}))
38 | thiscol <- which(apply(m, 2, function(x){any(x==i)}))
39 |
40 | addnodes <- dots[[i]]$nodes
41 | addx <- sum(xwidths[0:(thiscol-1)]) + (thiscol-1)*distance_x
42 | addnodes[c("x", "node_xmax", "node_xmin")] <- addnodes[c("x", "node_xmax", "node_xmin")] + addx
43 | addy <- sum(yheights[0:(thisrow-1)]) + (thisrow-1)*distance_y
44 | addnodes[c("y", "node_ymax", "node_ymin")] <- addnodes[c("y", "node_ymax", "node_ymin")] + addy
45 |
46 | dots[[i]]$nodes <- addnodes
47 | dots[[1]]$edges <- rbind(dots[[1]]$edges, dots[[m[i]]]$edges)
48 | dots[[1]]$nodes <- rbind(dots[[1]]$nodes, dots[[m[i]]]$nodes)
49 | }
50 | return(dots[[1]])
51 | }
52 |
53 |
--------------------------------------------------------------------------------
/R/print_layout.R:
--------------------------------------------------------------------------------
1 | # print.layout_matrix <- function(x, ...){
2 | # tab <- rbind(paste0("[, ", 1:ncol(x), "]"), x)
3 | # tab[is.na(tab)] <- ""
4 | # tab <- apply(tab, 2, function(i){
5 | # sprintf(paste0("%-", max(nchar(i, type = "width")), "s"), i)
6 | # })
7 | #
8 | #
9 | # dims <- dim(tab)
10 | # #tab <- rbind(tab, sapply(tab[1,], function(i){
11 | # # paste0(rep("-", nchar(i)), collapse = "")
12 | # #}))
13 | # #tab <- tab[c(1, nrow(tab), 2:(nrow(tab)-1)), ]
14 | #
15 | # tab[, 1:(ncol(tab)-1)] <- paste0(tab[, 1:(ncol(tab)-1)], " | ")
16 | # header <- tab[1,]
17 | # tab <- tab[-1, ]
18 | # lines <- matrix(rep(sapply(tab[1,], function(i){paste0(rep("-", (nchar(i))), collapse = "")}), nrow(tab)), nrow = nrow(tab), byrow = TRUE)
19 | # out <- matrix(t(cbind(lines, tab)), ncol = ncol(tab), byrow = TRUE)
20 | #
21 | # #print(out[-nrow(out), ], quote = FALSE)
22 | # spaces <- paste0(rep(" ", 5+nchar(nrow(out))), collapse = '')
23 | # cat(spaces, header, "\n", sep = "")
24 | # for(i in 1:(nrow(out))){
25 | # cat(ifelse(i %% 2 == 0, paste0("[", i%/%2, ", ] "), spaces), out[i, ], "\n", sep = "")
26 | # }
27 | # }
28 |
--------------------------------------------------------------------------------
/R/skip.R:
--------------------------------------------------------------------------------
1 | skip_if_not_local <- function() {
2 |
3 | if (Sys.info()[["user"]] %in% c("Lissa102", "vanlissa")) {
4 | return(invisible(TRUE))
5 | }
6 |
7 | testthat::skip("Not run by package maintainer")
8 | }
9 |
--------------------------------------------------------------------------------
/R/syntax-get_data.R:
--------------------------------------------------------------------------------
1 | # @title Get data from model object
2 | # @description Extracts data from an object for which a method exists.
3 | # @param x An object for which a method exists.
4 | # @param ... Additional arguments passed to and from functions.
5 | # @return A \code{data.frame}.
6 | # @examples
7 | # \dontrun{
8 | # if(interactive()){
9 | # #EXAMPLE1
10 | # }
11 | # }
12 | # @rdname mplus_data
13 | # @export
14 | mplus_data <- function(x, ...){
15 | UseMethod("mplus_data", x)
16 | }
17 |
18 | # @method mplus_data mplusObject
19 | #' @export
20 | mplus_data.mplusObject <- function(x, ...){
21 | Args <- as.list(match.call()[-1])
22 | Args$x <- x$results
23 | do.call(mplus_data, Args)
24 | }
25 |
26 | # @method mplus_data mplus.model
27 | # @export
28 | #' @importFrom utils read.table
29 | mplus_data.mplus.model <- function(x, ...){
30 | df <- read.table(x$input$data$file, stringsAsFactors = FALSE)
31 | names(df) <- mplus_expand_names(x$input$variable$names) #strsplit(x$input$variable$names, split = "\\s+")[[1]]
32 | df
33 | }
34 |
--------------------------------------------------------------------------------
/R/syntax-utils.R:
--------------------------------------------------------------------------------
1 | # Merge two lavaanify tables
2 |
3 |
4 |
5 | # Replace .p1. labels
6 | replace_ps <- function(vec, repl_nums){
7 | out <- vec
8 | rep_these <- which(grepl("^\\.p\\d+\\.$", vec))
9 | out[rep_these] <- paste0(".p", repl_nums[gsub(".", "", substring(vec[rep_these], first = 3), fixed = T)], ".")
10 | out
11 | }
12 |
13 | #' @importFrom lavaan lavOptions
14 | lav_from_dots <- function(...){
15 | dots <- list(...)
16 | # Get list of lavaan option names
17 | lav_opts <- formalArgs(lavaanify)#names(lavOptions())
18 | # Check if any of these are passed in dots
19 | these_opts <- which(names(dots) %in% lav_opts)
20 | if(length(these_opts > 0)){
21 | Args_lav <- dots[these_opts]
22 | } else {
23 | Args_lav <- list()
24 | }
25 | # Set default options corresponding to sem() and cfa()
26 | Args_lav_default <- list(
27 | int.ov.free = TRUE,
28 | int.lv.free = FALSE,
29 | auto.fix.first = TRUE,
30 | auto.fix.single = TRUE,
31 | auto.var = TRUE,
32 | auto.cov.lv.x = TRUE,
33 | auto.efa = TRUE,
34 | auto.th = TRUE,
35 | auto.delta = TRUE,
36 | auto.cov.y = TRUE,
37 | meanstructure = TRUE
38 | )
39 | # If user did not specify default, overwrite
40 | for(this_arg in names(Args_lav_default)){
41 | if(!this_arg %in% names(Args_lav)){
42 | Args_lav[[this_arg]] <- Args_lav_default[[this_arg]]
43 | }
44 | }
45 | return(Args_lav)
46 | }
47 |
--------------------------------------------------------------------------------
/R/syntax_make_constraints.R:
--------------------------------------------------------------------------------
1 | if(FALSE){
2 | tmp <- readClipboard()
3 | tmp <- tmp[grep("\\(", tmp)]
4 |
5 | tmp <- gsub("^.+\\((.+)\\);", "\\1", tmp)
6 |
7 | tmp2 <- gsub("(Moth|Fath)", "Prts", tmp)
8 |
9 | constraints <- mapply(function(x,y){
10 | paste0(gsub("(Moth|Fath)", "Prts", tmp[x]), " = ", tmp[x], " - ", tmp[y], ";")
11 | }, x = which(duplicated(tmp2)), y = which(duplicated(tmp2, fromLast = TRUE)), SIMPLIFY = TRUE)
12 |
13 | names(constraints) <- paste0("p", 1:length(constraints))
14 |
15 | model_constraints <- c("MODEL CONSTRAINT:", "NEW (", names(constraints), ");", paste0(names(constraints), " = ", paste0(attr(constraints, "labs"), "H"), " - ", paste0(attr(constraints, "labs"), "L"), ";"))
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/R/table_results_lavaan.R:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/R/table_results_lavaan.R
--------------------------------------------------------------------------------
/R/zegwaard_carecompass.R:
--------------------------------------------------------------------------------
1 | #' Caregiver Compass Data
2 | #'
3 | #' These simulated data are based on a study by Dijenborgh, Swildens,
4 | #' and Zegwaard on different types of caregivers among those
5 | #' providing informal care to outpatients receiving mental healthcare.
6 | #'
7 | #' \tabular{lll}{
8 | #' \strong{burdened} \tab \code{numeric} \tab How strongly is the caregiver's life affected by their responsibilities? Scale score, based on 15 items with Likert-type response options. Example: "I never feel free of responsibilities"\cr
9 | #' \strong{trapped} \tab \code{numeric} \tab Caregiver's cognitions regarding freedom of choice. Scale score, based on 3 items with Likert-type response options. Example: "I feel trapped by the affliction of my charge"\cr
10 | #' \strong{negaffect} \tab \code{numeric} \tab Different types of negative emotions experienced by the caregiver. Scale score, based on 9 items with Likert-type response options. Example: "I feel angry in the relationship with my charge"\cr
11 | #' \strong{loneliness} \tab \code{numeric} \tab Caregiver's perceived loneliness. Scale score, based on 11 items with Likert-type response options. Example: "I miss having people around"\cr
12 | #' \strong{sex} \tab \code{factor} \tab Caregiver sex\cr
13 | #' \strong{sexpatient} \tab \code{factor} \tab Sex of the patient\cr
14 | #' \strong{cohabiting} \tab \code{factor} \tab Whether or not the caregiver cohabits with the patient\cr
15 | #' \strong{distance} \tab \code{numeric} \tab Travel time in minutes for the caregiver to reach the patient\cr
16 | #' \strong{freqvisit} \tab \code{ordered} \tab Ordinal variable, indicating frequency of visits\cr
17 | #' \strong{relationship} \tab \code{factor} \tab Type of relationship of patient with caregiver
18 | #' }
19 | #' @docType data
20 | #' @keywords datasets
21 | #' @name zegwaard_carecompass
22 | #' @usage data(zegwaard_carecompass)
23 | # @references Alkema, L. M., Van Lissa, C. J., Kooi, M., & Koelmans, A. A. (2022).
24 | # Maximizing Realism: Mapping Plastic Particles at the Ocean Surface Using
25 | # Mixtures of Normal Distributions. Environmental Science & Technology,
26 | # 56(22), 15552-15562.
27 | # \doi{10.1021/acs.est.2c03559}
28 | #' @format A data frame with 513 rows and 10 variables.
29 | NULL
30 |
--------------------------------------------------------------------------------
/R/zzz.R:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/R/zzz.R
--------------------------------------------------------------------------------
/_pkgdown.yml:
--------------------------------------------------------------------------------
1 | url: https://cjvanlissa.github.io/tidySEM/
2 | template:
3 | bootstrap: 5
4 |
5 |
--------------------------------------------------------------------------------
/badge.ai:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/badge.ai
--------------------------------------------------------------------------------
/codecov.yml:
--------------------------------------------------------------------------------
1 | comment: false
2 |
3 | coverage:
4 | status:
5 | project:
6 | default:
7 | target: auto
8 | threshold: 1%
9 | informational: true
10 | patch:
11 | default:
12 | target: auto
13 | threshold: 1%
14 | informational: true
15 |
--------------------------------------------------------------------------------
/cran-comments.md:
--------------------------------------------------------------------------------
1 | # tidySEM 0.2.8
2 |
3 | * Make OpenMx a Suggest instead of an Import
4 | * Improve parsing of dagitty objects
5 | * Allow floating point coordinates in layouts of class `tidy_layout` (mostly for
6 | dagitty plots)
7 |
8 | ## Test environments
9 |
10 | * local Windows 11 install, R 4.4.2
11 | * GitHub Actions (r-lib): windows-latest (release)
12 | * GitHub Actions (r-lib): macOS-latest (release)
13 | * GitHub Actions (r-lib): ubuntu-20.04 (release)
14 | * GitHub Actions (r-lib): ubuntu-20.04 (devel)
15 | * GitHub Actions (r-lib): ubuntu-20.04 (oldrel-1)
16 | * win-builder: release
17 | * win-builder: oldrelease
18 | * win-builder: development
19 | * Rhub 14 [CT] gcc14 R-devel (2024-06-02 r86665)
20 | * Rhub 20 [CT] ubuntu-clang R-devel (2024-06-02 r86665)
21 | * Rhub 21 [CT] ubuntu-gcc12 R-devel (2024-06-02 r86665)
22 |
23 | ## R CMD check results
24 |
25 | 0 errors | 0 warnings | 0 notes
26 |
--------------------------------------------------------------------------------
/data/alkema_microplastics.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/data/alkema_microplastics.rda
--------------------------------------------------------------------------------
/data/data_mix_ordinal.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/data/data_mix_ordinal.rda
--------------------------------------------------------------------------------
/data/maene_identity.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/data/maene_identity.rda
--------------------------------------------------------------------------------
/data/plas_depression.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/data/plas_depression.rda
--------------------------------------------------------------------------------
/data/zegwaard_carecompass.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/data/zegwaard_carecompass.rda
--------------------------------------------------------------------------------
/dev/blrt_faster.R:
--------------------------------------------------------------------------------
1 | blrt2 <- function(null, alt, iter = 10, ...){
2 | LR <- null$output$Minus2LogLikelihood - alt$output$Minus2LogLikelihood
3 | mnull <- null
4 | malt <- alt
5 | out <- replicate(n = iter, {
6 | df_boot <- mxGenerateData(null)
7 | m1 <- mxModel(mnull, mxData(observed = df_boot, type = "raw"))
8 | m1 <- try(mxRun(m1, silent = TRUE))
9 | if(inherits(m1, "try-error") | m1$output$status$code %in% c(5, 6)){
10 | m1 <- try(mxTryHard(m1, silent = TRUE, extraTries = 10, verbose = FALSE, exhaustive = FALSE))
11 | }
12 | m2 <- mxModel(malt, mxData(observed = df_boot, type = "raw"))
13 | m2 <- try(mxRun(m2, silent = TRUE))
14 | if(inherits(m2, "try-error") | m2$output$status$code %in% c(5, 6)){
15 | m2 <- try(mxTryHard(m2, silent = TRUE, extraTries = 10, verbose = FALSE, exhaustive = FALSE))
16 | }
17 | m1$output$Minus2LogLikelihood-m2$output$Minus2LogLikelihood
18 | })
19 | pval <- sum(out > LR) / length(out)
20 | c(LR = LR, p_blrt = pval)
21 | }
22 |
23 | blrtpar <- function(null, alt, iter = 10, parallel = TRUE, ...){
24 | LR <- null$output$Minus2LogLikelihood - alt$output$Minus2LogLikelihood
25 | mnull <- null
26 | malt <- alt
27 | cl <- parallel::makeCluster(parallel::detectCores()) #change the 2 to your number of CPU cores
28 | doSNOW::registerDoSNOW(cl)
29 | out <- foreach::foreach(n = 1:iter, .packages = c("OpenMx")) %dopar% {
30 | df_boot <- mxGenerateData(null)
31 | m1 <- mxModel(mnull, mxData(observed = df_boot, type = "raw"))
32 | m1 <- try(mxRun(m1, silent = TRUE))
33 | if(inherits(m1, "try-error") | m1$output$status$code %in% c(5, 6)){
34 | m1 <- try(mxTryHard(m1, silent = TRUE, extraTries = 10, verbose = FALSE, exhaustive = FALSE))
35 | }
36 | m2 <- mxModel(malt, mxData(observed = df_boot, type = "raw"))
37 | m2 <- try(mxRun(m2, silent = TRUE))
38 | if(inherits(m2, "try-error") | m2$output$status$code %in% c(5, 6)){
39 | m2 <- try(mxTryHard(m2, silent = TRUE, extraTries = 10, verbose = FALSE, exhaustive = FALSE))
40 | }
41 | m1$output$Minus2LogLikelihood-m2$output$Minus2LogLikelihood
42 | }
43 | stopCluster(cl)
44 | pval <- sum(out > LR) / length(out)
45 | c(LR = LR, p_blrt = pval)
46 | }
47 |
48 |
--------------------------------------------------------------------------------
/dev/lazy_bootstrap.R:
--------------------------------------------------------------------------------
1 | library(foreach)
2 | library(tidySEM)
3 | library(parallel)
4 |
5 | reps <- 100
6 | df <- diabetes[, 2:4]
7 | df <- iris[1:4]
8 | #names(df) <- paste0("x", 1:4)
9 | res <- mx_profiles(df, 1:7)
10 |
11 | dat_stat = cor(df)
12 | select_these <- lower.tri(dat_stat)
13 | dat_stat = cor(df)[select_these]
14 |
15 | cl <- parallel::makeCluster(parallel::detectCores())
16 | doParallel::registerDoParallel(cl)
17 | rep_stat <- foreach(i = rep(2:length(res), each = reps), .combine = rbind, .packages = "OpenMx") %dopar% {
18 | c(i,
19 | (cor(mxGenerateData(res[[i-1]]))[select_these]-dat_stat)^2,
20 | (cor(mxGenerateData(res[[i]]))[select_these] - dat_stat)^2)
21 | }
22 | parallel::stopCluster(cl)
23 |
24 |
25 | npars <- sapply(res, function(m){ length(OpenMx::omxGetParameters(m)) })
26 | tests <- lapply(2:length(res), function(i){
27 | msqs <- colMeans(rep_stat[rep_stat[,1] == i,-1])
28 | fvals <- msqs[1:length(dat_stat)] / msqs[(length(dat_stat)+1):length(msqs)]
29 | cbind(fvals,
30 | sapply(fvals, pf, df1 = npars[i-1], df2 = npars[i], lower.tail = FALSE))
31 | })
32 |
33 | sapply(tests, function(i){formatC(i[,2], digits = 3, format = "f")})
34 |
35 | tab <- table_fit(res)
36 | tst <- list()
37 | for(i in 2:nrow(tab)){
38 | tst[[i-1]] <- tidyLPA::calc_lrt(n = tab$n[1],
39 | null_ll = tab$LL[i-1],
40 | null_param = tab$Parameters[i-1],
41 | null_classes = i-1,
42 | alt_ll = tab$LL[i],
43 | alt_param = tab$Parameters[i],
44 | alt_classes = i)
45 | }
46 |
--------------------------------------------------------------------------------
/dev/lca_res.RData:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/dev/lca_res.RData
--------------------------------------------------------------------------------
/dev/res_gmm_nopca.RData:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/dev/res_gmm_nopca.RData
--------------------------------------------------------------------------------
/docs/articles/Generating_syntax_files/accessible-code-block-0.0.1/empty-anchor.js:
--------------------------------------------------------------------------------
1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) -->
2 | // v0.0.1
3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020.
4 |
5 | document.addEventListener('DOMContentLoaded', function() {
6 | const codeList = document.getElementsByClassName("sourceCode");
7 | for (var i = 0; i < codeList.length; i++) {
8 | var linkList = codeList[i].getElementsByTagName('a');
9 | for (var j = 0; j < linkList.length; j++) {
10 | if (linkList[j].innerHTML === "") {
11 | linkList[j].setAttribute('aria-hidden', 'true');
12 | }
13 | }
14 | }
15 | });
16 |
--------------------------------------------------------------------------------
/docs/articles/Generating_syntax_files/header-attrs-2.9/header-attrs.js:
--------------------------------------------------------------------------------
1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to
2 | // be compatible with the behavior of Pandoc < 2.8).
3 | document.addEventListener('DOMContentLoaded', function(e) {
4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
5 | var i, h, a;
6 | for (i = 0; i < hs.length; i++) {
7 | h = hs[i];
8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
9 | a = h.attributes;
10 | while (a.length > 0) h.removeAttribute(a[0].name);
11 | }
12 | });
13 |
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/accessible-code-block-0.0.1/empty-anchor.js:
--------------------------------------------------------------------------------
1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) -->
2 | // v0.0.1
3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020.
4 |
5 | document.addEventListener('DOMContentLoaded', function() {
6 | const codeList = document.getElementsByClassName("sourceCode");
7 | for (var i = 0; i < codeList.length; i++) {
8 | var linkList = codeList[i].getElementsByTagName('a');
9 | for (var j = 0; j < linkList.length; j++) {
10 | if (linkList[j].innerHTML === "") {
11 | linkList[j].setAttribute('aria-hidden', 'true');
12 | }
13 | }
14 | }
15 | });
16 |
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-10-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-10-1.png
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-16-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-16-1.png
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-17-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-17-1.png
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-18-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-18-1.png
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-19-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-19-1.png
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-20-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-20-1.png
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-24-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-24-1.png
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-25-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-25-1.png
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-26-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-26-1.png
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-27-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-27-1.png
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-28-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-28-1.png
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-29-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-29-1.png
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-30-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-30-1.png
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-31-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-31-1.png
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-45-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-45-1.png
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-46-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-46-1.png
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-47-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-47-1.png
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-50-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-50-1.png
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-51-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-51-1.png
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-52-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/Plotting_graphs_files/figure-html/unnamed-chunk-52-1.png
--------------------------------------------------------------------------------
/docs/articles/Plotting_graphs_files/header-attrs-2.9/header-attrs.js:
--------------------------------------------------------------------------------
1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to
2 | // be compatible with the behavior of Pandoc < 2.8).
3 | document.addEventListener('DOMContentLoaded', function(e) {
4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
5 | var i, h, a;
6 | for (i = 0; i < hs.length; i++) {
7 | h = hs[i];
8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
9 | a = h.attributes;
10 | while (a.length > 0) h.removeAttribute(a[0].name);
11 | }
12 | });
13 |
--------------------------------------------------------------------------------
/docs/articles/Tabulating_results_files/accessible-code-block-0.0.1/empty-anchor.js:
--------------------------------------------------------------------------------
1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) -->
2 | // v0.0.1
3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020.
4 |
5 | document.addEventListener('DOMContentLoaded', function() {
6 | const codeList = document.getElementsByClassName("sourceCode");
7 | for (var i = 0; i < codeList.length; i++) {
8 | var linkList = codeList[i].getElementsByTagName('a');
9 | for (var j = 0; j < linkList.length; j++) {
10 | if (linkList[j].innerHTML === "") {
11 | linkList[j].setAttribute('aria-hidden', 'true');
12 | }
13 | }
14 | }
15 | });
16 |
--------------------------------------------------------------------------------
/docs/articles/Tabulating_results_files/header-attrs-2.9/header-attrs.js:
--------------------------------------------------------------------------------
1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to
2 | // be compatible with the behavior of Pandoc < 2.8).
3 | document.addEventListener('DOMContentLoaded', function(e) {
4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
5 | var i, h, a;
6 | for (i = 0; i < hs.length; i++) {
7 | h = hs[i];
8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
9 | a = h.attributes;
10 | while (a.length > 0) h.removeAttribute(a[0].name);
11 | }
12 | });
13 |
--------------------------------------------------------------------------------
/docs/articles/arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/arrow.png
--------------------------------------------------------------------------------
/docs/articles/arrow.svg:
--------------------------------------------------------------------------------
1 |
2 |
18 |
--------------------------------------------------------------------------------
/docs/articles/curve.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/curve.png
--------------------------------------------------------------------------------
/docs/articles/curve.svg:
--------------------------------------------------------------------------------
1 |
2 |
17 |
--------------------------------------------------------------------------------
/docs/articles/error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/error.png
--------------------------------------------------------------------------------
/docs/articles/error.svg:
--------------------------------------------------------------------------------
1 |
2 |
21 |
--------------------------------------------------------------------------------
/docs/articles/gmm_bivariate_bic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/gmm_bivariate_bic.png
--------------------------------------------------------------------------------
/docs/articles/gmm_plotfit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/gmm_plotfit.png
--------------------------------------------------------------------------------
/docs/articles/lca_confirmatory_files/figure-html/unnamed-chunk-18-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/lca_confirmatory_files/figure-html/unnamed-chunk-18-1.png
--------------------------------------------------------------------------------
/docs/articles/lca_confirmatory_files/figure-html/unnamed-chunk-21-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/lca_confirmatory_files/figure-html/unnamed-chunk-21-1.png
--------------------------------------------------------------------------------
/docs/articles/lca_confirmatory_files/figure-html/unnamed-chunk-21-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/lca_confirmatory_files/figure-html/unnamed-chunk-21-2.png
--------------------------------------------------------------------------------
/docs/articles/lca_exploratory_files/figure-html/unnamed-chunk-20-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/lca_exploratory_files/figure-html/unnamed-chunk-20-1.png
--------------------------------------------------------------------------------
/docs/articles/lca_plot_desc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/lca_plot_desc.png
--------------------------------------------------------------------------------
/docs/articles/lca_prob.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/lca_prob.png
--------------------------------------------------------------------------------
/docs/articles/lcga_plot_fit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/lcga_plot_fit.png
--------------------------------------------------------------------------------
/docs/articles/lpa_bivariate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/lpa_bivariate.png
--------------------------------------------------------------------------------
/docs/articles/lpa_profiles.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/lpa_profiles.png
--------------------------------------------------------------------------------
/docs/articles/mod_meas.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/mod_meas.png
--------------------------------------------------------------------------------
/docs/articles/mod_reg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/mod_reg.png
--------------------------------------------------------------------------------
/docs/articles/mod_sem1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/mod_sem1.png
--------------------------------------------------------------------------------
/docs/articles/mod_sem2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/mod_sem2.png
--------------------------------------------------------------------------------
/docs/articles/pgfig1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/pgfig1.png
--------------------------------------------------------------------------------
/docs/articles/pgfig10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/pgfig10.png
--------------------------------------------------------------------------------
/docs/articles/pgfig11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/pgfig11.png
--------------------------------------------------------------------------------
/docs/articles/pgfig2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/pgfig2.png
--------------------------------------------------------------------------------
/docs/articles/pgfig2_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/pgfig2_1.png
--------------------------------------------------------------------------------
/docs/articles/pgfig3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/pgfig3.png
--------------------------------------------------------------------------------
/docs/articles/pgfig4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/pgfig4.png
--------------------------------------------------------------------------------
/docs/articles/pgfig4.svg:
--------------------------------------------------------------------------------
1 |
2 |
32 |
--------------------------------------------------------------------------------
/docs/articles/pgfig5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/pgfig5.png
--------------------------------------------------------------------------------
/docs/articles/pgfig6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/pgfig6.png
--------------------------------------------------------------------------------
/docs/articles/pgfig7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/pgfig7.png
--------------------------------------------------------------------------------
/docs/articles/pgfig8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/pgfig8.png
--------------------------------------------------------------------------------
/docs/articles/pgfig9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/pgfig9.png
--------------------------------------------------------------------------------
/docs/articles/plot_dist.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/plot_dist.png
--------------------------------------------------------------------------------
/docs/articles/plot_fit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/plot_fit.png
--------------------------------------------------------------------------------
/docs/articles/plot_gmm_desc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/plot_gmm_desc.png
--------------------------------------------------------------------------------
/docs/articles/plot_gmm_desc_log.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/plot_gmm_desc_log.png
--------------------------------------------------------------------------------
/docs/articles/plot_gmm_scatter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/plot_gmm_scatter.png
--------------------------------------------------------------------------------
/docs/articles/plot_lpa_desc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/plot_lpa_desc.png
--------------------------------------------------------------------------------
/docs/articles/plot_traj.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/plot_traj.png
--------------------------------------------------------------------------------
/docs/articles/plot_trans.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/plot_trans.png
--------------------------------------------------------------------------------
/docs/articles/sem_graph_files/accessible-code-block-0.0.1/empty-anchor.js:
--------------------------------------------------------------------------------
1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) -->
2 | // v0.0.1
3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020.
4 |
5 | document.addEventListener('DOMContentLoaded', function() {
6 | const codeList = document.getElementsByClassName("sourceCode");
7 | for (var i = 0; i < codeList.length; i++) {
8 | var linkList = codeList[i].getElementsByTagName('a');
9 | for (var j = 0; j < linkList.length; j++) {
10 | if (linkList[j].innerHTML === "") {
11 | linkList[j].setAttribute('aria-hidden', 'true');
12 | }
13 | }
14 | }
15 | });
16 |
--------------------------------------------------------------------------------
/docs/articles/sem_graph_files/header-attrs-2.9/header-attrs.js:
--------------------------------------------------------------------------------
1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to
2 | // be compatible with the behavior of Pandoc < 2.8).
3 | document.addEventListener('DOMContentLoaded', function(e) {
4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
5 | var i, h, a;
6 | for (i = 0; i < hs.length; i++) {
7 | h = hs[i];
8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
9 | a = h.attributes;
10 | while (a.length > 0) h.removeAttribute(a[0].name);
11 | }
12 | });
13 |
--------------------------------------------------------------------------------
/docs/articles/spreadsheet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/spreadsheet.png
--------------------------------------------------------------------------------
/docs/articles/spreadsheet2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/spreadsheet2.png
--------------------------------------------------------------------------------
/docs/articles/var_lat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/var_lat.png
--------------------------------------------------------------------------------
/docs/articles/var_obs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/articles/var_obs.png
--------------------------------------------------------------------------------
/docs/articles/var_obs.svg:
--------------------------------------------------------------------------------
1 |
2 |
38 |
--------------------------------------------------------------------------------
/docs/badge.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/badge.png
--------------------------------------------------------------------------------
/docs/bootstrap-toc.css:
--------------------------------------------------------------------------------
1 | /*!
2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/)
3 | * Copyright 2015 Aidan Feldman
4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */
5 |
6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */
7 |
8 | /* All levels of nav */
9 | nav[data-toggle='toc'] .nav > li > a {
10 | display: block;
11 | padding: 4px 20px;
12 | font-size: 13px;
13 | font-weight: 500;
14 | color: #767676;
15 | }
16 | nav[data-toggle='toc'] .nav > li > a:hover,
17 | nav[data-toggle='toc'] .nav > li > a:focus {
18 | padding-left: 19px;
19 | color: #563d7c;
20 | text-decoration: none;
21 | background-color: transparent;
22 | border-left: 1px solid #563d7c;
23 | }
24 | nav[data-toggle='toc'] .nav > .active > a,
25 | nav[data-toggle='toc'] .nav > .active:hover > a,
26 | nav[data-toggle='toc'] .nav > .active:focus > a {
27 | padding-left: 18px;
28 | font-weight: bold;
29 | color: #563d7c;
30 | background-color: transparent;
31 | border-left: 2px solid #563d7c;
32 | }
33 |
34 | /* Nav: second level (shown on .active) */
35 | nav[data-toggle='toc'] .nav .nav {
36 | display: none; /* Hide by default, but at >768px, show it */
37 | padding-bottom: 10px;
38 | }
39 | nav[data-toggle='toc'] .nav .nav > li > a {
40 | padding-top: 1px;
41 | padding-bottom: 1px;
42 | padding-left: 30px;
43 | font-size: 12px;
44 | font-weight: normal;
45 | }
46 | nav[data-toggle='toc'] .nav .nav > li > a:hover,
47 | nav[data-toggle='toc'] .nav .nav > li > a:focus {
48 | padding-left: 29px;
49 | }
50 | nav[data-toggle='toc'] .nav .nav > .active > a,
51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a,
52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a {
53 | padding-left: 28px;
54 | font-weight: 500;
55 | }
56 |
57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */
58 | nav[data-toggle='toc'] .nav > .active > ul {
59 | display: block;
60 | }
61 |
--------------------------------------------------------------------------------
/docs/docsearch.js:
--------------------------------------------------------------------------------
1 | $(function() {
2 |
3 | // register a handler to move the focus to the search bar
4 | // upon pressing shift + "/" (i.e. "?")
5 | $(document).on('keydown', function(e) {
6 | if (e.shiftKey && e.keyCode == 191) {
7 | e.preventDefault();
8 | $("#search-input").focus();
9 | }
10 | });
11 |
12 | $(document).ready(function() {
13 | // do keyword highlighting
14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */
15 | var mark = function() {
16 |
17 | var referrer = document.URL ;
18 | var paramKey = "q" ;
19 |
20 | if (referrer.indexOf("?") !== -1) {
21 | var qs = referrer.substr(referrer.indexOf('?') + 1);
22 | var qs_noanchor = qs.split('#')[0];
23 | var qsa = qs_noanchor.split('&');
24 | var keyword = "";
25 |
26 | for (var i = 0; i < qsa.length; i++) {
27 | var currentParam = qsa[i].split('=');
28 |
29 | if (currentParam.length !== 2) {
30 | continue;
31 | }
32 |
33 | if (currentParam[0] == paramKey) {
34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20"));
35 | }
36 | }
37 |
38 | if (keyword !== "") {
39 | $(".contents").unmark({
40 | done: function() {
41 | $(".contents").mark(keyword);
42 | }
43 | });
44 | }
45 | }
46 | };
47 |
48 | mark();
49 | });
50 | });
51 |
52 | /* Search term highlighting ------------------------------*/
53 |
54 | function matchedWords(hit) {
55 | var words = [];
56 |
57 | var hierarchy = hit._highlightResult.hierarchy;
58 | // loop to fetch from lvl0, lvl1, etc.
59 | for (var idx in hierarchy) {
60 | words = words.concat(hierarchy[idx].matchedWords);
61 | }
62 |
63 | var content = hit._highlightResult.content;
64 | if (content) {
65 | words = words.concat(content.matchedWords);
66 | }
67 |
68 | // return unique words
69 | var words_uniq = [...new Set(words)];
70 | return words_uniq;
71 | }
72 |
73 | function updateHitURL(hit) {
74 |
75 | var words = matchedWords(hit);
76 | var url = "";
77 |
78 | if (hit.anchor) {
79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor;
80 | } else {
81 | url = hit.url + '?q=' + escape(words.join(" "));
82 | }
83 |
84 | return url;
85 | }
86 |
--------------------------------------------------------------------------------
/docs/link.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
13 |
--------------------------------------------------------------------------------
/docs/pkgdown.yml:
--------------------------------------------------------------------------------
1 | pandoc: '3.2'
2 | pkgdown: 2.1.1
3 | pkgdown_sha: ~
4 | articles:
5 | Generating_syntax: Generating_syntax.html
6 | lca_confirmatory: lca_confirmatory.html
7 | lca_exploratory: lca_exploratory.html
8 | lca_lcga: lca_lcga.html
9 | lca_ordinal: lca_ordinal.html
10 | Plotting_graphs: Plotting_graphs.html
11 | sem_graph: sem_graph.html
12 | SMART_LCA_checklist: SMART_LCA_checklist.html
13 | Tabulating_results: Tabulating_results.html
14 | last_built: 2025-01-16T12:39Z
15 |
--------------------------------------------------------------------------------
/docs/reference/Rplot001.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/reference/Rplot001.png
--------------------------------------------------------------------------------
/docs/reference/Rplot002.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/reference/Rplot002.png
--------------------------------------------------------------------------------
/docs/reference/edit_graph-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/reference/edit_graph-1.png
--------------------------------------------------------------------------------
/docs/reference/graph_sem-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/reference/graph_sem-1.png
--------------------------------------------------------------------------------
/docs/reference/plot_bivariate-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/reference/plot_bivariate-1.png
--------------------------------------------------------------------------------
/docs/reference/plot_prob-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/reference/plot_prob-1.png
--------------------------------------------------------------------------------
/docs/reference/plot_profiles-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/docs/reference/plot_profiles-1.png
--------------------------------------------------------------------------------
/man/BCH.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/mixture-3step.R
3 | \name{BCH}
4 | \alias{BCH}
5 | \title{Estimate an Auxiliary Model using the BCH Method}
6 | \usage{
7 | BCH(x, model, data, ...)
8 | }
9 | \arguments{
10 | \item{x}{An object for which a method exists.}
11 |
12 | \item{model}{An object that can be converted to an \code{OpenMx} model
13 | using \code{\link{as_ram}}.}
14 |
15 | \item{data}{A data.frame on which the auxiliary model can be evaluated.}
16 |
17 | \item{...}{further arguments to be passed to or from other methods.}
18 | }
19 | \value{
20 | An MxModel.
21 | }
22 | \description{
23 | Estimate an auxiliary model based on a latent classification
24 | by means of mixture modeling (see \code{\link{mx_mixture}}).
25 |
26 | The auxiliary model is treated as a multi-group model. All cases are used in
27 | all groups, but they are weighted by group-specific BCH weights as described
28 | in Bolck, Croon, & Hagenaars, 2004.
29 | }
30 | \examples{
31 | if(requireNamespace("OpenMx", quietly = TRUE)){
32 | dat <- data.frame(x = iris$Petal.Length)
33 | mixmod <- mx_profiles(dat,
34 | classes = 2)
35 | res <- BCH(mixmod, "y ~ 1", data = data.frame(y = iris$Sepal.Length))
36 | }
37 | }
38 | \references{
39 | Bolck, A., Croon, M., & Hagenaars, J. (2004). Estimating latent
40 | structure models with categorical variables: One-step versus three-step
41 | estimators. Political Analysis, 12(1), 3–27. \doi{10.1093/pan/mph001}
42 | }
43 |
--------------------------------------------------------------------------------
/man/BLRT.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/blrt.R
3 | \name{BLRT}
4 | \alias{BLRT}
5 | \title{Conduct Bootstrapped Likelihood Ratio Test}
6 | \usage{
7 | BLRT(x, replications = 100, ...)
8 | }
9 | \arguments{
10 | \item{x}{An object for which a method exists.}
11 |
12 | \item{replications}{Integer reflecting the number of bootstrapped
13 | replications, defaults to \code{100}.}
14 |
15 | \item{...}{further arguments to be passed to or from other methods.}
16 | }
17 | \value{
18 | A data.frame.
19 | }
20 | \description{
21 | Conduct Bootstrapped Likelihood Ratio Test to compare two
22 | mixture models.
23 | }
24 | \examples{
25 | \dontrun{
26 | df <- iris[, 1, drop = FALSE]
27 | names(df) <- "x"
28 | res <- mx_mixture(model = "x ~ m{C}*1
29 | x ~~ v{C}*x", classes = 1:2, data = df)
30 | BLRT(res, replications = 4)
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/man/add_paths.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/syntax-add_paths.R
3 | \name{add_paths}
4 | \alias{add_paths}
5 | \title{Add paths to an object of class 'tidy_sem'}
6 | \usage{
7 | add_paths(model, ...)
8 | }
9 | \arguments{
10 | \item{model}{An object of class \code{tidy_sem}.}
11 |
12 | \item{...}{Paths to add or substitute, specified in
13 | \link[lavaan:model.syntax]{lavaan::model.syntax},
14 | and separated by commas.}
15 | }
16 | \value{
17 | An object of class \code{tidy_sem}.
18 | }
19 | \description{
20 | Add paths to an object of class \code{tidy_sem}, or replace
21 | existing paths. The paths must be specified as
22 | \link[lavaan:model.syntax]{lavaan::model.syntax}, and separated by commas.
23 | }
24 | \details{
25 | Currently, only the \code{lavaan}
26 | commands \code{~,
27 | ~~, =~,} and \code{~1} are parsed.
28 |
29 | This function relies on
30 | \link[lavaan:model.syntax]{lavaan::model.syntax} to convert syntax strings
31 | to \code{lavaan} parameter tables. By default, is uses the arguments
32 | \code{int.ov.free = TRUE, int.lv.free = FALSE, auto.fix.first = TRUE,
33 | auto.fix.single = TRUE, auto.var = TRUE, auto.cov.lv.x = TRUE,
34 | auto.efa = TRUE, auto.th = TRUE, auto.delta = TRUE, auto.cov.y = TRUE,
35 | meanstructure = TRUE}, in a similar way
36 | to \code{\link[lavaan:sem]{lavaan::sem()}} and \code{\link[lavaan:cfa]{lavaan::cfa()}}.
37 | }
38 | \examples{
39 | library(lavaan)
40 | df <- iris[, 1:4]
41 | names(df) <- paste0("x_", 1:4)
42 | model <- tidy_sem(df)
43 | model <- measurement(model)
44 | model <- add_paths(model, x =~ a*x_1 + b*x_2 + a*x_3 + b*x_4)
45 | res <- estimate_lavaan(model)
46 | summary(res)
47 | }
48 | \seealso{
49 | \link[lavaan:model.syntax]{lavaan::model.syntax}
50 | }
51 |
--------------------------------------------------------------------------------
/man/alkema_microplastics.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/alkema_microplastics.R
3 | \docType{data}
4 | \name{alkema_microplastics}
5 | \alias{alkema_microplastics}
6 | \title{Ocean Microplastics Data}
7 | \format{
8 | A data frame with 6942 rows and 11 variables.
9 | }
10 | \usage{
11 | data(alkema_microplastics)
12 | }
13 | \description{
14 | These data were collected by Alkema during a cruise from 04/2018 to
15 | 06/2018 traversing the Atlantic Ocean from South Africa to Norway.
16 | A 500 micrometer meshed Manta Trawl was towed outside the
17 | wake of the ship for 1 h
18 | each day. Length, width, height and polymer type of 6.942 particles
19 | were measured using infrared spectroscopy and image analysis.
20 | }
21 | \details{
22 | \tabular{lll}{
23 | \strong{current} \tab \code{factor} \tab Which ocean current the sample was taken from\cr
24 | \strong{sample} \tab \code{integer} \tab Sample ID\cr
25 | \strong{length} \tab \code{numeric} \tab Particle length in mm\cr
26 | \strong{width} \tab \code{numeric} \tab Particle width in mm\cr
27 | \strong{height_est} \tab \code{numeric} \tab Estimated particle height in mm\cr
28 | \strong{height_obs} \tab \code{numeric} \tab Observed particle height in mm. Height was only measured for large particles\cr
29 | \strong{category} \tab \code{factor} \tab Particle category based on visual inspection\cr
30 | \strong{poly_type} \tab \code{factor} \tab Polymer type as determined by near infrared spectroscopy (NIR)\cr
31 | \strong{two_dim} \tab \code{logical} \tab Whether or not the particle can be treated as two-dimensional\cr
32 | \strong{film} \tab \code{logical} \tab Whether or not the particle appears to be a film\cr
33 | \strong{line} \tab \code{logical} \tab Whether or not the particle appears to be a line
34 | }
35 | }
36 | \references{
37 | Alkema, L. M., Van Lissa, C. J., Kooi, M., & Koelmans, A. A. (2022).
38 | Maximizing Realism: Mapping Plastic Particles at the Ocean Surface Using
39 | Mixtures of Normal Distributions. Environmental Science & Technology,
40 | 56(22), 15552-15562.
41 | \doi{10.1021/acs.est.2c03559}
42 | }
43 | \keyword{datasets}
44 |
--------------------------------------------------------------------------------
/man/append_class_draws.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/mixture-pseudo_class.R
3 | \name{append_class_draws}
4 | \alias{append_class_draws}
5 | \title{Append Pseudo-class Draws}
6 | \usage{
7 | append_class_draws(x, data = NULL, m = 20)
8 | }
9 | \arguments{
10 | \item{x}{An object for which a method exists, usually a \code{mx_mixture} model.}
11 |
12 | \item{data}{A data.frame which the \code{class} variable is appended to. Note
13 | that the row order must be identical to that of the data used to fit \code{x},
14 | as these data will be augmented with a pseudo-class draw for that specific
15 | individual.}
16 |
17 | \item{m}{Integer. Number of datasets to generate. Default is 10.}
18 | }
19 | \value{
20 | A data.frame of class \code{class_draws}.
21 | }
22 | \description{
23 | Generates \code{m} datasets with random draws of a variable named \code{class}, with
24 | probability for these draws based on each case's probability of belonging to
25 | that class according to the model in \code{x}.
26 | }
27 | \examples{
28 | if(requireNamespace("OpenMx", quietly = TRUE)){
29 | dat <- iris[c(1:5, 50:55, 100:105),1:3]
30 | colnames(dat) <- letters[1:3]
31 | fit <- mx_profiles(data = dat, classes = 2)
32 |
33 | append_class_draws(fit, data = iris[c(1:5, 50:55, 100:105), 4, drop = FALSE])
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/man/as_lavaan.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/syntax-as_syntax.R
3 | \name{as_lavaan}
4 | \alias{as_lavaan}
5 | \title{Convert tidy_sem to 'lavaan' syntax}
6 | \usage{
7 | as_lavaan(x, ...)
8 | }
9 | \arguments{
10 | \item{x}{An object of class \code{tidy_sem}}
11 |
12 | \item{...}{Additional parameters to be passed to and from functions.}
13 | }
14 | \value{
15 | Character vector.
16 | }
17 | \description{
18 | Final stage in the 'tidySEM' workflow for syntax generation:
19 | Convert the \code{tidy_sem} object to \code{lavaan} syntax in tabular format
20 | (see \code{\link[lavaan]{model.syntax}}).
21 | }
22 | \examples{
23 | mod <- list(syntax = structure(list(lhs = "x", op = "~", rhs = "y",
24 | free = TRUE, value = "", label = "",
25 | category = "", aspect = ""),
26 | class = "data.frame", row.names = c(NA, -1L)))
27 | class(mod) <- "tidy_sem"
28 | as_lavaan(mod)
29 | }
30 |
--------------------------------------------------------------------------------
/man/as_mplus.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/syntax-as_syntax.R
3 | \name{as_mplus}
4 | \alias{as_mplus}
5 | \title{Convert tidy_sem to 'Mplus' syntax}
6 | \usage{
7 | as_mplus(x, ...)
8 | }
9 | \arguments{
10 | \item{x}{An object of class \code{tidy_sem}.}
11 |
12 | \item{...}{Additional parameters to be passed to and from functions.}
13 | }
14 | \value{
15 | Character vector.
16 | }
17 | \description{
18 | Final stage in the 'tidySEM' workflow for syntax generation:
19 | Convert the \code{tidy_sem} object to 'Mplus' syntax.
20 | }
21 | \examples{
22 | mod <- list(syntax = structure(list(lhs = "x", op = "~", rhs = "y",
23 | free = TRUE, value = "", label = "",
24 | category = "", aspect = ""),
25 | class = "data.frame", row.names = c(NA, -1L)))
26 | class(mod) <- "tidy_sem"
27 | as_mplus(mod)
28 | }
29 |
--------------------------------------------------------------------------------
/man/as_ram.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/openmx_functions.R
3 | \name{as_ram}
4 | \alias{as_ram}
5 | \title{Convert lavaan syntax to RAM specification}
6 | \usage{
7 | as_ram(x, ...)
8 | }
9 | \arguments{
10 | \item{x}{An object for which a method exists, such as a \code{tidy_sem}
11 | object, or character vector describing the user-specified model using
12 | the lavaan model syntax.}
13 |
14 | \item{...}{Parameters passed on to other functions.}
15 | }
16 | \value{
17 | Returns an \code{\link[OpenMx]{mxModel}}.
18 | }
19 | \description{
20 | Converts SEM models to RAM models for
21 | \code{OpenMx}.
22 | }
23 | \details{
24 | For models specified using lavaan syntax, the procedure is as
25 | follows:
26 | \enumerate{
27 | \item Apply \code{\link[lavaan]{lavaanify}} to the \code{model}. The default
28 | arguments to \code{\link[lavaan]{lavaanify}} correspond to those of the
29 | \code{\link[lavaan]{sem}} function.
30 | \item Convert each row of the resulting lavaan parameter table to a
31 | \code{\link[OpenMx]{mxPath}}.
32 | \item Apply \code{\link[OpenMx]{mxModel}} to the \code{mxPath}s to create
33 | an \code{OpenMx} model using RAM specification
34 | }
35 | }
36 | \examples{
37 | as_ram("y ~ x")
38 | }
39 |
--------------------------------------------------------------------------------
/man/chisq_sb.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/motley_functions.R
3 | \name{chisq_sb}
4 | \alias{chisq_sb}
5 | \title{Satorra-Bentler corrected chi-square test}
6 | \usage{
7 | chisq_sb(chisq1, df1, scf1 = 1, chisq2, df2, scf2 = 1)
8 | }
9 | \arguments{
10 | \item{chisq1}{An object for which a method exists; e.g., a chi-square value,
11 | or a \code{data.frame}.}
12 |
13 | \item{df1}{Degrees of freedom of model 1.}
14 |
15 | \item{scf1}{Scale correction factor of model 1.}
16 |
17 | \item{chisq2}{Chi square value of model 2.}
18 |
19 | \item{df2}{Degrees of freedom of model 2.}
20 |
21 | \item{scf2}{Scale correction factor of model 2.}
22 | }
23 | \value{
24 | Chi-square difference value with corresponding degrees of freedom and
25 | p-value.
26 | }
27 | \description{
28 | Computes Satorra-Bentler corrected chi-square test.
29 | }
30 | \details{
31 | Reference:
32 | Satorra, A., & Bentler, P. M. (2001). A scaled difference chi-square test
33 | statistic for moment structure analysis. Psychometrika, 66(4), 507-514.
34 | \doi{10.1007/BF02296192}
35 | }
36 | \examples{
37 | df <- data.frame(chi2 = c(23, 44, 65), df = c(78, 74, 70), scf = c(1.02, 1.12, 1.28))
38 | chisq_sb(24, 78, 1.02, 65, 70, 1.28)
39 | }
40 | \author{
41 | Caspar J. van Lissa
42 | }
43 | \keyword{internal}
44 |
--------------------------------------------------------------------------------
/man/class_prob.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/mixture_summaries.R
3 | \name{class_prob}
4 | \alias{class_prob}
5 | \title{Obtain latent class probabilities}
6 | \usage{
7 | class_prob(
8 | x,
9 | type = c("sum.posterior", "sum.mostlikely", "mostlikely.class", "avg.mostlikely",
10 | "individual"),
11 | ...
12 | )
13 | }
14 | \arguments{
15 | \item{x}{An object for which a method exists.}
16 |
17 | \item{type}{Character vector, indicating which types of probabilities to
18 | extract. See Details.}
19 |
20 | \item{...}{Further arguments to be passed to or from other methods.}
21 | }
22 | \value{
23 | A data.frame.
24 | }
25 | \description{
26 | Obtain latent class probabilities for an object for which a
27 | method exists. See Details.
28 | }
29 | \details{
30 | The following types are available:
31 | \describe{
32 | \item{"sum.posterior"}{A summary table of the posterior class
33 | probabilities; this indicates what proportion of your data contributes to
34 | each class.}
35 | \item{"sum.mostlikely"}{A summary table of the most likely class
36 | membership, based on the highest posterior class probability. Note that
37 | this is subject to measurement error.}
38 | \item{"mostlikely.class"}{If C is the true class of an observation, and N is
39 | the most likely class based on the model, then this table shows the
40 | probability P(N==i|C==j). The diagonal represents the probability that
41 | observations in each class will be correctly classified.}
42 | \item{"avg.mostlikely"}{Average posterior probabilities for each class, for
43 | the subset of observations with most likely class of 1:k, where k is the
44 | number of classes.}
45 | \item{"individual"}{The posterior probability matrix, with dimensions n
46 | (number of cases in the data) x k (number of classes).}
47 | }
48 | }
49 | \examples{
50 | \dontrun{
51 | df <- iris[, 1, drop = FALSE]
52 | names(df) <- "x"
53 | res <- mx_mixture(model = "x ~ m{C}*1
54 | x ~~ v{C}*x", classes = 1, data = df)
55 | class_prob(res)
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/man/conf_int.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/results-table_results.R
3 | \name{conf_int}
4 | \alias{conf_int}
5 | \title{Format confidence intervals}
6 | \usage{
7 | conf_int(x, digits = 2, se = NULL, lb = NULL, ub = NULL, ci = 95)
8 | }
9 | \arguments{
10 | \item{x}{Optional. An object for which a method exists.}
11 |
12 | \item{digits}{Integer. The number of digits to round the confidence
13 | boundaries to.}
14 |
15 | \item{se}{Optional, numeric. Standard error of the parameters.}
16 |
17 | \item{lb}{Optional, numeric. Lower boundary of confidence intervals.}
18 |
19 | \item{ub}{Optional, numeric. Upper boundary of confidence intervals.}
20 |
21 | \item{ci}{Optional, numeric. What percentage CI to use (only used when
22 | computing CI from a numeric vector \code{x}, and the standard error
23 | \code{se}, based on a normal distribution).}
24 | }
25 | \value{
26 | A character vector of formatted confidence intervals.
27 | }
28 | \description{
29 | Creates 'APA'-formatted confidence intervals, either from an object for which
30 | a method exists, or from the arguments \code{lb} and \code{ub}. When argument
31 | \code{x} is a numeric vector, it is also possible to construct a confidence
32 | interval using the standard error (\code{se}) and a percentile interval
33 | (\code{ci}).
34 | }
35 | \examples{
36 | conf_int(x = c(1.325, 2.432), se = c(.05336, .00325))
37 | }
38 | \seealso{
39 | table_results est_sig
40 |
41 | Other Reporting tools:
42 | \code{\link{est_sig}()},
43 | \code{\link{table_fit}()},
44 | \code{\link{table_prob}()},
45 | \code{\link{table_results}()}
46 | }
47 | \author{
48 | Caspar J. van Lissa
49 | }
50 | \concept{Reporting tools}
51 |
--------------------------------------------------------------------------------
/man/cors.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/syntax-cors.R
3 | \name{cors}
4 | \alias{cors}
5 | \title{Generate syntax for correlations}
6 | \usage{
7 | cors(x, ...)
8 | }
9 | \arguments{
10 | \item{x}{Object for which a method exists. If \code{x} is an object of class
11 | \code{tidy_sem}, then correlations between all
12 | observed and latent variables in the data dictionary of that object are
13 | computed, by default. If
14 | \code{x} is a character vector, all elements of the vector are used.}
15 |
16 | \item{...}{Optional additional character vectors of variables to be
17 | correlated. If \code{x} is an object of class \code{tidy_sem}, then up to two
18 | vectors can be provided. If \code{x} is a
19 | vector, then one more optional vector can be provided.
20 | When no additional vectors of variable names are provided, only the
21 | correlations among the elements of \code{x} are returned.}
22 | }
23 | \value{
24 | An object of class \code{tidy_sem}.
25 | }
26 | \description{
27 | Generate syntax for correlations between variables.
28 | }
29 | \examples{
30 | dict <- tidy_sem(c("bfi_1", "bfi_2", "bfi_3", "bfi_4", "bfi_5"))
31 | cors(dict, c("bfi_1", "bfi_2"))
32 | }
33 |
--------------------------------------------------------------------------------
/man/curry_mac.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/data-mac.R
3 | \docType{data}
4 | \name{curry_mac}
5 | \alias{curry_mac}
6 | \title{Simulated MAC data}
7 | \format{
8 | A data.frame with 1392 rows and 42 variables.
9 | }
10 | \usage{
11 | data(curry_mac)
12 | }
13 | \description{
14 | This simulated dataset, based on Curry et al., 2019, contains data on moral
15 | relevance and judgment across the seven domains of the Morality As
16 | Cooperation scale.
17 | }
18 | \details{
19 | \tabular{lll}{
20 | \strong{sex} \tab \code{factor} \tab Self-identified sex of participants, Male, Female, or Transgendered.\cr
21 | \strong{age_years} \tab \code{numeric} \tab Participants' age in years.\cr
22 | \strong{KinshipR} \tab \code{numeric} \tab Mean score of moral relevance, kinship subscale.\cr
23 | \strong{MutualismR} \tab \code{numeric} \tab Mean score of moral relevance, mutualism subscale.\cr
24 | \strong{ExchangeR} \tab \code{numeric} \tab Mean score of moral relevance, exchange subscale.\cr
25 | \strong{HawkR} \tab \code{numeric} \tab Mean score of moral relevance, hawk subscale.\cr
26 | \strong{DoveR} \tab \code{numeric} \tab Mean score of moral relevance, dove subscale.\cr
27 | \strong{DivisionR} \tab \code{numeric} \tab Mean score of moral relevance, division subscale.\cr
28 | \strong{PossessionR} \tab \code{numeric} \tab Mean score of moral relevance, possession subscale.\cr
29 | \strong{KinshipJ} \tab \code{numeric} \tab Mean score of moral judgment, kinship subscale.\cr
30 | \strong{MutualismJ} \tab \code{numeric} \tab Mean score of moral judgment, mutualism subscale.\cr
31 | \strong{ExchangeJ} \tab \code{numeric} \tab Mean score of moral judgment, exchange subscale.\cr
32 | \strong{HawkJ} \tab \code{numeric} \tab Mean score of moral judgment, hawk subscale.\cr
33 | \strong{DoveJ} \tab \code{numeric} \tab Mean score of moral judgment, dove subscale.\cr
34 | \strong{DivisionJ} \tab \code{numeric} \tab Mean score of moral judgment, division subscale.\cr
35 | \strong{PossessionJ} \tab \code{numeric} \tab Mean score of moral judgment, possession subscale.
36 | }
37 | }
38 | \references{
39 | Curry, O. S., Jones Chesters, M., & Van Lissa, C. J. (2019). Mapping morality with a compass: Testing the theory of ‘morality-as-cooperation’ with a new questionnaire. Journal of Research in Personality, 78, 106–124.
40 | \doi{10.1016/j.jrp.2018.10.008}
41 | }
42 | \keyword{datasets}
43 |
--------------------------------------------------------------------------------
/man/data_mix_ordinal.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/data-data_mix_ordinal.R
3 | \docType{data}
4 | \name{data_mix_ordinal}
5 | \alias{data_mix_ordinal}
6 | \title{Simulated data for mixture model with ordinal indicators}
7 | \format{
8 | A data frame with 5000 rows and 4 variables.
9 | }
10 | \usage{
11 | data(data_mix_ordinal)
12 | }
13 | \description{
14 | This simulated dataset, based on the 'Mplus' User's Guide example 7.6,
15 | contains four columns of integer data that should be treated as ordinal.
16 | }
17 | \details{
18 | \tabular{lll}{
19 | \strong{u1} \tab \code{integer} \tab Indicator 1, should be treated as
20 | ordinal.\cr
21 | \strong{u2} \tab \code{integer} \tab Indicator 2, should be treated as
22 | ordinal.\cr
23 | \strong{u3} \tab \code{integer} \tab Indicator 3, should be treated as
24 | ordinal.\cr
25 | \strong{u4} \tab \code{integer} \tab Indicator 4, should be treated as
26 | ordinal.
27 | }
28 | }
29 | \references{
30 | Muthén, L.K. and Muthén, B.O. (1998-2017). Mplus User's Guide.
31 | Eighth Edition. Los Angeles, CA: Muthén & Muthén
32 | }
33 | \keyword{datasets}
34 |
--------------------------------------------------------------------------------
/man/dictionary.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/syntax-attributes.R
3 | \name{dictionary}
4 | \alias{dictionary}
5 | \alias{dictionary<-}
6 | \title{Extract dictionary from tidy_sem}
7 | \usage{
8 | dictionary(x)
9 |
10 | dictionary(x) <- value
11 | }
12 | \arguments{
13 | \item{x}{Object of class tidy_sem.}
14 |
15 | \item{value}{A valid value for \code{dictionary(x)}.}
16 | }
17 | \value{
18 | data.frame
19 | }
20 | \description{
21 | Provides access to the \code{dictionary} element of a
22 | \code{tidy_sem} object. This can be used to return or assign to the
23 | \code{dictionary} element.
24 | }
25 | \examples{
26 | dict <- tidy_sem(iris, split = "\\\\.")
27 | dictionary(dict)
28 | }
29 |
--------------------------------------------------------------------------------
/man/edges.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/plot-attributes.R
3 | \name{edges}
4 | \alias{edges}
5 | \alias{edges<-}
6 | \title{Extract edges from sem_graph}
7 | \usage{
8 | edges(x)
9 |
10 | edges(x) <- value
11 | }
12 | \arguments{
13 | \item{x}{Object of class sem_graph.}
14 |
15 | \item{value}{A valid value for \code{edges(x)}.}
16 | }
17 | \value{
18 | data.frame
19 | }
20 | \description{
21 | Provides access to the \code{edges} element of a
22 | \code{sem_graph} object. This can be used to return or assign to the
23 | \code{edges} element.
24 | }
25 | \examples{
26 | edg <- data.frame(from = "x", to = "y")
27 | p <- prepare_graph(edges = edg, layout = get_layout("x", "y", rows = 1))
28 | edges(p)
29 | }
30 |
--------------------------------------------------------------------------------
/man/edit_graph.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/plot-plot_sem.R
3 | \name{edit_graph}
4 | \alias{edit_graph}
5 | \alias{edit_nodes}
6 | \alias{edit_edges}
7 | \title{Edit graph elements}
8 | \usage{
9 | edit_graph(x, expr, element = c("edges", "nodes"), ...)
10 |
11 | edit_nodes(x, expr, ...)
12 |
13 | edit_edges(x, expr, ...)
14 | }
15 | \arguments{
16 | \item{x}{An object of class \code{sem_graph}.}
17 |
18 | \item{expr}{expression to evaluate.}
19 |
20 | \item{element}{Character. The element of the \code{sem_graph} to edit,
21 | defaults to \code{c("edges", "nodes")}.}
22 |
23 | \item{...}{Arguments passed on to \code{\link{within}}.}
24 | }
25 | \value{
26 | An object of class \code{sem_graph}.
27 | }
28 | \description{
29 | Evaluate an R expression within the environment of the elements
30 | of a \code{sem_graph} object, and return the modified \code{sem_graph}.
31 | }
32 | \examples{
33 | p <- prepare_graph(layout = get_layout("x", rows = 1))
34 | p <- edit_graph(p, {colour = "blue"}, element = "nodes")
35 | plot(p)
36 | }
37 |
--------------------------------------------------------------------------------
/man/empathy.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/empathy.R
3 | \docType{data}
4 | \name{empathy}
5 | \alias{empathy}
6 | \title{Simulated empathy data}
7 | \format{
8 | A data frame with 467 rows and 13 variables.
9 | }
10 | \usage{
11 | data(empathy)
12 | }
13 | \description{
14 | This simulated dataset, based on Van Lissa et al., 2014, contains six annual
15 | assessments of adolescents' mean scores on the empathic concern and
16 | perspective taking subscales of the Interpersonal Reactivity Index
17 | (Davis, 1983). The first measurement wave occurred when adolescents were, on
18 | average, 13 years old, and the last one when they were 18 years old.
19 | }
20 | \details{
21 | \tabular{lll}{
22 | \strong{ec1} \tab \code{numeric} \tab Mean score of empathic concern in
23 | wave 1\cr
24 | \strong{ec2} \tab \code{numeric} \tab Mean score of empathic concern in
25 | wave 2\cr
26 | \strong{ec3} \tab \code{numeric} \tab Mean score of empathic concern in
27 | wave 3\cr
28 | \strong{ec4} \tab \code{numeric} \tab Mean score of empathic concern in
29 | wave 4\cr
30 | \strong{ec5} \tab \code{numeric} \tab Mean score of empathic concern in
31 | wave 5\cr
32 | \strong{ec6} \tab \code{numeric} \tab Mean score of empathic concern in
33 | wave 6\cr
34 | \strong{pt1} \tab \code{numeric} \tab Mean score of perspective taking in
35 | wave 1\cr
36 | \strong{pt2} \tab \code{numeric} \tab Mean score of perspective taking in
37 | wave 2\cr
38 | \strong{pt3} \tab \code{numeric} \tab Mean score of perspective taking in
39 | wave 3\cr
40 | \strong{pt4} \tab \code{numeric} \tab Mean score of perspective taking in
41 | wave 4\cr
42 | \strong{pt5} \tab \code{numeric} \tab Mean score of perspective taking in
43 | wave 5\cr
44 | \strong{pt6} \tab \code{numeric} \tab Mean score of perspective taking in
45 | wave 6\cr
46 | \strong{sex} \tab \code{factor} \tab Adolescent sex; M = male, F = female.
47 | }
48 | }
49 | \references{
50 | Van Lissa, C. J., Hawk, S. T., Branje, S. J., Koot, H. M.,
51 | Van Lier, P. A., & Meeus, W. H. (2014). Divergence Between Adolescent and
52 | Parental Perceptions of Conflict in Relationship to Adolescent Empathy
53 | Development. Journal of Youth and Adolescence, (Journal Article), 1–14.
54 | \doi{10.1007/s10964-014-0152-5}
55 | }
56 | \keyword{datasets}
57 |
--------------------------------------------------------------------------------
/man/est_sig.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/results-table_results.R
3 | \name{est_sig}
4 | \alias{est_sig}
5 | \title{Add significance asterisks to object}
6 | \usage{
7 | est_sig(x, digits = 2, sig = NULL)
8 | }
9 | \arguments{
10 | \item{x}{An object for which a method exists. This will be treated as numeric
11 | by the default method.}
12 |
13 | \item{digits}{Integer. The number of digits to round the estimate column to.}
14 |
15 | \item{sig}{Optional, a vector of p-values for the default method.}
16 | }
17 | \value{
18 | A character vector of formatted estimates.
19 | }
20 | \description{
21 | Takes an object, and adds significance asterisks.
22 | }
23 | \examples{
24 | est_sig(c(.222, .3333), sig = c(.054, .045))
25 | }
26 | \seealso{
27 | table_results
28 |
29 | Other Reporting tools:
30 | \code{\link{conf_int}()},
31 | \code{\link{table_fit}()},
32 | \code{\link{table_prob}()},
33 | \code{\link{table_results}()}
34 | }
35 | \author{
36 | Caspar J. van Lissa
37 | }
38 | \concept{Reporting tools}
39 |
--------------------------------------------------------------------------------
/man/estimate_lavaan.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/syntax-estimate.R
3 | \name{estimate_lavaan}
4 | \alias{estimate_lavaan}
5 | \title{Estimate tidy_sem using 'lavaan'}
6 | \usage{
7 | estimate_lavaan(x, func = "sem", ...)
8 | }
9 | \arguments{
10 | \item{x}{An object of class \code{tidy_sem}.}
11 |
12 | \item{func}{The \code{\link[lavaan]{lavaan}} modeling function to invoke,
13 | Default: 'sem'.}
14 |
15 | \item{...}{Additional parameters passed to the estimating function.}
16 | }
17 | \value{
18 | An object of class \code{lavaan}.
19 | }
20 | \description{
21 | This function is a wrapper for the \code{\link[lavaan]{lavaan}}
22 | estimating functions. By default, the wrapper uses \code{\link[lavaan]{sem}},
23 | but users can also specify \code{\link[lavaan]{lavaan}},
24 | \code{\link[lavaan]{cfa}}, or \code{\link[lavaan]{growth}}.
25 | }
26 | \examples{
27 | library(lavaan)
28 | model <- tidy_sem(iris, "\\\\.")
29 | model <- measurement(model)
30 | res <- estimate_lavaan(model)
31 | summary(res)
32 | }
33 |
--------------------------------------------------------------------------------
/man/estimate_mplus.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/syntax-estimate.R
3 | \name{estimate_mplus}
4 | \alias{estimate_mplus}
5 | \title{Estimate tidy_sem using 'Mplus'}
6 | \usage{
7 | estimate_mplus(x, ...)
8 | }
9 | \arguments{
10 | \item{x}{An object of class \code{tidy_sem}.}
11 |
12 | \item{...}{Additional parameters passed to
13 | \code{\link[MplusAutomation]{mplusObject}} and
14 | \code{\link[MplusAutomation]{mplusModeler}}. These arguments are matched to
15 | the correct function by name. The arguments \code{rdata}, and \code{MODEL}
16 | cannot be edited, as they are determined from the \code{tidy_sem} object.}
17 | }
18 | \value{
19 | An object of class \code{mplusObject}.
20 | }
21 | \description{
22 | This function is a wrapper for the functions
23 | \code{\link[MplusAutomation]{mplusObject}} and
24 | \code{\link[MplusAutomation]{mplusModeler}}. Using this function requires
25 | 'Mplus' to be installed.
26 | }
27 | \details{
28 | The arguments \code{dataout}, \code{modelout}, and \code{run} are
29 | optional. If these are not specified, the model will be run in
30 | \code{\link{tempdir}}.
31 | }
32 | \examples{
33 | library(MplusAutomation)
34 | model <- tidy_sem(iris, "\\\\.")
35 | model <- measurement(model)
36 | \dontrun{
37 | estimate_mplus(model, run = 0L)
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/man/estimate_mx.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/syntax-estimate.R
3 | \name{estimate_mx}
4 | \alias{estimate_mx}
5 | \title{Estimate tidy_sem using 'OpenMx'}
6 | \usage{
7 | estimate_mx(x, ...)
8 | }
9 | \arguments{
10 | \item{x}{An object of class \code{tidy_sem}.}
11 |
12 | \item{...}{Additional parameters passed to the estimating function.}
13 | }
14 | \value{
15 | An object of class \code{MxModel}.
16 | }
17 | \description{
18 | This function is a wrapper for the \code{\link{as_ram}}
19 | and \code{\link{run_mx}} functions.
20 | }
21 | \examples{
22 | df <- iris[1:4]
23 | names(df) <- paste0("x_", 1:4)
24 | model <- tidy_sem(df)
25 | model <- measurement(model)
26 | res <- estimate_mx(model)
27 | summary(res)
28 | }
29 |
--------------------------------------------------------------------------------
/man/get_data.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/syntax-attributes.R
3 | \name{get_data}
4 | \alias{get_data}
5 | \alias{get_data<-}
6 | \title{Extract data from tidy_sem}
7 | \usage{
8 | get_data(x)
9 |
10 | get_data(x) <- value
11 | }
12 | \arguments{
13 | \item{x}{Object of class tidy_sem.}
14 |
15 | \item{value}{A valid value for \code{get_data(x)}.}
16 | }
17 | \value{
18 | data.frame
19 | }
20 | \description{
21 | Provides access to the \code{data} element of a
22 | \code{tidy_sem} object. This can be used to return or assign to the
23 | \code{data} element.
24 | }
25 | \examples{
26 | dict <- tidy_sem(iris, split = "\\\\.")
27 | get_data(dict)
28 | }
29 |
--------------------------------------------------------------------------------
/man/get_fit.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/mixture_summaries.R
3 | \name{get_fit}
4 | \alias{get_fit}
5 | \title{Get fit indices from objects}
6 | \usage{
7 | get_fit(x, ...)
8 | }
9 | \arguments{
10 | \item{x}{An object for which a method exists.}
11 |
12 | \item{...}{further arguments to be passed to or from other methods.}
13 | }
14 | \value{
15 | A data.frame.
16 | }
17 | \description{
18 | Get fit indices from objects for which a method exists.
19 | }
20 | \examples{
21 | \dontrun{
22 | df <- iris[, 1, drop = FALSE]
23 | names(df) <- "x"
24 | res <- mx_mixture(model = "x ~ m{C}*1
25 | x ~~ v{C}*x", classes = 1, data = df)
26 | table_fit(res)
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/man/ic_weights.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/ic_weights.R
3 | \name{ic_weights}
4 | \alias{ic_weights}
5 | \title{Compare Information Criteria}
6 | \usage{
7 | ic_weights(x, ...)
8 | }
9 | \arguments{
10 | \item{x}{An object for which a method exists.}
11 |
12 | \item{...}{Additional arguments.}
13 | }
14 | \value{
15 | A \code{list} of class \code{ic_weights} with elements \verb{$weights}, which
16 | contains the model weights, and \verb{$comparison}, which contains the relative
17 | support in favor of each model over the others.
18 | }
19 | \description{
20 | IC weights quantify the evidence in favor of different models in a set.
21 | This function normalizes the IC values to obtain IC weights, which sum to 1.
22 | The model with the highest weight is most supported by the data.
23 | The ratio of different weights gives the relative support in favor of one
24 | model over another.
25 | }
26 | \examples{
27 | ics <- c(100, 200, 102, 300)
28 | ic_weights(ics)
29 | }
30 | \references{
31 | Wagenmakers, E. J., & Farrell, S. (2004). AIC model selection
32 | using Akaike weights. Psychonomic bulletin & review, 11(1), 192-196.
33 | \doi{10.3758/BF03206482}
34 | }
35 |
--------------------------------------------------------------------------------
/man/lr_lmr.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/lr_vml.R
3 | \name{lr_lmr}
4 | \alias{lr_lmr}
5 | \title{Lo-Mendell-Rubin Likelihood Ratio Test}
6 | \usage{
7 | lr_lmr(x, ...)
8 | }
9 | \arguments{
10 | \item{x}{An object for which a method exists.}
11 |
12 | \item{...}{Additional arguments.}
13 | }
14 | \value{
15 | A \code{data.frame} containing the Z-value for the likelihood ratio test,
16 | its p-value, df (which indicates the difference in number of parameters, not
17 | true degrees of freedom, which may be zero), w2 (omega squared) statistic for
18 | the test of distinguishability, an its p-value.
19 | }
20 | \description{
21 | A likelihood ratio test for class enumeration in latent class
22 | analysis, proposed by Lo, Mendell, & Rubin (2001) based on work by Vuong
23 | (1989). See Details for important clarification.
24 | }
25 | \details{
26 | The likelihood ratio test for non-nested models, based on
27 | work by Vuong (1989), is often used for class enumeration in latent class
28 | analysis (see Lo, Mendell, & Rubin, 2001). Following work by Merkle,
29 | You, & Preacher (2016), the models to be compared must first be tested for
30 | distinguishability in the population, using the \code{w2} test. The null
31 | hypothesis is that the models are indistinguishable. If this null hypothesis
32 | is not rejected, there is no point in statistical model comparison, either
33 | using the LMR LRT or other statistics. If the null hypothesis is rejected,
34 | the LMR LRT can be evaluated using a Z-test. This function wraps
35 | \verb{\link[nonnest2]\{vuongtest\}} to perform that test.
36 | }
37 | \examples{
38 | if(requireNamespace("OpenMx", quietly = TRUE)){
39 | df <- iris[c(1:5, 100:105), 1:3]
40 | names(df) <- letters[1:3]
41 | res <- mx_profiles(df, classes = 1:2)
42 | lr_lmr(res)
43 | }
44 | }
45 | \references{
46 | Lo Y, Mendell NR, Rubin DB. Testing the number of components in a
47 | normal mixture. Biometrika. 2001;88(3):767–778.
48 | \doi{10.1093/biomet/88.3.767}
49 |
50 | Vuong, Q. H. (1989). Likelihood ratio tests for model selection
51 | and non-nested hypotheses. Econometrica, 57, 307-333. \doi{10.2307/1912557}
52 |
53 | Merkle, E. C., You, D., & Preacher, K. (2016). Testing non-nested
54 | structural equation models. Psychological Methods, 21, 151-163.
55 | \doi{10.1037/met0000038}
56 | }
57 |
--------------------------------------------------------------------------------
/man/lr_test.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/mixture-3step.R
3 | \name{lr_test}
4 | \alias{lr_test}
5 | \title{Conduct Likelihood Ratio tests}
6 | \usage{
7 | lr_test(x, compare = c("All", "A", "S", "F", "M", "Thresholds"), ...)
8 | }
9 | \arguments{
10 | \item{x}{An object for which a method exists.}
11 |
12 | \item{compare}{Character vector, indicating which matrices to constrain to be
13 | equal in pairwise comparisons.}
14 |
15 | \item{...}{Additional arguments passed to other functions.}
16 | }
17 | \value{
18 | An object of class \code{lr_test} and \code{list}.
19 | }
20 | \description{
21 | For a multigroup model of class \code{MxModel},
22 | conduct overall and pairwise likelihood ratio tests.
23 | All submodels must be identical.
24 | }
25 | \examples{
26 | if(requireNamespace("OpenMx", quietly = TRUE)){
27 | df <- iris[c(1:10, 140:150), c(1, 5)]
28 | names(df) <- c("x", "group")
29 | mod <- as_ram("x~1", data = df, group = "group")
30 | mod <- run_mx(mod)
31 | lr_test(mod)
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/man/lsub.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/openmx_functions.R
3 | \name{lsub}
4 | \alias{lsub}
5 | \title{Apply pattern replacement over a vector}
6 | \usage{
7 | lsub(x, replacement = NULL, pattern = "{C}", fixed = TRUE, ...)
8 | }
9 | \arguments{
10 | \item{x}{A character vector where matches are sought.}
11 |
12 | \item{replacement}{a character vector of length 1 or more. Each element is
13 | applied to \code{x} in turn. Default: NULL}
14 |
15 | \item{pattern}{A character string containing a regular expression (or
16 | character string when \code{fixed = TRUE}). Default: \code{'{C}'}.}
17 |
18 | \item{fixed}{logical. If TRUE, pattern is a string to be matched as is.
19 | Default: TRUE}
20 |
21 | \item{...}{Parameters passed on to \code{\link[base:grep]{gsub}}.}
22 | }
23 | \value{
24 | A list of results returned by \code{\link[base:grep]{gsub}}.
25 | }
26 | \description{
27 | \code{lsub} returns a list of the same length as
28 | \code{replacement}, each element of which is the result of applying
29 | \code{\link[base:grep]{gsub}} to \code{x} using \code{\link{lapply}}.
30 | }
31 | \examples{
32 | lsub("a{C}", 1:3)
33 | }
34 |
--------------------------------------------------------------------------------
/man/measurement.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/syntax-cfa.R
3 | \name{measurement}
4 | \alias{measurement}
5 | \title{Generate syntax for a measurement model}
6 | \usage{
7 | measurement(x, ...)
8 | }
9 | \arguments{
10 | \item{x}{An object for which a method exists, including \code{tidy_sem}
11 | (generated using \code{\link[tidySEM]{dictionary}}, or \code{data.frame} (for
12 | which \code{\link[tidySEM]{dictionary}} will be run first).}
13 |
14 | \item{...}{Additional parameters passed to \code{\link{add_paths}}.}
15 | }
16 | \value{
17 | An object of class \code{tidy_sem}.
18 | }
19 | \description{
20 | Generate syntax for a measurement model for latent variables.
21 | This function relies on \code{\link{add_paths}} to generate syntax.
22 | }
23 | \examples{
24 | dict <- tidy_sem(c("bfi_1", "bfi_2", "bfi_3", "bfi_4", "bfi_5"))
25 | measurement(dict)
26 | }
27 |
--------------------------------------------------------------------------------
/man/mplus_expand_names.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/utilities.R
3 | \name{mplus_expand_names}
4 | \alias{mplus_expand_names}
5 | \title{Expand abbreviated Mplus variable names}
6 | \usage{
7 | mplus_expand_names(x)
8 | }
9 | \arguments{
10 | \item{x}{Atomic character string containing the variable names section of an
11 | Mplus syntax file.}
12 | }
13 | \value{
14 | Character vector of names.
15 | }
16 | \description{
17 | Expand the Mplus syntax for abbreviating lists of variable
18 | names.
19 | }
20 | \examples{
21 | mplus_expand_names("test1-test12")
22 | mplus_expand_names("testa-testb")
23 | }
24 | \keyword{mplus}
25 | \keyword{utilities}
26 |
--------------------------------------------------------------------------------
/man/mx_dummies.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/mx_dummies.R
3 | \name{mx_dummies}
4 | \alias{mx_dummies}
5 | \title{Dummy Code Factor Variables}
6 | \usage{
7 | mx_dummies(x, classes = c("factor", "character"), ...)
8 | }
9 | \arguments{
10 | \item{x}{An object for which a method exists.}
11 |
12 | \item{classes}{Character vector, indicating which classes to dummy code.
13 | Defaults to \code{c("factor", "character")}.}
14 |
15 | \item{...}{Arguments}
16 | }
17 | \value{
18 | A \code{data.frame}.
19 | }
20 | \description{
21 | For each variable \emph{v} that inherits
22 | \code{factor}, create a number of new variables equal
23 | to \code{levels(v)} to indicate group membership (1)
24 | or non-membership (0) of that level.
25 | The resulting dummies have class \code{mxFactor}.
26 | }
27 | \examples{
28 | if(requireNamespace("OpenMx", quietly = TRUE)){
29 | mx_dummies(iris[1:5,])
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/man/mx_lca.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/mx_mixture.R
3 | \name{mx_lca}
4 | \alias{mx_lca}
5 | \title{Estimate latent class analyses using OpenMx}
6 | \usage{
7 | mx_lca(data = NULL, classes = 1L, run = TRUE, ...)
8 | }
9 | \arguments{
10 | \item{data}{The data.frame to be used for model fitting.}
11 |
12 | \item{classes}{A vector of integers, indicating which class solutions to
13 | generate. Defaults to 1L. E.g., \code{classes = 1:6},}
14 |
15 | \item{run}{Logical, whether or not to run the model. If \code{run = TRUE},
16 | the function calls \code{\link[OpenMx:mxTryHardOrdinal]{OpenMx::mxTryHardOrdinal()}}.}
17 |
18 | \item{...}{Additional arguments, passed to functions.}
19 | }
20 | \value{
21 | Returns an \code{\link[OpenMx:mxModel]{OpenMx::mxModel()}}.
22 | }
23 | \description{
24 | This function simplifies the specification of latent class models:
25 | models that estimate membership of a categorical latent variable based on
26 | binary or ordinal indicators.
27 | }
28 | \examples{
29 | \dontrun{
30 | df <- data_mix_ordinal
31 | df[1:4] <- lapply(df, ordered)
32 | mx_lca(data = df,
33 | classes = 2) -> res
34 | }
35 | }
36 | \references{
37 | Van Lissa, C. J., Garnier-Villarreal, M., & Anadria, D. (2023).
38 | Recommended Practices in Latent Class Analysis using the Open-Source
39 | R-Package tidySEM. Structural Equation Modeling.
40 | \doi{10.1080/10705511.2023.2250920}
41 | }
42 | \keyword{mixture}
43 | \keyword{models}
44 | \keyword{openmx}
45 |
--------------------------------------------------------------------------------
/man/mx_switch_labels.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/mx_switch_labels.R
3 | \name{mx_switch_labels}
4 | \alias{mx_switch_labels}
5 | \title{Switch LCA Class Labels}
6 | \usage{
7 | mx_switch_labels(x, param = "weights", decreasing = TRUE, order = NULL)
8 | }
9 | \arguments{
10 | \item{x}{An \code{MxModel} estimated by \code{mx_mixture} or one of its wrappers.}
11 |
12 | \item{param}{The parameter by which to order the classes,
13 | defaults to \code{'weights'}, which orders classes based on their sample size.}
14 |
15 | \item{decreasing}{logical. Should the classes be sorted in increasing
16 | or decreasing order? Default: TRUE}
17 |
18 | \item{order}{Integer, indicating the ordering of classes. Ignored
19 | when NULL (default).}
20 | }
21 | \value{
22 | An \code{MxModel} with \code{"tidySEM"} attribute: \code{"mixture"}
23 | }
24 | \description{
25 | The order of class labels in LCA is arbitrary. This can
26 | result in a phenomenon called 'label switching', where classes change
27 | places between replications of an analysis. This function attempts to
28 | re-order classes in a substantively meaningful way.
29 | }
30 | \details{
31 | The argument \code{param} can accept either:
32 | \enumerate{
33 | \item The default string "weights", in which classes are sorted by size.
34 | \item The \code{OpenMx} matrix indicator for a specific model parameter; e.g.,
35 | the first mean is indicated by \code{"M[1,1]"}. These indicators can be viewed
36 | by running \code{table_results(x, columns = NULL)}.
37 | \item The letter indicating an \code{OpenMx} model matrix, e.g., \code{"M"} refers to
38 | the matrix of means. To account for all elements of the matrix, Euclidean
39 | distance to the origin is used.
40 | }
41 | }
42 | \examples{
43 | \dontrun{
44 | df <- iris[1:4]
45 | names(df) <- letters[1:4]
46 | res1 <- mx_profiles(data = df, classes = 2)
47 | mx_switch_labels(res1, decreasing = FALSE)
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/man/nodes.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/plot-attributes.R
3 | \name{nodes}
4 | \alias{nodes}
5 | \alias{nodes<-}
6 | \title{Extract nodes from sem_graph}
7 | \usage{
8 | nodes(x)
9 |
10 | nodes(x) <- value
11 | }
12 | \arguments{
13 | \item{x}{Object of class sem_graph.}
14 |
15 | \item{value}{A valid value for \code{nodes(x)}.}
16 | }
17 | \value{
18 | data.frame
19 | }
20 | \description{
21 | Provides access to the \code{nodes} element of a
22 | \code{sem_graph} object. This can be used to return or assign to the
23 | \code{nodes} element.
24 | }
25 | \examples{
26 | edg <- data.frame(from = "x", to = "y")
27 | p <- prepare_graph(edges = edg, layout = get_layout("x", "y", rows = 1))
28 | nodes(p)
29 | }
30 |
--------------------------------------------------------------------------------
/man/paste2.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/utilities.R
3 | \name{paste2}
4 | \alias{paste2}
5 | \title{Concatenate Strings while omitting NA}
6 | \usage{
7 | paste2(..., sep = " ", collapse = NULL, na.rm = TRUE)
8 | }
9 | \arguments{
10 | \item{...}{one or more R objects, to be converted to character vectors.}
11 |
12 | \item{sep}{a character string to separate the terms.
13 | Not \code{NA_character_}.}
14 |
15 | \item{collapse}{an optional character string to separate the results.
16 | Not \code{NA_character_}.}
17 |
18 | \item{na.rm}{logical, indicating whether \code{NA} values should be stripped
19 | before concatenation.
20 | Not \code{NA_character_}.}
21 | }
22 | \value{
23 | A character vector of the concatenated values.
24 | }
25 | \description{
26 | Concatenate vectors after converting to character and removing
27 | \code{NA} values. See \code{\link{paste}}.
28 | }
29 | \examples{
30 | paste2("word", NA)
31 | }
32 |
--------------------------------------------------------------------------------
/man/plas_depression.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/plas_depression.R
3 | \docType{data}
4 | \name{plas_depression}
5 | \alias{plas_depression}
6 | \title{Simulated depression data}
7 | \format{
8 | A data frame with 978 rows and 6 variables.
9 | }
10 | \usage{
11 | data(plas_depression)
12 | }
13 | \description{
14 | This simulated dataset, based on work
15 | in progress by Plas and colleagues,
16 | contains six repeated measurements
17 | of the Depression subscale of the
18 | Symptom Checklist-90 (SCL-90).
19 | }
20 | \details{
21 | These data are inspired by the
22 | \emph{Prospection in Stress-related Military Research (PRISMO)} study,
23 | which examined of psychological problems
24 | after deployment in more than 1,000 Dutch
25 | military personnel who were deployed to Afghanistan, from 2005-2019.
26 |
27 | \tabular{lll}{
28 | \strong{scl.1} \tab \code{integer} \tab Sum score of SCL90 depression pre-deployment\cr
29 | \strong{scl.2} \tab \code{integer} \tab Sum score of SCL90 depression 1 month post-deployment\cr
30 | \strong{scl.3} \tab \code{integer} \tab Sum score of SCL90 depression 6 months post-deployment\cr
31 | \strong{scl.4} \tab \code{integer} \tab Sum score of SCL90 depression 1 year post-deployment\cr
32 | \strong{scl.5} \tab \code{integer} \tab Sum score of SCL90 depression 2 years post-deployment\cr
33 | \strong{scl.6} \tab \code{integer} \tab Sum score of SCL90 depression 10 years post-deployment
34 | }
35 | }
36 | \references{
37 | van der Wal, S. J., Gorter, R., Reijnen, A., Geuze, E., & Vermetten, E. (2019). Cohort profile: The Prospective Research In Stress-Related Military Operations (PRISMO) study in the Dutch Armed Forces. BMJ Open, 9(3), e026670.
38 | \doi{10.1136/bmjopen-2018-026670}
39 | }
40 | \keyword{datasets}
41 |
--------------------------------------------------------------------------------
/man/plot_bivariate.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/plot-bivariate.R
3 | \name{plot_bivariate}
4 | \alias{plot_bivariate}
5 | \title{Create correlation plots for a mixture model}
6 | \usage{
7 | plot_bivariate(
8 | x,
9 | variables = NULL,
10 | sd = TRUE,
11 | cors = TRUE,
12 | rawdata = TRUE,
13 | bw = FALSE,
14 | alpha_range = c(0, 0.1),
15 | return_list = FALSE,
16 | ...
17 | )
18 | }
19 | \arguments{
20 | \item{x}{An object for which a method exists.}
21 |
22 | \item{variables}{Which variables to plot. If NULL, plots all variables that
23 | are present in the model.}
24 |
25 | \item{sd}{Logical. Whether to show the estimated standard deviations as lines
26 | emanating from the cluster centroid.}
27 |
28 | \item{cors}{Logical. Whether to show the estimated correlation (standardized
29 | covariance) as ellipses surrounding the cluster centroid.}
30 |
31 | \item{rawdata}{Logical. Whether to plot raw data, weighted by posterior class
32 | probability.}
33 |
34 | \item{bw}{Logical. Whether to make a black and white plot (for print) or a
35 | color plot. Defaults to FALSE, because these density plots are hard to read
36 | in black and white.}
37 |
38 | \item{alpha_range}{Numeric vector (0-1). Sets
39 | the transparency of geom_density and geom_point.}
40 |
41 | \item{return_list}{Logical. Whether to return a list of ggplot objects, or
42 | just the final plot. Defaults to FALSE.}
43 |
44 | \item{...}{Additional arguments.}
45 | }
46 | \value{
47 | An object of class 'ggplot'.
48 | }
49 | \description{
50 | Creates a faceted plot of two-dimensional correlation plots and
51 | unidimensional density plots for a single mixture model.
52 | }
53 | \examples{
54 | if(requireNamespace("OpenMx", quietly = TRUE)){
55 | iris_sample <- iris[c(1:5, 145:150), c("Sepal.Length", "Sepal.Width")]
56 | names(iris_sample) <- c("x", "y")
57 | res <- mx_profiles(iris_sample, classes = 2)
58 | plot_bivariate(res, rawdata = FALSE)
59 | }
60 | }
61 | \author{
62 | Caspar J. van Lissa
63 | }
64 | \keyword{correlation}
65 | \keyword{mixture}
66 | \keyword{plot}
67 |
--------------------------------------------------------------------------------
/man/plot_density.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/plot-mixture_densities.R
3 | \name{plot_density}
4 | \alias{plot_density}
5 | \title{Create density plots for mixture models}
6 | \usage{
7 | plot_density(
8 | x,
9 | variables = NULL,
10 | bw = FALSE,
11 | conditional = FALSE,
12 | alpha = 0.2,
13 | facet_labels = NULL
14 | )
15 | }
16 | \arguments{
17 | \item{x}{Object for which a method exists.}
18 |
19 | \item{variables}{Which variables to plot. If NULL, plots all variables that
20 | are present in all models.}
21 |
22 | \item{bw}{Logical. Whether to make a black and white plot (for print) or a
23 | color plot. Defaults to FALSE, because these density plots are hard to read
24 | in black and white.}
25 |
26 | \item{conditional}{Logical. Whether to show a conditional density plot
27 | (surface area is divided among the latent classes), or a classic density
28 | plot (surface area of the total density plot is equal to one, and is
29 | divided among the classes).}
30 |
31 | \item{alpha}{Numeric (0-1). Only used when bw and conditional are FALSE. Sets
32 | the transparency of geom_density, so that classes with a small number of
33 | cases remain visible.}
34 |
35 | \item{facet_labels}{Named character vector, the names of which should
36 | correspond to the facet labels one wishes to rename, and the values of which
37 | provide new names for these facets. For example, to rename variables, in the
38 | example with the 'iris' data below, one could specify:
39 | \code{facet_labels = c("Pet_leng" = "Petal length")}.}
40 | }
41 | \value{
42 | An object of class 'ggplot'.
43 | }
44 | \description{
45 | Creates mixture density plots. For
46 | each variable, a Total density plot will be shown, along with separate
47 | density plots for each latent class, where cases are weighted by the
48 | posterior probability of being assigned to that class.
49 | }
50 | \examples{
51 | \dontrun{
52 | dat <-
53 | iris[, c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")]
54 | names(dat) <- paste0("x", 1:4)
55 | res <- mx_profiles(dat, 1:3)
56 | plot_density(res)
57 | }
58 | }
59 | \author{
60 | Caspar J. van Lissa
61 | }
62 | \keyword{density}
63 | \keyword{mixture}
64 | \keyword{plot}
65 |
--------------------------------------------------------------------------------
/man/plot_prob.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/plot-thresholds.R
3 | \name{plot_prob}
4 | \alias{plot_prob}
5 | \title{Plot categorical variable probabilities}
6 | \usage{
7 | plot_prob(
8 | x,
9 | variables = NULL,
10 | bars = c("Variable", "group", "class"),
11 | facet = c("group", "class", "Variable"),
12 | bw = FALSE,
13 | ...
14 | )
15 | }
16 | \arguments{
17 | \item{x}{An object for which a method exists}
18 |
19 | \item{variables}{A character vectors with the names of the variables to be
20 | plotted (optional).}
21 |
22 | \item{bars}{Atomic character, indicating what separate bars represent. One of
23 | \code{c("Variable", "group", "class")}.}
24 |
25 | \item{facet}{Atomic character, indicating what separate facets represent. One
26 | of \code{c("group", "class", "Variable")}.}
27 |
28 | \item{bw}{Logical. Should the plot be black and white (for print), or color?}
29 |
30 | \item{...}{Arguments passed to and from other functions.}
31 | }
32 | \value{
33 | An object of class 'ggplot'.
34 | }
35 | \description{
36 | Creates a bar chart of categorical variable probabilities with bars
37 | reflecting the probability of category membership for each category of the
38 | observed variable.
39 | }
40 | \examples{
41 | df_plot <- data.frame(Variable = rep(c("u1", "u2"), each = 3),
42 | Category = rep(1:3, 2),
43 | Probability = c(0.3381302605812, 0.148395173612088, 0.513474565806711,
44 | 0.472337708760608, 0.118484201496432, 0.40917808974296))
45 | plot_prob(df_plot)
46 | }
47 | \author{
48 | Caspar J. van Lissa
49 | }
50 | \keyword{mixture}
51 | \keyword{plot}
52 |
--------------------------------------------------------------------------------
/man/poms.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/motley_functions.R
3 | \name{poms}
4 | \alias{poms}
5 | \title{Apply POMS-coding to data}
6 | \usage{
7 | poms(data)
8 | }
9 | \arguments{
10 | \item{data}{A data.frame.}
11 | }
12 | \value{
13 | A data.frame.
14 | }
15 | \description{
16 | Takes in a data.frame, and applies POMS (proportion of of maximum)-coding to
17 | the numeric columns.
18 | }
19 | \examples{
20 | data <- data.frame(a = c(1, 2, 2, 4, 1, 6),
21 | b = c(6, 6, 3, 5, 3, 4),
22 | c = c("a", "b", "b", "t", "f", "g"))
23 | poms(data)
24 | }
25 | \author{
26 | Caspar J. van Lissa
27 | }
28 | \keyword{internal}
29 |
--------------------------------------------------------------------------------
/man/report.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/motley_functions.R
3 | \name{report}
4 | \alias{report}
5 | \title{Report formatted number}
6 | \usage{
7 | report(x, digits = 2, equals = TRUE)
8 | }
9 | \arguments{
10 | \item{x}{Numeric. Value to be reported}
11 |
12 | \item{digits}{Integer. Number of digits to round to.}
13 |
14 | \item{equals}{Logical. Whether to report an equals (or: smaller than) sign.}
15 | }
16 | \value{
17 | An atomic character vector.
18 | }
19 | \description{
20 | Report a number, rounded to a specific number of decimals (defaults to two),
21 | using \code{\link{formatC}}. Intended for 'R Markdown' reports.
22 | }
23 | \examples{
24 | report(.0234)
25 | }
26 | \author{
27 | Caspar J. van Lissa
28 | }
29 | \keyword{internal}
30 |
--------------------------------------------------------------------------------
/man/run_lavaan.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/syntax-run.R
3 | \name{run_lavaan}
4 | \alias{run_lavaan}
5 | \title{Run as lavaan model}
6 | \usage{
7 | run_lavaan(x, ...)
8 | }
9 | \arguments{
10 | \item{x}{An object for which a method exists.}
11 |
12 | \item{...}{Parameters passed on to other functions.}
13 | }
14 | \value{
15 | Returns a lavaan object.
16 | }
17 | \description{
18 | This convenience function runs objects for which a method exists
19 | using lavaan. It is intended for use with
20 | \code{tidySEM}, and passes the \code{$syntax} and \code{$data} elements of a
21 | \code{tidy_sem} object on to \code{\link[lavaan]{lavaan}}.
22 | }
23 | \examples{
24 | df <- iris[1:3]
25 | names(df) <- paste0("X_", 1:3)
26 | run_lavaan(measurement(tidy_sem(df), meanstructure = TRUE))
27 | }
28 |
--------------------------------------------------------------------------------
/man/run_mx.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/syntax-run.R
3 | \name{run_mx}
4 | \alias{run_mx}
5 | \title{Run as OpenMx model with sensible defaults}
6 | \usage{
7 | run_mx(x, ...)
8 | }
9 | \arguments{
10 | \item{x}{An object for which a method exists.}
11 |
12 | \item{...}{Parameters passed on to other functions.}
13 | }
14 | \value{
15 | Returns an \code{\link[OpenMx]{mxModel}} with free parameters updated
16 | to their final values.
17 | }
18 | \description{
19 | This convenience function runs objects for which a method exists
20 | using OpenMx, with sensible defaults. It is intended for use with
21 | \code{tidySEM}. For instance, it will convert a \code{tidySEM} object to
22 | a \code{mxModel} and run it, and it will try to ensure convergence for
23 | mixture models created using \code{\link{mx_mixture}}.
24 | Knowledgeable users may want to run models manually.
25 | }
26 | \examples{
27 | df <- iris[1:3]
28 | names(df) <- paste0("X_", 1:3)
29 | run_mx(measurement(tidy_sem(df), meanstructure = TRUE))
30 | }
31 |
--------------------------------------------------------------------------------
/man/skew_kurtosis.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/descriptives.R
3 | \name{skew_kurtosis}
4 | \alias{skew_kurtosis}
5 | \title{Calculate skew and kurtosis}
6 | \usage{
7 | skew_kurtosis(x, verbose = FALSE, se = FALSE, ...)
8 | }
9 | \arguments{
10 | \item{x}{An object for which a method exists.}
11 |
12 | \item{verbose}{Logical. Whether or not to print messages to the console,
13 | Default: FALSE}
14 |
15 | \item{se}{Whether or not to return the standard errors, Default: FALSE}
16 |
17 | \item{...}{Additional arguments to pass to and from functions.}
18 | }
19 | \value{
20 | A \code{matrix} of skew and kurtosis statistics for \code{x}.
21 | }
22 | \description{
23 | Calculate skew and kurtosis, standard errors for both, and the
24 | estimates divided by two times the standard error. If this latter quantity
25 | exceeds an absolute value of 1, the skew/kurtosis is significant. With very
26 | large sample sizes, significant skew/kurtosis is common.
27 | }
28 | \examples{
29 | skew_kurtosis(datasets::anscombe)
30 | }
31 |
--------------------------------------------------------------------------------
/man/syntax.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/syntax-attributes.R
3 | \name{syntax}
4 | \alias{syntax}
5 | \alias{syntax<-}
6 | \title{Extract syntax from tidy_sem}
7 | \usage{
8 | syntax(x)
9 |
10 | syntax(x) <- value
11 | }
12 | \arguments{
13 | \item{x}{Object of class tidy_sem.}
14 |
15 | \item{value}{A valid value for \code{syntax(x)}.}
16 | }
17 | \value{
18 | data.frame
19 | }
20 | \description{
21 | Provides access to the \code{syntax} element of a
22 | \code{tidy_sem} object. This can be used to return or assign to the
23 | \code{syntax} element.
24 | }
25 | \examples{
26 | dict <- tidy_sem(iris, split = "\\\\.")
27 | dict <- add_paths(dict, Sepal.Width ~~ Sepal.Length)
28 | syntax(dict)
29 | }
30 |
--------------------------------------------------------------------------------
/man/table_cors.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/results-table_results.R
3 | \name{table_cors}
4 | \alias{table_cors}
5 | \title{Extract correlation tables}
6 | \usage{
7 | table_cors(x, value_column = "est_sig_std", digits = 2, ...)
8 | }
9 | \arguments{
10 | \item{x}{An object for which a method exists.}
11 |
12 | \item{value_column}{Character. Name of the column to use to propagate the
13 | matrix. Defaults to "est_sig_std", the standardized estimate with
14 | significance asterisks.}
15 |
16 | \item{digits}{Number of digits to round to when formatting values.}
17 |
18 | \item{...}{Additional arguments passed to and from methods.}
19 | }
20 | \value{
21 | A Matrix or a list of matrices (in case there are between/within
22 | correlation matrices).
23 | }
24 | \description{
25 | Extracts a publication-ready covariance or correlation matrix from an object
26 | for which a method exists.
27 | }
28 | \examples{
29 | library(lavaan)
30 | HS.model <- ' visual =~ x1 + x2 + x3
31 | textual =~ x4 + x5 + x6
32 | speed =~ x7 + x8 + x9 '
33 | fit <- cfa(HS.model,
34 | data = HolzingerSwineford1939,
35 | group = "school")
36 | table_cors(fit)
37 | }
38 | \author{
39 | Caspar J. van Lissa
40 | }
41 |
--------------------------------------------------------------------------------
/man/table_fit.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/results-table_fit.R
3 | \name{table_fit}
4 | \alias{table_fit}
5 | \title{Print model fit table formatted for publication}
6 | \usage{
7 | table_fit(x, ...)
8 | }
9 | \arguments{
10 | \item{x}{A model object for which a method exists.}
11 |
12 | \item{...}{Arguments passed to other functions.}
13 | }
14 | \value{
15 | A data.frame of formatted results.
16 | }
17 | \description{
18 | Takes a model object, extracts model fit information, and formats it as a
19 | publication-ready table.
20 | }
21 | \examples{
22 | library(lavaan)
23 | HS.model <- ' visual =~ x1 + x2 + x3
24 | textual =~ x4 + x5 + x6
25 | speed =~ x7 + x8 + x9 '
26 | fit <- cfa(HS.model,
27 | data = HolzingerSwineford1939,
28 | group = "school")
29 | table_fit(fit)
30 | }
31 | \seealso{
32 | Other Reporting tools:
33 | \code{\link{conf_int}()},
34 | \code{\link{est_sig}()},
35 | \code{\link{table_prob}()},
36 | \code{\link{table_results}()}
37 | }
38 | \author{
39 | Caspar J. van Lissa
40 | }
41 | \concept{Reporting tools}
42 | \keyword{reporting}
43 |
--------------------------------------------------------------------------------
/man/table_prob.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/results-mx_ordinal.R
3 | \name{table_prob}
4 | \alias{table_prob}
5 | \title{Results table in probability scale}
6 | \usage{
7 | table_prob(x, ...)
8 | }
9 | \arguments{
10 | \item{x}{An object for which a method exists.}
11 |
12 | \item{...}{Arguments passed to other functions.}
13 | }
14 | \value{
15 | A data.frame with results in probability scale.
16 | }
17 | \description{
18 | Returns thresholds for ordinal
19 | dependent variables in probability scale.
20 | }
21 | \examples{
22 | \dontrun{
23 | df <- data_mix_ordinal
24 | df[1:4] <- lapply(df, ordered)
25 | mx_lca(data = df,
26 | classes = 2) -> res
27 | }
28 | }
29 | \seealso{
30 | Other Reporting tools:
31 | \code{\link{conf_int}()},
32 | \code{\link{est_sig}()},
33 | \code{\link{table_fit}()},
34 | \code{\link{table_results}()}
35 | }
36 | \concept{Reporting tools}
37 | \keyword{reporting}
38 |
--------------------------------------------------------------------------------
/man/table_results.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/results-table_results.R
3 | \name{table_results}
4 | \alias{table_results}
5 | \title{Print results table formatted for publication}
6 | \usage{
7 | table_results(
8 | x,
9 | columns = c("label", "est_sig", "se", "pval", "confint", "group", "level"),
10 | digits = 2,
11 | format_numeric = TRUE,
12 | ...
13 | )
14 | }
15 | \arguments{
16 | \item{x}{A model object for which a method exists.}
17 |
18 | \item{columns}{A character vector of columns to retain from the results
19 | section. If this is set to \code{NULL}, all available columns are returned.
20 | Defaults to \code{c("label", "est_sig", "se", "pval", "confint", "group",
21 | "level")}. These correspond to 1) the parameter label, 2) estimate column
22 | with significance asterisks appended
23 | (* <.05, ** < .01, *** < .001); 3) standard error, 4) p-value, 5) a
24 | formatted confidence interval, 6) grouping variable (if available), 7) level
25 | variable for multilevel models, if available.}
26 |
27 | \item{digits}{Number of digits to round to when formatting numeric columns.}
28 |
29 | \item{format_numeric}{Logical, indicating whether or not to format numeric
30 | columns. Defaults to \code{TRUE}.}
31 |
32 | \item{...}{Logical expressions used to filter the rows of results returned.}
33 | }
34 | \value{
35 | A data.frame of formatted results.
36 | }
37 | \description{
38 | Takes a model object, and formats it as a publication-ready table.
39 | }
40 | \examples{
41 | library(lavaan)
42 | HS.model <- ' visual =~ x1 + x2 + x3
43 | textual =~ x4 + x5 + x6
44 | speed =~ x7 + x8 + x9 '
45 | fit <- cfa(HS.model,
46 | data = HolzingerSwineford1939,
47 | group = "school")
48 | table_results(fit)
49 | }
50 | \seealso{
51 | Other Reporting tools:
52 | \code{\link{conf_int}()},
53 | \code{\link{est_sig}()},
54 | \code{\link{table_fit}()},
55 | \code{\link{table_prob}()}
56 | }
57 | \author{
58 | Caspar J. van Lissa
59 | }
60 | \concept{Reporting tools}
61 | \keyword{reporting}
62 |
--------------------------------------------------------------------------------
/man/wald_test.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/wald_test.R
3 | \name{wald_test}
4 | \alias{wald_test}
5 | \title{Wald Test for Linear Hypotheses}
6 | \usage{
7 | wald_test(x, hypothesis, ...)
8 | }
9 | \arguments{
10 | \item{x}{An object for which a method exists.}
11 |
12 | \item{hypothesis}{A character string with equality constrained hypotheses,
13 | specified according to the \code{\link[bain:bain]{bain::bain()}} syntax.}
14 |
15 | \item{...}{Additional arguments passed to \code{\link[car:linearHypothesis]{car::linearHypothesis()}}.}
16 | }
17 | \value{
18 | A \code{data.frame} of class \code{wald_test}.
19 | }
20 | \description{
21 | This function is a wrapper for the function
22 | \code{\link[car:linearHypothesis]{car::linearHypothesis()}}, but which uses the \code{\link[bain:bain]{bain::bain()}} syntax to parse
23 | equality constrained hypotheses.
24 | }
25 | \examples{
26 | mod <- lm(Sepal.Length ~ Sepal.Width, data = iris)
27 | coef(mod)
28 | wald_test(mod, "Sepal.Width = 0")
29 | }
30 | \seealso{
31 | \code{\link[car]{linearHypothesis}}
32 | }
33 |
--------------------------------------------------------------------------------
/man/zegwaard_carecompass.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/zegwaard_carecompass.R
3 | \docType{data}
4 | \name{zegwaard_carecompass}
5 | \alias{zegwaard_carecompass}
6 | \title{Caregiver Compass Data}
7 | \format{
8 | A data frame with 513 rows and 10 variables.
9 | }
10 | \usage{
11 | data(zegwaard_carecompass)
12 | }
13 | \description{
14 | These simulated data are based on a study by Dijenborgh, Swildens,
15 | and Zegwaard on different types of caregivers among those
16 | providing informal care to outpatients receiving mental healthcare.
17 | }
18 | \details{
19 | \tabular{lll}{
20 | \strong{burdened} \tab \code{numeric} \tab How strongly is the caregiver's life affected by their responsibilities? Scale score, based on 15 items with Likert-type response options. Example: "I never feel free of responsibilities"\cr
21 | \strong{trapped} \tab \code{numeric} \tab Caregiver's cognitions regarding freedom of choice. Scale score, based on 3 items with Likert-type response options. Example: "I feel trapped by the affliction of my charge"\cr
22 | \strong{negaffect} \tab \code{numeric} \tab Different types of negative emotions experienced by the caregiver. Scale score, based on 9 items with Likert-type response options. Example: "I feel angry in the relationship with my charge"\cr
23 | \strong{loneliness} \tab \code{numeric} \tab Caregiver's perceived loneliness. Scale score, based on 11 items with Likert-type response options. Example: "I miss having people around"\cr
24 | \strong{sex} \tab \code{factor} \tab Caregiver sex\cr
25 | \strong{sexpatient} \tab \code{factor} \tab Sex of the patient\cr
26 | \strong{cohabiting} \tab \code{factor} \tab Whether or not the caregiver cohabits with the patient\cr
27 | \strong{distance} \tab \code{numeric} \tab Travel time in minutes for the caregiver to reach the patient\cr
28 | \strong{freqvisit} \tab \code{ordered} \tab Ordinal variable, indicating frequency of visits\cr
29 | \strong{relationship} \tab \code{factor} \tab Type of relationship of patient with caregiver
30 | }
31 | }
32 | \keyword{datasets}
33 |
--------------------------------------------------------------------------------
/tests/testthat.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(tidySEM)
3 | if(requireNamespace("OpenMx", quietly = TRUE)) require("OpenMx")
4 | if(requireNamespace("umx", quietly = TRUE)) require("umx")
5 | options("test_mplus" = FALSE)
6 | test_check("tidySEM")
7 |
--------------------------------------------------------------------------------
/tests/testthat/Rplots.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/tests/testthat/Rplots.pdf
--------------------------------------------------------------------------------
/tests/testthat/test-BLRT_lr_lmr.R:
--------------------------------------------------------------------------------
1 | if(requireNamespace("OpenMx", quietly = TRUE)){
2 | set.seed(5)
3 | df <- iris[c(1:5, 50:55, 100:105), 1:4]
4 | names(df) <- letters[1:4]
5 | res <- mx_profiles(df, 1:2)
6 |
7 | test_that("blrt works as expected", {
8 | res_blrt <- BLRT(res, 10)
9 | expect_equivalent(res_blrt$lr, 79.6, tolerance = .02)
10 | expect_equivalent(res_blrt$blrt_p, 0)
11 | })
12 |
13 | test_that("lr_lmr works as expected", {
14 | res_lmr <- lr_lmr(res)
15 | expect_equivalent(res_lmr$lr, 4.89, tolerance = .01)
16 | expect_equivalent(res_lmr$p, 4.9e-7, tolerance = .001)
17 | })
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/tests/testthat/test-a-namespaces.R:
--------------------------------------------------------------------------------
1 | df <- iris[1:4]
2 | names(df) <- paste0("x", 1:4)
3 | tmp <- tidy_sem(df)
4 | tmp <- add_paths(tmp, "x1 ~ x2")
5 | if(isTRUE(getOption("test_mplus"))){
6 | res <- suppressWarnings(estimate_mplus(tmp))
7 |
8 | test_that("table_fit does not give namespace error", {
9 | expect_error({table_fit(res)}, NA)
10 | })
11 | }
12 |
13 |
14 | test_that("mx profiles does not give namespace error", {
15 | expect_error({mx_profiles(data = df, classes = 2)}, NA)
16 | })
17 |
--------------------------------------------------------------------------------
/tests/testthat/test-get_edges_columns.R:
--------------------------------------------------------------------------------
1 | library(lavaan)
2 | library(MplusAutomation)
3 |
4 | test_that("get_edges handles columns argument", {
5 | fit <- sem("mpg ~ cyl\nmpg ~ am", data = mtcars, meanstructure = TRUE)
6 |
7 | out <- get_edges(fit, label = NULL, columns = c("est", "pval"))
8 | out <- within(out, {label <- paste(est, pval)})
9 |
10 |
11 | expect_equivalent(out$label, c("-2.50 0.00", "2.57 0.04", "8.48 0.00", "3.09 NA", "-0.45 NA",
12 | "0.24 NA"))
13 |
14 | out <- get_nodes(fit, label = NULL, columns = c("est", "pval"))
15 |
16 |
17 | if(isTRUE(getOption("test_mplus"))){
18 | the_test <- "get_edges_columns"
19 | old_wd <- getwd()
20 | test_dir <- file.path(tempdir(), the_test)
21 | dir.create(test_dir)
22 | setwd(test_dir)
23 | on.exit({unlink(test_dir, recursive = TRUE); setwd(old_wd)}, add = TRUE)
24 |
25 | res_mplus <- mplusModeler(mplusObject(MODEL = "mpg ON cyl am;", OUTPUT = "standardized;", rdata = mtcars), modelout = "test.inp", run = 1L)
26 |
27 | out <- get_edges(res_mplus$results, label = NULL, columns = c("est", "pval"))
28 | out <- within(out, {label <- paste(est, pval)})
29 |
30 | expect_equivalent(out$label, c("2.57 0.04", "-2.50 0.00", "8.48 0.00"))
31 |
32 | }
33 | })
34 |
--------------------------------------------------------------------------------
/tests/testthat/test-get_nodes_label.R:
--------------------------------------------------------------------------------
1 | library(lavaan)
2 | library(MplusAutomation)
3 |
4 | res_lav <- sem("mpg ~ cyl\nmpg ~ am", data = mtcars, meanstructure = TRUE)
5 |
6 | test_that("get_nodes.lavaan handles columns argument", {
7 | out <- get_nodes(res_lav, label = NULL, columns = c("est", "pval"))
8 | expect_true(all(c("est", "pval") %in% names(out)))
9 | })
10 |
11 | test_that("get_nodes.lavaan handles character label", {
12 | out <- get_nodes(res_lav, label = "pval", columns = c("est", "pval"))
13 | expect_equivalent(out$label, out$pval)
14 | })
15 |
16 | test_that("get_nodes.lavaan handles custom label", {
17 | out <- get_nodes(res_lav, label = paste0(name, " (", confint, ")"))
18 | expect_true(all(grepl("^[a-z]+\\s\\(\\[\\d*\\.\\d{2}, \\d*\\.\\d{2}\\]\\)$", out$label)))
19 | })
20 |
21 |
22 | if(isTRUE(getOption("test_mplus"))){
23 | the_test <- "get_nodes_label"
24 | old_wd <- getwd()
25 | test_dir <- file.path(tempdir(), the_test)
26 | dir.create(test_dir)
27 | setwd(test_dir)
28 | on.exit({unlink(test_dir, recursive = TRUE); setwd(old_wd)}, add = TRUE)
29 |
30 | res_mplus <- mplusModeler(mplusObject(MODEL = "mpg ON cyl am;", OUTPUT = "standardized;", rdata = mtcars), modelout = "test.inp", run = 1L)
31 |
32 | test_that("get_nodes.mplus handles columns argument", {
33 | out <- get_nodes(res_mplus, label = NULL, columns = c("est", "pval"))
34 | expect_true(all(c("est", "pval") %in% names(out)))
35 | })
36 |
37 | test_that("get_nodes.mplus handles character label", {
38 | out <- get_nodes(res_mplus, label = "pval", columns = c("est", "pval"))
39 | expect_equivalent(out$label, out$pval)
40 | })
41 | test_that("get_nodes.mplus handles custom label", {
42 | out <- get_nodes(res_mplus, label = paste0(name, " (", confint, ")"))
43 | expect_true(all(grepl("^[A-Z]+\\s\\((\\[[0-9\\.,\\s -]+\\]|NA)\\)$", out$label)))
44 | })
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/tests/testthat/test-get_nodes_multigroup_label.R:
--------------------------------------------------------------------------------
1 | library(lavaan)
2 | library(tidySEM)
3 |
4 | HS.model <- ' F =~ x1 + x2 + x3'
5 | fit <- cfa(HS.model,
6 | data = HolzingerSwineford1939,
7 | group = "school")
8 |
9 | test_that("get_nodes correctly labels multigroup models", {
10 | expect_true(get_nodes(fit, label = "name")$label[1] == "F")
11 | })
12 |
13 |
--------------------------------------------------------------------------------
/tests/testthat/test-graph_sem_flip.R:
--------------------------------------------------------------------------------
1 | model <- "
2 | visual =~ x1 + x2 + x3
3 | textual =~ x4 + x5 + x6
4 | speed =~ x7 + x8 + x9
5 | speed ~ ageyr + grade
6 | textual ~ ageyr + grade
7 | x4 ~~ x5 + x6
8 | textual ~~ speed
9 | "
10 |
11 | fit <- sem(model, HolzingerSwineford1939)
12 |
13 | layout <- data.frame(
14 | IV = c("x1", "grade", "", "ageyr", ""),
15 | M = c("x2", "", "visual", "", ""),
16 | DV = c("x3", "textual", "", "speed", "x9"),
17 | DV.items = c(paste0("x", 4:8)))
18 |
19 | tmp = prepare_graph(fit, layout = layout)
20 | # wrn <- getOption("warn")
21 | # options(warn=0)
22 | test_that("curves flipped correctly when nodes have same x coordinates", {
23 | expect_no_warning(print(plot(tmp)))
24 | })
25 |
--------------------------------------------------------------------------------
/tests/testthat/test-graph_sem_label.R:
--------------------------------------------------------------------------------
1 | library(lavaan)
2 | res <- sem("dist ~ speed", cars, meanstructure =T)
3 |
4 |
5 | # graph_sem(res)
6 | # lay <- get_layout("dist", "speed", rows = 1)
7 | # graph_sem(res,
8 | # layout = lay, # layout
9 | # label = "est_std", # get standardized results (not rounded)
10 | # angle = 170 # adjust the arrows
11 | # )
12 | #
13 | # graph_sem(res,
14 | # layout = lay, # layout
15 | # nodes = get_nodes(res, label = "name"),
16 | # edges = get_edges(res, label = "est_std"),
17 | # angle = 170 # adjust the arrows
18 | # )
19 |
20 | test_that("prepare_graph handles label argument", {
21 | tmp <- prepare_graph(res, label = "est_std")
22 | expect_true(all(!is.na(as.numeric(tmp$edges$label))))
23 | expect_true(all(!is.na(as.numeric(tmp$nodes$label))))
24 | })
25 |
26 | test_that("prepare_graph handles expression in label argument", {
27 | tmp <- prepare_graph(res, label = paste2(lhs, est_sig, sep = "\n"))
28 | expect_true(any(startsWith(tmp$edges$label, "dist")))
29 | expect_true(any(startsWith(tmp$nodes$label, "dist")))
30 | })
31 |
32 | test_that("graph_sem handles label argument", {
33 | tmp <- graph_sem(res, label = "est_std")
34 | expect_true(all(!is.na(as.numeric(tmp$layers[[3]]$data$label))))
35 | expect_true(all(!is.na(as.numeric(tmp$layers[[5]]$data$label))))
36 | })
37 |
38 | test_that("graph_sem handles expression in label argument", {
39 | tmp <- graph_sem(res, label = paste2(lhs, est_sig, sep = "\n"))
40 | expect_true(any(startsWith(tmp$layers[[3]]$data$label, "dist")))
41 | expect_true(any(startsWith(tmp$layers[[5]]$data$label, "dist")))
42 | })
43 |
--------------------------------------------------------------------------------
/tests/testthat/test-lr_test_negative_df.R:
--------------------------------------------------------------------------------
1 | if(requireNamespace("OpenMx", quietly = TRUE)){
2 |
3 | df = iris[1:3]
4 | names(df) <- letters[1:3]
5 | res <- mx_profiles(df, 2)
6 | df_aux <- cut(iris[[4]], 3)
7 | df_aux <- mx_dummies(df_aux)
8 | names(df_aux) <- letters[1:ncol(df_aux)]
9 | res_bch <- suppressWarnings(BCH(res, paste0(names(df_aux), " | t1", collapse = "\n"), data = df_aux))
10 | testres <- suppressWarnings(lr_test(res_bch))
11 |
12 | test_that("lr_test does not give negative df", {
13 | expect_true(testres$overall$df > 0)
14 | expect_true(all(testres$pairwise$df > 0))
15 | })
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/tests/testthat/test-lrt_bch.R:
--------------------------------------------------------------------------------
1 | if(requireNamespace("OpenMx", quietly = TRUE)){
2 |
3 | df <- iris[, 1:2]
4 | names(df) <- c("x", "y")
5 | set.seed(1)
6 | mix <- mx_profiles(df[, "x", drop = FALSE], classes = 3)
7 | bch1 <- BCH(x = mix, data = df$y)
8 |
9 | test_that("bch works with continuous data", {
10 | tab <- table_results(bch1, columns = NULL)
11 | expect_equal(tab$est[tab$matrix == "M"], c("2.90", "3.16", "3.19"))
12 | })
13 |
14 | test_that("bch lrt works with continuous data", {
15 | tst <- lr_test(bch1)
16 | expect_equal(tst$overall$LL_dif, 44, tolerance = .1)
17 | expect_equal(tst$pairwise$LL_dif, c(11.9532756799639, 42.7749648547106, 1.72975571779375)
18 | , tolerance = .1)
19 | })
20 |
21 | df$y <- factor(cut(df$y, 3), labels = letters[1:3])
22 | set.seed(1)
23 | bch1 <- suppressWarnings(BCH(x = mix, data = df$y))
24 |
25 | test_that("bch works with ordinal data", {
26 | tab <- table_results(bch1, columns = NULL)
27 | expect_equal(as.numeric(tab$est[tab$matrix == "Thresholds"]), as.numeric(c("0.24", "-0.26", "8.29", "0.76", "-0.20", "0.86", "0.70", "-0.18", "0.89")), tolerance = .1)
28 | })
29 |
30 | test_that("bch lrt works with ordinal data", {
31 | tst <- suppressWarnings(lr_test(bch1))
32 | expect_equal(tst$overall$LL_dif, 62.66664, tolerance = .1)
33 | expect_equal(tst$pairwise$LL_dif, c(49.8339753225328, 61.1695798706335, 0.0196484043474641)
34 | , tolerance = .1)
35 | })
36 | }
37 |
--------------------------------------------------------------------------------
/tests/testthat/test-lrt_multigroup.R:
--------------------------------------------------------------------------------
1 | if(requireNamespace("OpenMx", quietly = TRUE)){
2 |
3 | df <- iris[c(1:10, 140:150), c(1, 5)]
4 | names(df) <- c("x", "group")
5 | mod <- as_ram("x~1", data = df, group = "group")
6 | mod <- run_mx(mod)
7 |
8 | test_that("lrt works with multigroup", {
9 | tst <- lr_test(mod)
10 | expect_equal(tst$overall$LL_dif, 42.12566, tolerance = .1)
11 | expect_equal(tst$pairwise$LL_dif, 42.1256631767803, tolerance = .1)
12 | })
13 | }
14 |
--------------------------------------------------------------------------------
/tests/testthat/test-minimal_plot.R:
--------------------------------------------------------------------------------
1 | nod <- data.frame(name = "x",
2 | shape = "rect")
3 |
4 | test_that("possible to plot only a node", {
5 | expect_s3_class(graph_sem(nodes = nod, layout = get_layout("x", rows = 1)), "ggplot")
6 | })
7 |
8 | library(lavaan)
9 |
10 | fit <- sem("Sepal.Length ~~ Sepal.Width", data = iris)
11 | if(FALSE){
12 | # Dit gaat mis in .connect: bij één column of één row.
13 | graph_sem(fit)
14 |
15 | test_that("can adjust curvature", {
16 | expect_s3_class(graph_sem(nodes = nod, layout = get_layout("x", rows = 1)), "ggplot")
17 | })
18 |
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/tests/testthat/test-mx_profiles_dataframe.R:
--------------------------------------------------------------------------------
1 | if(FALSE){library(testthat)
2 | set.seed(1)
3 | n = 100
4 | C <- sample(c("Man", "Woman"), n, replace = TRUE)
5 | means <- c(Man = 10, Woman = 7)
6 | X <- rnorm(n, mean = means[C], sd = 1)
7 | test_that("mx_profiles works with data = data.frame()", {
8 | expect_error({est <- mx_profiles(data = data.frame(X), classes = 1:3)}, NA)
9 | })
10 | }
11 |
--------------------------------------------------------------------------------
/tests/testthat/test-namespace_checks_dominique.R:
--------------------------------------------------------------------------------
1 | detach("package:tidySEM", unload = TRUE)
2 | m <- lavaan::sem('
3 | ind60 =~ x1 + x2 + x3
4 | dem60 =~ y1 + a*y2 + b*y3
5 | ', data = lavaan::PoliticalDemocracy)
6 |
7 | test_that("graph_sem works when tidySEM is not attached", {
8 | expect_error({tidySEM::graph_sem(m, edges = tidySEM::get_edges(m))}, NA)
9 | })
10 |
11 | if(requireNamespace("ggraph", quietly = TRUE)){
12 | library(tidySEM)
13 | library(ggraph)
14 | test_that("graph_sem works when ggraph masks get_edges etc", {
15 | expect_error({tidySEM::graph_sem(m)}, NA)
16 | })
17 | detach("package:ggraph", unload = TRUE)
18 | }
19 |
--------------------------------------------------------------------------------
/tests/testthat/test-plot_color_argument.R:
--------------------------------------------------------------------------------
1 | library(ggplot2)
2 | test_that("color argument works for graph_sem", {
3 | the_test <- "plot_color"
4 | old_wd <- getwd()
5 | test_dir <- file.path(tempdir(), the_test)
6 | dir.create(test_dir)
7 | setwd(test_dir)
8 | on.exit({unlink(test_dir, recursive = TRUE); setwd(old_wd)}, add = TRUE)
9 |
10 | p <- prepare_graph(layout = get_layout("x", rows = 1))
11 | p1 <- edit_graph(p, {color = "blue"}, element = "nodes")
12 | p2 <- edit_graph(p, {colour = "blue"}, element = "nodes")
13 | ggsave("p1.png", plot(p1), device = "png")
14 | ggsave("p2.png", plot(p2), device = "png")
15 |
16 | expect_equivalent(tools::md5sum("p1.png"), tools::md5sum("p2.png"))
17 |
18 | })
19 |
--------------------------------------------------------------------------------
/tests/testthat/test-plot_digits.R:
--------------------------------------------------------------------------------
1 | library(tidySEM)
2 | library(lavaan)
3 |
4 | fit <- sem("mpg ~ am", data = mtcars, meanstructure = TRUE)
5 |
6 | p <- prepare_graph(fit, digits = 5)
7 |
8 | fit <- sem("mpg ~ am", data = mtcars, meanstructure = TRUE)
9 |
10 | prepare_graph(fit, digits = 5) |>
11 | color_sig("green") |>
12 | label_color_sig("green") |>
13 | plot()
14 |
15 |
16 | test_that("prepare_graph passed on digits", {
17 | expect_true(all(grepl("\\.\\d{5}", p$edges$est)))
18 | expect_true(all(grepl("\\.\\d{5}", p$nodes$est)))
19 | })
20 |
21 | p <- prepare_graph(fit, label = "confint")
22 |
23 | test_that("prepare_graph passed on label", {
24 | expect_true(all(grepl("^\\[.*\\]$", p$edges$label)))
25 | expect_true(all(grepl("^\\[.*\\]$", p$nodes$label)))
26 | })
27 |
28 | p <- prepare_graph(fit, columns = c("lhs", "op", "pval"))
29 |
30 | test_that("prepare_graph passed on columns", {
31 | expect_true(all(c("lhs", "op", "pval") %in% names(p$edges)))
32 | expect_true(all(c("lhs", "op", "pval") %in% names(p$nodes)))
33 | expect_true(!"est" %in% names(p$edges))
34 | expect_true(!"est" %in% names(p$nodes))
35 | })
36 |
37 |
--------------------------------------------------------------------------------
/tests/testthat/test-plot_group_labels.R:
--------------------------------------------------------------------------------
1 | library(lavaan)
2 | library(tidySEM)
3 |
4 | test_that("Multigroup labels are OK", {
5 | HS.model <- ' visual =~ x1 + x2 + x3
6 | textual =~ x4 + x5 + x6
7 | speed =~ x7 + x8 + x9 '
8 | fit <- cfa(HS.model,
9 | data = HolzingerSwineford1939,
10 | group = "school")
11 |
12 | p <- prepare_graph(fit)
13 |
14 |
15 | expect_true(!any(grepl("Grant-White", p$edges$label)))
16 | expect_true(!any(grepl("TRUE", as.character(p$edges$label))))
17 | })
18 |
--------------------------------------------------------------------------------
/tests/testthat/test-plot_growth_model.R:
--------------------------------------------------------------------------------
1 | library(lavaan)
2 | library(tidySEM)
3 |
4 | model.syntax <- '
5 | # intercept and slope with fixed coefficients
6 | i =~ 1*t1 + 1*t2 + 1*t3 + 1*t4
7 | s =~ 0*t1 + 1*t2 + 2*t3 + 3*t4
8 |
9 | # regressions
10 | i ~ x1 + x2
11 | s ~ x1 + x2
12 | '
13 |
14 | fit <- growth(model.syntax, data = Demo.growth)
15 |
16 | lay <- get_layout(
17 | "t1", "t2", "t3", "t4",
18 | NA, "i", "s", NA,
19 | rows = 2
20 | )
21 | tmp <- fit
22 |
23 | # Check whether there are any errors related to the environment:
24 | p=prepare_graph(fit, nodes = get_nodes(tmp))
25 | # Then carry on with the regular tests
26 | p=prepare_graph(fit, layout = lay)
27 |
28 | test_that("node labels correct", {
29 | expect_true(all(grepl("\\n", p$nodes$label)))
30 | })
31 |
32 | model.syntax <- '
33 | # intercept and slope with fixed coefficients
34 | i =~ 1*t1 + 1*t2 + 1*t3 + 1*t4
35 | s =~ 0*t1 + 1*t2 + 2*t3 + 3*t4
36 |
37 | # time-varying covariates
38 | t1 ~ c1
39 | t2 ~ c2
40 | t3 ~ c3
41 | t4 ~ c4
42 |
43 | # regressions
44 | i ~ x1 + x2
45 | s ~ x1 + x2
46 | '
47 |
48 | fit <- growth(model.syntax, data = Demo.growth)
49 |
50 | lay <- get_layout(
51 | "c1", "c2", "c3", "c4",
52 | "t1", "t2", "t3", "t4",
53 | NA, "i", "s", NA,
54 | "x1", NA, NA, "x2",
55 | rows = 4
56 | )
57 |
58 | p <- prepare_graph(fit, layout = lay) # TOO MANY ARROWS!
59 |
60 | test_that("node labels correct", {
61 | expect_true(sum(p$edges$op == "=~") == 8)
62 | })
63 |
--------------------------------------------------------------------------------
/tests/testthat/test-plot_if_edit.R:
--------------------------------------------------------------------------------
1 | library(lavaan)
2 |
3 | test_that("if_edit and its derivatives work", {
4 | fit <- sem("mpg ~ cyl\nmpg ~ am", data = mtcars, meanstructure = TRUE)
5 |
6 | p <- prepare_graph(model = fit)
7 |
8 | tmp <- hide_sig(p)
9 | expect_true(all(!tmp$edges$show))
10 | expect_error(plot(tmp), NA)
11 |
12 | tmp <- hide_fixed(p)
13 | expect_equivalent(tmp$edges$show, p$edges$show)
14 | expect_error(plot(tmp), NA)
15 |
16 | tmp <- hide_sig(p, element = c("nodes", "edges"))
17 | expect_true(all(!tmp$edges$show))
18 | expect_equivalent(tmp$nodes$show, c(TRUE, TRUE, FALSE))
19 | expect_message(plot(tmp))
20 | expect_error(plot(tmp), NA)
21 |
22 | tmp <- hide_fixed(p, element = c("nodes", "edges"))
23 | expect_equivalent(tmp$edges$show, !c(FALSE, FALSE, FALSE, TRUE, TRUE, TRUE))
24 | expect_equivalent(tmp$nodes$show, c(FALSE, FALSE, TRUE))
25 | expect_message(plot(tmp))
26 | expect_error(plot(tmp), NA)
27 |
28 | tmp <- hide_sig(tmp, element = c("nodes", "edges"))
29 | expect_true(all(!tmp$edges$show))
30 | expect_true(all(!tmp$nodes$show))
31 | expect_error(plot(tmp))
32 |
33 | tmp <- show_sig(tmp, element = c("nodes", "edges"))
34 | expect_equivalent(tmp$edges$show, c(TRUE, TRUE, TRUE, FALSE, FALSE, FALSE))
35 | expect_equivalent(tmp$nodes$show, c(FALSE, FALSE, TRUE))
36 | expect_error(plot(tmp), NA)
37 | p$edges$confint_std[4:6] <- "3"
38 | p$nodes$confint_std[1:2] <- "3"
39 | tmp <- if_edit(p, {grepl("3", confint_std)}, {show = FALSE}, element = c("edges", "nodes"))
40 | expect_equivalent(tmp$edges$show, c(TRUE, TRUE, FALSE, FALSE, FALSE, FALSE))
41 | expect_equivalent(tmp$nodes$show, c(FALSE, FALSE, TRUE))
42 | expect_error(plot(tmp), NA)
43 |
44 | # tmp <- p
45 | # tmp$edges$linetype <- c(1,1,1,2,2,2)
46 | # tmp<- linetype_sig(p, 2)
47 | # plot(tmp)
48 | #
49 | # plot(colour_fixed(p, "red"))
50 | #
51 | # tmp$edges$pval[4] <- "0.5"
52 | # plot(linetype_non_sig(tmp, 3))
53 | # tmp$nodes$pval[3] <- "0.5"
54 | # plot(linetype_non_sig(tmp, 2, elements = c("nodes", "edges")))
55 | # tmp$edges
56 | #
57 | # plot(tmp)
58 |
59 | })
60 |
--------------------------------------------------------------------------------
/tests/testthat/test-plot_if_edit_overwrite_aes.R:
--------------------------------------------------------------------------------
1 | fit <- sem("mpg ~ cyl\nmpg ~ am", data = mtcars, meanstructure = TRUE)
2 |
3 | g <- prepare_graph(fit)
4 | edges(g) %>%
5 | color_pos("green") %>%
6 | color_neg("red") ->
7 | p
8 |
9 | test_that("if_edit functions not overwrite aesthetic column", {
10 | expect_true(all(p$color == c("red", "green", "green", "green", "red", "green")))
11 | })
12 |
13 |
14 | g <- prepare_graph(fit)
15 | g$edges$bla <- rep(0, nrow(g$edges))
16 | g$edges$bla[1] <- 1
17 | g$edges$linetype = 1
18 |
19 | test_that("if_edit works when column exists in either edges or nodes", {
20 | expect_error({
21 | p <- if_edit(g, {bla == 1}, {linetype = 2})
22 | plot(p)
23 | }, NA)
24 | })
25 |
--------------------------------------------------------------------------------
/tests/testthat/test-plot_igraph.R:
--------------------------------------------------------------------------------
1 | library(igraph)
2 | library(tidySEM)
3 | g <- make_ring(10)
4 | edge_attr(g) <- list(
5 | name = LETTERS[1:10],
6 | color = rep("green", gsize(g))
7 | )
8 |
9 | test_that("igraph edges correct", {
10 | edg <- get_edges(g)
11 | expect_true(all(c("from", "to", "name", "color", "arrow") %in% names(edg)) )
12 | expect_true(all(edg$arrow == "none"))
13 | edge_attr(g, "label") <- paste0("lab", E(g)$name)
14 | edg <- get_edges(g)
15 | expect_true(all(startsWith(edg$label, "lab")))
16 | })
17 |
18 | test_that("igraph nodes correct", {
19 | nod <- get_nodes(g)
20 | expect_true(all(c("name", "shape", "label") %in% names(nod)) )
21 | expect_true(all(nod$shape == "none"))
22 | })
23 |
24 | test_that("igraph layout correct", {
25 | lo <- get_layout(g)
26 | expect_true(all(c("x", "y", "name") %in% names(lo)) )
27 | })
28 |
29 | g <- graph_from_data_frame(data.frame(one=1:2,two=2:3))
30 | g <- set_vertex_attr(g,'id',1,'first_id')
31 |
32 | test_that("igraph edges correct", {
33 | edg <- get_edges(g)
34 | expect_true(all(c("from", "to", "arrow") %in% names(edg)) )
35 | expect_true(all(edg$arrow == "last"))
36 | })
37 |
38 | test_that("igraph nodes correct", {
39 | nod <- get_nodes(g)
40 | expect_true(all(c("name", "id", "shape", "label") %in% names(nod)) )
41 | })
42 |
43 | test_that("igraph layout correct", {
44 | lo <- get_layout(g)
45 | expect_true(all(c("x", "y", "name") %in% names(lo)) )
46 | })
47 |
48 |
49 | names <- c('A','B','C,','D')
50 | from <- c(113,115,112,114,113)
51 | to <- c(112,112,115,113,114)
52 | structure <- data.frame("from" = from, "to" = to)
53 | g <- graph.data.frame(structure)
54 | #V(g)$label <- names
55 | V(g)$nonsense <- letters[seq_along(names)]
56 |
57 | test_that("igraph edges correct", {
58 | edg <- get_edges(g)
59 | expect_true(all(c("from", "to", "arrow") %in% names(edg)) )
60 | expect_true(all(edg$arrow == "last"))
61 | g_un <- as_undirected(g)
62 | edg_un <- get_edges(g_un)
63 | expect_true(all(edg_un$arrow == "none"))
64 | })
65 |
66 | test_that("igraph nodes correct", {
67 | nod <- get_nodes(g)
68 | expect_true(all(c("name", "nonsense", "shape", "label") %in% names(nod)) )
69 | })
70 |
71 | test_that("igraph layout correct", {
72 | lo <- get_layout(g)
73 | expect_true(all(c("x", "y", "name") %in% names(lo)) )
74 | })
75 |
--------------------------------------------------------------------------------
/tests/testthat/test-plot_lav_cfa.R:
--------------------------------------------------------------------------------
1 | library(lavaan)
2 | df <- HolzingerSwineford1939
3 | #df$x2 <- ordered(cut(df$x2, 4))
4 |
5 | HS.model <- ' visual =~ x1 + x2 + x3
6 | textual =~ x4 + x5 + x6
7 | speed =~ x7 + x8 + x9 '
8 | fit <- cfa(HS.model, data=df, meanstructure = T)
9 |
10 | test_that("Can plot lavaan without specifying anything", {
11 | expect_error(do.call(graph_sem, list(model = fit)), NA)
12 | })
13 |
14 | layout <- get_layout("", "", "visual","","textual","","speed","", "",
15 | paste0("x", 1:9), rows = 2)
16 |
17 | edg <- get_edges(fit)
18 | nod <- get_nodes(fit)
19 |
20 | #nod$label[5] <- "bla"
21 |
22 | p2 <- prepare_graph(nodes = nod, layout = layout, edges = edg, angle = 170, text_size = 3)
23 | #p2$edges$curvature[19:24] <- .3
24 | #edges(p2)$curvature[10:12] <- edges(p2)$curvature[10:12] *-1
25 | tmp <- plot(p2)
26 | edges(p2)
27 | test_that("Plot works for lavaan cfa", {
28 | expect_s3_class(tmp, "ggplot")
29 | })
30 |
31 | edges(p2)$linetype <- 1
32 |
33 | edges(p2)$colour <- sample(c("red", "blue"), nrow(edges(p2)), replace = T)
34 |
--------------------------------------------------------------------------------
/tests/testthat/test-plot_multigroup_multilevel.R:
--------------------------------------------------------------------------------
1 | test_that("multilevmultigroup works", {
2 | tidySEM:::skip_if_not_local()
3 | Galo <- read.csv("../testdata/galo.csv")
4 |
5 | L.in.G <- ' group: foo
6 | level: within
7 | galo ~ focc
8 | level: between
9 | galo ~ focc
10 |
11 | group: bar
12 | level: within
13 | galo ~ focc
14 | level: between
15 | galo ~ focc
16 | '
17 |
18 | fit <- suppressWarnings(sem(L.in.G, data = Galo, cluster = "school", fixed.x = FALSE,
19 | missing = "fiml", std.lv = TRUE, h1 = TRUE, group = "g"))
20 |
21 |
22 | nod <- get_nodes(fit)
23 | edg <- get_edges(fit)
24 |
25 | layout <- matrix(c("focc.within", "galo.within",
26 | "focc.between", "galo.between"), ncol = 2, byrow = TRUE)
27 |
28 |
29 | expect_true(nrow(nod) == 2*length(as.vector(layout)[!as.vector(layout) == ""]))
30 |
31 | plevgroup <- prepare_graph(edges = edg, nodes = nod, layout = layout)
32 | p <- plot(plevgroup)
33 |
34 |
35 | expect_s3_class(p, "ggplot")
36 | })
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/tests/testthat/test-plot_plot_prob.R:
--------------------------------------------------------------------------------
1 | test_that("plot_prob works", {
2 | testthat::skip_if_not_installed("OpenMx")
3 | tidySEM:::skip_if_not_local()
4 | df <- data_mix_ordinal
5 | df[1:4] <- lapply(df, ordered)
6 | mx_lca(data = df,
7 | classes = 2) -> res
8 | plot_prob(res)
9 | expect_equal(1, 1)
10 | })
11 |
--------------------------------------------------------------------------------
/tests/testthat/test-plot_profiles_varyingcov.R:
--------------------------------------------------------------------------------
1 | test_that("plot_profiles works with varying covariances", {
2 | skip_on_cran()
3 | testthat::skip_if_not_installed("OpenMx")
4 | df <- iris[1:4]
5 | names(df) <- paste0("x", 1:4 )
6 | res <- mx_profiles(df, 2, covariances = "varying")
7 | expect_error(tidySEM::plot_profiles(res), NA)
8 | })
9 |
10 |
--------------------------------------------------------------------------------
/tests/testthat/test-plot_sem.R:
--------------------------------------------------------------------------------
1 | lo <- get_layout("ne", "phys", "",
2 | "plea", "", "",
3 | "dist", "", "dep",
4 | "saf", "", "",
5 | "coh", "stress", "", rows = 5)
6 |
7 | test_that("get_layout generates matrix", {
8 | expect_true(inherits(lo, "matrix"))
9 | })
10 |
11 | long_lo <- tidySEM:::long_layout(lo)
12 | df_nodes <- data.frame(node_id = 1:length(long_lo$name), name = long_lo$name, stringsAsFactors = FALSE)
13 | df_nodes$shape <- "oval"
14 | df_nodes$shape[grepl("(phys)", df_nodes$name)] <- "rect"
15 | labels <- list("ne" = "Natural environment",
16 | "plea" = "Pleasantness",
17 | "dist" = "Disturbance",
18 | "saf" = "Safety",
19 | "coh" = "Cohesion",
20 | "phys" = "Physical activity",
21 | "stress" = "Stress",
22 | "dep" ="Depression"
23 | )
24 | df_nodes$label <- unlist(labels[match(df_nodes$name, names(labels))])
25 | #df_nodes$name <- df_nodes$node_id
26 | df_edges <- data.frame(matrix(c(
27 | 1, 6, "last", "+",
28 | 2, 6, "last", "+",
29 | 3, 6, "last", "-",
30 | 4, 6, "last", "+",
31 | 5, 6, "last", "+",
32 |
33 | 1, 7, "last", "-",
34 | 2, 7, "last", "-",
35 | 3, 7, "last", "+",
36 | 4, 7, "last", "-",
37 | 5, 7, "last", "-",
38 | 6, 8, "last", "-",
39 | 7, 8, "last", "+"), ncol = 4, byrow = TRUE), stringsAsFactors = FALSE)
40 | names(df_edges) <- c("from", "to", "arrow", "label")
41 | df_edges$connector <- c(rep("line", 12))
42 |
43 | df_edges$from <- df_nodes$name[as.numeric(df_edges$from)]
44 | df_edges$to <- df_nodes$name[as.numeric(df_edges$to)]
45 | df_edges$curvature <- c(rep(NA, 12))
46 |
47 | prep <- prepare_graph(nodes = df_nodes, layout = lo, edges = df_edges)
48 |
49 | test_that("prepare_graph correctly generates graph data", {
50 | expect_s3_class(prep, "sem_graph")
51 | })
52 |
53 |
54 | prep$edges$connect_from <- "right"
55 | prep$edges$connect_to[c(5,6)] <- c("bottom", "top")
56 | prep$edges$connect_to <- c(rep("left", 10), "top", "bottom")
57 | prep$edges$label_location <- .2
58 | p <- plot(prep)
59 |
60 | test_that("multiplication works", {
61 | expect_equal(2 * 2, 4)
62 | })
63 |
64 |
--------------------------------------------------------------------------------
/tests/testthat/test-pseudo_class_technique.R:
--------------------------------------------------------------------------------
1 | library(lavaan)
2 | test_that("pseudo_class works", {
3 | testthat::skip_if_not_installed("OpenMx")
4 | testthat::skip_if_not_installed("mice")
5 | dat <- iris[,c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")]
6 | colnames(dat) <- c("SL", "SW", "PL", "PW")
7 | fit <- mx_profiles(data = dat, classes = 3)
8 |
9 | pct_lm <- pseudo_class(x = fit,
10 | model = lm( SL ~ class, data = data ),
11 | data = dat)
12 |
13 | pct_lv <- pseudo_class(x = fit,
14 | model = sem( "SL ~ class", data = data),
15 | df_complete = nrow(dat) - 1,
16 | data = dat)
17 |
18 | pct_mx <- pseudo_class(x = fit,
19 | model = "SL ~ class",
20 | df_complete = nrow(x) - 1,
21 | data = dat)
22 |
23 | overlapping_terms <- c(pct_lv$term, pct_mx$term)
24 | overlapping_terms <- overlapping_terms[duplicated(overlapping_terms)]
25 |
26 | stopifnot(length(overlapping_terms) == 2)
27 |
28 | lv_results <- pct_lv[pct_lv$term %in% overlapping_terms, c("estimate", "se")]
29 | mx_results <- pct_mx[pct_mx$term %in% overlapping_terms, c("estimate", "se")]
30 |
31 | expect_equivalent(lv_results$estimate, mx_results$estimate, tolerance = .01)
32 | expect_equivalent(lv_results$se, mx_results$se, tolerance = .01)
33 |
34 |
35 | lm_results <- unlist(pct_lm[pct_lm$term == "class", c("estimate", "std.error"), drop = TRUE])
36 | lm_specific_lv_results <- unlist(pct_lv[pct_lv$term == "SL ~ class", c("estimate", "se"), drop = TRUE])
37 |
38 | expect_equivalent(lm_results, lm_specific_lv_results, tolerance = .01)
39 | })
40 |
--------------------------------------------------------------------------------
/tests/testthat/test-results_digits.R:
--------------------------------------------------------------------------------
1 | library(lavaan)
2 | library(MplusAutomation)
3 |
4 | test_that("digits are respected in table_results", {
5 |
6 | fit <- sem("mpg ~ cyl\nmpg ~ am", data = mtcars)
7 | expect_error(table_results(fit), NA)
8 |
9 | out <- table_results(fit, columns = c("label", "est_std", "confint"), digits = 3)
10 | expect_equivalent(sapply(out, function(x){max(nchar(x))}), c(13, 6, 16))
11 |
12 |
13 | if(isTRUE(getOption("test_mplus"))){
14 | the_test <- "digits"
15 | old_wd <- getwd()
16 | test_dir <- file.path(tempdir(), the_test)
17 | dir.create(test_dir)
18 | setwd(test_dir)
19 | on.exit({unlink(test_dir, recursive = TRUE); setwd(old_wd)}, add = TRUE)
20 |
21 | res_mplus <- mplusModeler(mplusObject(MODEL = "mpg ON cyl am;", OUTPUT = "standardized;", rdata = mtcars), modelout = "test.inp", run = 1L)
22 | expect_error(table_results(res_mplus), NA)
23 | out <- table_results(res_mplus, columns = c("label", "est_std", "confint"), digits = 1)
24 | expect_equivalent(sapply(out, function(x){max(nchar(x))}), c(22, 4, 12))
25 |
26 | }
27 | })
28 |
--------------------------------------------------------------------------------
/tests/testthat/test-results_has_pval.R:
--------------------------------------------------------------------------------
1 | library(lavaan)
2 | library(tidySEM)
3 | library(MplusAutomation)
4 |
5 | test_that("table_results has pval", {
6 | the_test <- "has_pval"
7 | old_wd <- getwd()
8 | test_dir <- file.path(tempdir(), the_test)
9 | dir.create(test_dir)
10 | setwd(test_dir)
11 | on.exit({unlink(test_dir, recursive = TRUE); setwd(old_wd)}, add = TRUE)
12 |
13 | fit <- sem("mpg ~ cyl\nmpg ~ am", data = mtcars)
14 |
15 | expect_equivalent(table_results(fit, columns = c("pval"))$pval[1:3], c("0.00", "0.04", "0.00"))
16 |
17 | if(isTRUE(getOption("test_mplus"))){
18 | res_mplus <- mplusModeler(mplusObject(MODEL = "mpg ON cyl am;", OUTPUT = "standardized;", rdata = mtcars), modelout = "test.inp", run = 1L)
19 |
20 | expect_equivalent(table_results(res_mplus, columns = c("pval"))$pval[1:3], c("0.00", "0.04", "0.00"))
21 | }
22 | })
23 |
--------------------------------------------------------------------------------
/tests/testthat/test-results_labels.R:
--------------------------------------------------------------------------------
1 | library(tidySEM)
2 | library(lavaan)
3 |
4 | fit <- sem("mpg ~ a * am", data = mtcars)
5 | tmp <- table_results(fit, columns = NULL)
6 |
7 | test_that("table_results() returns all labels", {
8 | expect_true(all(c("lavaan_label", "label") %in% names(tmp)))
9 | expect_true(tmp$lavaan_label[1] == "a")
10 | })
11 |
12 |
13 |
14 | df <- HolzingerSwineford1939
15 |
16 | names(df)[grepl("^x", names(df))] <- c("vis_1", "vis_2", "vis_3", "tex_1", "tex_2", "tex_3", "spe_1", "spe_2", "spe_3")
17 | dict <- tidy_sem(df)
18 |
19 | expect_true(all(dict$dictionary$scale[-c(1:6)] == rep(c("vis", "tex", "spe"), each = 3)))
20 |
21 | measurement(dict, meanstructure = TRUE) -> model
22 |
23 | res_lav <- sem(as_lavaan(model), data = df)
24 |
25 | tb_lav <- table_results(res_lav, columns = NULL)
26 | expect_true(nrow(tb_lav) == 36)
27 |
28 | if(isTRUE(getOption("test_mplus"))){
29 | test_that("table_results() returns all labels for mplus", {
30 | the_test <- "mplus_labels"
31 | old_wd <- getwd()
32 | test_dir <- file.path(tempdir(), the_test)
33 | dir.create(test_dir)
34 | setwd(test_dir)
35 | on.exit({unlink(test_dir, recursive = TRUE); setwd(old_wd)}, add = TRUE)
36 |
37 | res_mplus <- mplusModeler(mplusObject(MODEL = "mpg ON am (a);", OUTPUT = "standardized;", rdata = mtcars), modelout = "test.inp", run = 1L)
38 |
39 | tb_mplus <- table_results(res_mplus, columns = NULL)
40 |
41 | expect_true("label" %in% names(tmp))
42 | })
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/tests/testthat/test-syntax_categorical.R:
--------------------------------------------------------------------------------
1 | if(FALSE){
2 |
3 |
4 | set.seed(1)
5 |
6 | data("jointdata", package ="OpenMx")
7 |
8 | jointdata[,c(2,4,5)] <-
9 | mxFactor(jointdata[,c(2,4,5)],
10 | levels=list(c(0,1), c(0, 1, 2, 3), c(0, 1, 2)))
11 |
12 | jointdata$extra <- rnorm(nrow(jointdata))
13 |
14 | m1 <- mxModel(
15 | "m1", type="RAM",
16 | manifestVars = paste0('z',sample.int(5,5)),
17 | latentVars='G',
18 | mxData(jointdata[,sample.int(5,5)], "raw", verbose=0L),
19 | mxPath('one', paste0('z', c(1,3))),
20 | mxPath(paste0('z', c(1,3)), arrows=2, values=2),
21 | mxPath(paste0('z', c(2,4,5)), arrows=2, free=FALSE, values=.5),
22 | mxPath('G', arrows=2, values=1, free=FALSE),
23 | mxPath('G', paste0('z', 1:5), values=1),
24 | mxMarginalProbit(paste0('z', c(2,5)), nThresh=c(1,2), free=TRUE),
25 | mxMarginalPoisson('z4', lambda = .5))
26 |
27 | mxMargin
28 | summary(m1)
29 | m1 <- mxRun(m1)
30 | m1$Thresholds
31 |
32 | HS9 <- HolzingerSwineford1939[,c("x1","x2","x3","x4","x5", "x6","x7","x8","x9")]
33 | HSbinary <- data.frame(lapply(cbind(data.frame( lapply(HS9[c(1,4)], cut, 2, labels=FALSE)),
34 | data.frame( lapply(HS9[c(2,3,5,6,7)], cut, 3, labels=FALSE)),
35 | data.frame( lapply(HS9[c(8:9)], cut, 4, labels=FALSE))), as.ordered))
36 |
37 | model <- ' visual =~ x1 + x2 + x3
38 | textual =~ x4 + x5 + x6
39 | speed =~ x7 + x8 + x9
40 | x8 | NA*t1
41 | x8 | NA*t2
42 | x8 | a*t3
43 | x9 | NA*t1
44 | x9 | NA*t2
45 | x9 | a*t3'
46 |
47 | lavaanify(model)
48 |
49 | names(HSbinary) <- paste0(rep(c("vis", "tex", "spd"), each = 3), "_", 1:3)
50 | tmp <- tidy_sem(HSbinary)
51 | tmp$dictionary$type <- "cat"
52 | tmp <- measurement(tmp)
53 | tmp$syntax
54 | HS <- data.frame(lapply(HolzingerSwineford1939[paste0("x", 1:9)], function(i){ordered(cut(i, 2))}))
55 | mod_simple <- ' visual =~ x1 + x2 + x3
56 | textual =~ x4 + x5 + x6
57 | speed =~ x7 + x8 + x9'
58 |
59 | res <- run_mx(as_ram(mod_simple, data = HS), data = HS)
60 |
61 | mod_thres <- ' visual =~ x1 + x2 + x3
62 | textual =~ x4 + x5 + x6
63 | speed =~ x7 + x8 + x9
64 | x8 | a*t3
65 | x9 | a*t3'
66 |
67 | as_ram(mod_thres, data = HSbinary)
68 |
69 |
70 |
71 | fit <- cfa(model, data=HSbinary, ordered=names(HSbinary))
72 | summary(fit, fit.measures=TRUE)
73 | }
74 |
--------------------------------------------------------------------------------
/tests/testthat/test-syntax_cfa_mplus_lavaan.R:
--------------------------------------------------------------------------------
1 | library(lavaan)
2 | library(MplusAutomation)
3 |
4 | test_that("CFA gives same results in lavaan and Mplus", {
5 | the_test <- "compare_mplus_lavaan"
6 | old_wd <- getwd()
7 | test_dir <- file.path(tempdir(), the_test)
8 | dir.create(test_dir)
9 | setwd(test_dir)
10 | on.exit({unlink(test_dir, recursive = TRUE); setwd(old_wd)}, add = TRUE)
11 |
12 | df <- HolzingerSwineford1939
13 |
14 | names(df)[grepl("^x", names(df))] <- c("vis_1", "vis_2", "vis_3", "tex_1", "tex_2", "tex_3", "spe_1", "spe_2", "spe_3")
15 | dict <- tidy_sem(df)
16 |
17 | expect_true(all(dict$dictionary$scale[-c(1:6)] == rep(c("vis", "tex", "spe"), each = 3)))
18 |
19 | measurement(dict, meanstructure = TRUE) -> model
20 |
21 | res_lav <- sem(as_lavaan(model), data = df)
22 |
23 | tb_lav <- table_results(res_lav, columns = NULL)
24 | expect_true(nrow(tb_lav) == 36)
25 |
26 | if(isTRUE(getOption("test_mplus"))){
27 | res_mplus <- mplusModeler(mplusObject(MODEL = as_mplus(model), OUTPUT = "standardized;", rdata = df), modelout = "test.inp", run = 1L)
28 |
29 | tb_mplus <- table_results(res_mplus, columns = NULL)
30 |
31 |
32 | expect_true(all(gsub("^intercepts", "means", gsub("^residual.", "", tolower(tb_mplus$label))) %in% tolower(tb_lav$label)))
33 |
34 |
35 | }
36 | })
37 |
--------------------------------------------------------------------------------
/tests/testthat/test-syntax_same_sem_addpaths.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(tidySEM)
3 | library(dplyr)
4 | df <- PoliticalDemocracy
5 | names(df)[match(c("x1", "x2", "x3", "y1", "y2", "y3", "y4", "y5", "y6", "y7", "y8"), names(df))] <- c(paste0("ind_", 1:3), paste0("dem60_", 1:4), paste0("dem65_", 1:4))
6 | model <- '
7 | # measurement model
8 | ind =~ ind_1 + ind_2 + ind_3
9 | dem60 =~ dem60_1 + dem60_2 + dem60_3 + dem60_4
10 | dem65 =~ dem65_1 + dem65_2 + dem65_3 + dem65_4'
11 |
12 |
13 | fit <- sem(model, data=df)
14 |
15 |
16 |
17 | df %>%
18 | tidy_sem() %>%
19 | measurement() -> model_tidy
20 |
21 | fit2 <- sem(model_tidy$syntax, df)
22 |
23 | test_that("Lavaan and measurement return same result", {
24 | expect_true((fitmeasures(fit)["chisq"] - fitmeasures(fit2)["chisq"]) < .001)
25 | })
26 |
27 |
28 | model_reg <- '
29 | # measurement model
30 | ind =~ ind_1 + ind_2 + ind_3
31 | dem60 =~ dem60_1 + dem60_2 + dem60_3 + dem60_4
32 | dem65 =~ dem65_1 + dem65_2 + dem65_3 + dem65_4
33 | dem60 ~ ind
34 | dem65 ~ ind + dem60'
35 |
36 | fit_reg <- sem(model_reg, data=df)
37 |
38 | model_tidy %>%
39 | add_paths("dem60 ~ ind",
40 | "dem65 ~ ind + dem60") -> mod_tidy_reg
41 |
42 | fit_reg_tidy <- sem(mod_tidy_reg$syntax, df)
43 |
44 | test_that("Lavaan and measurement return same result", {
45 | expect_true((fitmeasures(fit_reg)["chisq"] - fitmeasures(fit_reg_tidy)["chisq"]) < .001)
46 | })
47 |
--------------------------------------------------------------------------------
/tests/testthat/test-tidyLPA_and_SEM_coexist.R:
--------------------------------------------------------------------------------
1 | if(FALSE){
2 | library(tidySEM)
3 | library(tidyLPA)
4 | df <- iris[1:3]
5 | names(df) <- letters[1:3]
6 | res <- tidyLPA::estimate_profiles(df, 2)
7 | test_that("tidyLPA and tidySEM can coexist with similarly named methods", {
8 | expect_error(plot_profiles(res), NA)
9 | expect_error(plot_density(res), NA)
10 | expect_error(suppressWarnings(tidyLPA:::plot_bivariate.tidyProfile(res)), NA)
11 | })
12 |
13 | res <- mx_profiles(df, 2)
14 | test_that("tidyLPA and tidySEM can coexist with similarly named methods", {
15 | expect_error(plot_profiles(res), NA)
16 | expect_error(plot_density(res), NA)
17 | expect_error(suppressWarnings(plot_bivariate(res)), NA)
18 | })
19 | }
20 |
--------------------------------------------------------------------------------
/tests/testthat/test-tidy_sem_lavaan_cfa_same.R:
--------------------------------------------------------------------------------
1 | library(lavaan)
2 | df <- HolzingerSwineford1939
3 | names(df)[grepl("^x", names(df))] <- c("vis_1", "vis_2", "vis_3", "tex_1", "tex_2", "tex_3", "spe_1", "spe_2", "spe_3")
4 |
5 | mod <- "vis =~ vis_1 + vis_2 + vis_3
6 | tex =~ tex_1 + tex_2 + tex_3
7 | spe =~ spe_1 + spe_2 + spe_3"
8 |
9 | res1 <- lavaan::sem(mod, data = df, meanstructure = TRUE)
10 |
11 | mod_ts <- measurement(tidy_sem(df))
12 | res2 <- sem(as_lavaan(mod_ts), data = df)
13 |
14 | pt1 <- parTable(res1)
15 | pt2 <- parTable(res2)
16 |
17 | test_that("All parameters the same", {
18 | expect_true(all(do.call(paste0, pt1[, 2:4]) %in% do.call(paste0, pt2[, 2:4])))
19 | expect_true(all(do.call(paste0, pt2[, 2:4]) %in% do.call(paste0, pt1[, 2:4])))
20 |
21 | expect_true(all(do.call(paste0, pt1[!pt1$free == 0, 2:4]) %in% do.call(paste0, pt2[!pt2$free == 0, 2:4])))
22 | expect_true(all(do.call(paste0, pt2[!pt2$free == 0, 2:4]) %in% do.call(paste0, pt1[!pt1$free == 0, 2:4])))
23 | })
24 |
25 |
--------------------------------------------------------------------------------
/tidySEM.Rproj:
--------------------------------------------------------------------------------
1 | Version: 1.0
2 | ProjectId: 661cd1c0-211f-4666-bc66-756af619e6a8
3 |
4 | RestoreWorkspace: Default
5 | SaveWorkspace: Default
6 | AlwaysSaveHistory: Default
7 |
8 | EnableCodeIndexing: Yes
9 | UseSpacesForTab: Yes
10 | NumSpacesForTab: 2
11 | Encoding: UTF-8
12 |
13 | RnwWeave: Sweave
14 | LaTeX: pdfLaTeX
15 |
16 | AutoAppendNewline: Yes
17 | StripTrailingWhitespace: Yes
18 |
19 | BuildType: Package
20 | PackageUseDevtools: Yes
21 | PackageInstallArgs: --no-multiarch --with-keep.source
22 | PackageRoxygenize: rd,collate,namespace,vignette
23 |
--------------------------------------------------------------------------------
/vignettes/.gitignore:
--------------------------------------------------------------------------------
1 | *.html
2 | *.R
3 | !tabres_1.R
4 | !mplusfit.R
5 | !run_everything.txt
6 | !pkgdown.txt
7 | !lcga_fit.RData
8 | !lcga_tab_res.csv
9 | !lcga_wald_tests.csv
10 | !lpatablmr.csv
11 |
--------------------------------------------------------------------------------
/vignettes/appendixbresblrt.csv:
--------------------------------------------------------------------------------
1 | "null","alt","lr","df","blrt_p","samples"
2 | "mix1","mix2",421.233643742685,5,0,20
3 | "mix2","mix3",160.031935739323,5,0,20
4 | "mix3","mix4",70.1913899054475,5,0,20
5 | "mix4","mix5",7.76605689139615,5,0.3,20
6 |
--------------------------------------------------------------------------------
/vignettes/gmm_aux_pt.RData:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/gmm_aux_pt.RData
--------------------------------------------------------------------------------
/vignettes/gmm_bivariate_bic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/gmm_bivariate_bic.png
--------------------------------------------------------------------------------
/vignettes/gmm_plotfit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/gmm_plotfit.png
--------------------------------------------------------------------------------
/vignettes/gmm_results.csv:
--------------------------------------------------------------------------------
1 | "label","est"
2 | "Means.length","0.65"
3 | "Means.width","0.34"
4 | "Variances.length","0.10"
5 | "Covariances.length.WITH.width","0.09"
6 | "Variances.width","0.10"
7 | "Means.length","1.33"
8 | "Means.width","0.86"
9 | "Variances.length","0.19"
10 | "Covariances.length.WITH.width","0.20"
11 | "Variances.width","0.28"
12 | "mix2.weights[1,1]","1.00"
13 | "mix2.weights[1,2]","0.75"
14 |
--------------------------------------------------------------------------------
/vignettes/gmm_tabfit.csv:
--------------------------------------------------------------------------------
1 | "Name","Classes","LL","n","Parameters","AIC","BIC","saBIC","Entropy","prob_min","prob_max","n_min","n_max","np_ratio","np_local"
2 | "equal var, equal cov 1",1,-3388.56053870426,5605,5,6787.12107740853,6820.27814908606,6804.38966373741,1,1,1,1,1,1121,1121
3 | "equal var, equal cov 2",2,-3082.30644910367,5605,8,6180.61289820734,6233.66421289139,6208.24263633355,0.723103934740247,0.860956970147751,0.946869250095599,0.308474576271186,0.691525423728814,700.625,494
4 | "equal var, equal cov 3",3,-3030.09572231826,5605,11,6082.19144463652,6155.13700232708,6120.18233456005,0.66870155104001,0.714606859881928,0.925497935346214,0.167707404103479,0.555932203389831,509.545454545455,313.333333333333
5 | "free var, equal cov 1",1,-3388.56053870426,5605,5,6787.12107740853,6820.27814908606,6804.38966373741,1,1,1,1,1,1121,1121
6 | "free var, equal cov 2",2,-2544.73655105547,5605,10,5109.47310211093,5175.787245466,5144.01027476869,0.641550751791187,0.50989522659159,0.984879681267885,0.0865298840321142,0.913470115967886,560.5,107.777777777778
7 | "free var, equal cov 3",3,-2256.94623819348,5605,15,4543.89247638696,4643.36369141955,4595.69823537359,0.682409652970874,0.543304366340314,0.937057057165197,0.064049955396967,0.63764495985727,373.666666666667,82.8461538461539
8 | "equal var, free cov 1",1,-3388.56053870426,5605,5,6787.12107740853,6820.27814908606,6804.38966373741,1,1,1,1,1,1121,1121
9 | "equal var, free cov 2",2,-2551.86048083346,5605,9,5121.72096166692,5181.40369068648,5152.8044170589,0.648732086823922,0.517947239533194,0.984998062225818,0.0865298840321142,0.913470115967886,622.777777777778,121.25
10 | "equal var, free cov 3",3,-2367.85626986026,5605,13,4761.71253972052,4847.9209260821,4806.6108641756,0.556901785214115,0.508274806378739,0.912775199603418,0.0178412132024978,0.658697591436218,431.153846153846,27.2727272727273
11 | "free var, free cov 1",1,-3388.56053870426,5605,5,6787.12107740853,6820.27814908606,6804.38966373741,1,1,1,1,1,1121,1121
12 | "free var, free cov 2",2,-2574.87094758677,5605,11,5171.74189517354,5244.68745286411,5209.73278509708,0.556542152565665,0.813665019421944,0.913207509946542,0.3992863514719,0.6007136485281,509.545454545455,447.6
13 | "free var, free cov 3",3,-2111.38085915731,5605,17,4256.76171831462,4369.49576201823,4315.47491183281,0.653862059395143,0.510366343566759,0.876843987066316,0.0363960749330954,0.555218554861731,329.705882352941,40.8
14 |
--------------------------------------------------------------------------------
/vignettes/lca_desc.csv:
--------------------------------------------------------------------------------
1 | "name","type","n","missing","unique","mode","mode_value","v"
2 | "Ethnic_1","ordered, factor",439,0,6,269,"5",0.533963605419233
3 | "Ethnic_2","ordered, factor",439,0,6,272,"5",0.521199039025327
4 | "Ethnic_3","ordered, factor",439,0,6,262,"5",0.543677129114108
5 | "Belgian","ordered, factor",439,0,11,88,"7",0.858235480305727
6 | "Flemish","ordered, factor",439,0,11,90,"7",0.866765946627508
7 |
--------------------------------------------------------------------------------
/vignettes/lca_fit.csv:
--------------------------------------------------------------------------------
1 | "Name","Classes","LL","n","Parameters","AIC","BIC","saBIC","Entropy","prob_min","prob_max","n_min","n_max","np_ratio","np_local"
2 | "1",1,-3075.53103809311,439,30,6211.06207618621,6333.59705857847,6238.39180753918,1,1,1,1,1,14.6333333333333,14.6333333333333
3 | "2",2,-2849.36729677621,439,61,5820.73459355243,6069.88905775001,5876.30504730346,0.887963489567058,0.961573712539445,0.985451848406681,0.460136674259681,0.539863325740319,7.19672131147541,6.73333333333333
4 | "3",3,-2747.23967319944,439,92,5678.47934639888,6054.25329240179,5762.29052254798,0.926552501474133,0.938920202628457,0.988829671544761,0.150341685649203,0.52619589977221,4.77173913043478,2.2
5 | "4",4,-2659.01333054755,439,123,5564.02666109509,6066.42008890334,5676.07855964226,0.930456009618725,0.937975283579601,0.975526660453861,0.109339407744875,0.332574031890661,3.56910569105691,1.6
6 | "5",5,-2618.51857810467,439,154,5545.03715620935,6174.05006582292,5685.32977715458,0.947960386921234,0.956649248992114,0.999999999999767,0.100227790432802,0.348519362186788,2.85064935064935,1.46666666666667
7 | "6",6,-2577.76360792023,439,185,5525.52721584045,6281.15960725936,5694.06055918375,0.924888475485487,0.944155108414728,0.965508410942944,0.100227790432802,0.289293849658314,2.37297297297297,1.46666666666667
8 |
--------------------------------------------------------------------------------
/vignettes/lca_plot_desc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/lca_plot_desc.png
--------------------------------------------------------------------------------
/vignettes/lca_prob.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/lca_prob.png
--------------------------------------------------------------------------------
/vignettes/lca_res.RData:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/lca_res.RData
--------------------------------------------------------------------------------
/vignettes/lcga_fit.csv:
--------------------------------------------------------------------------------
1 | "Name","Classes","LL","n","Parameters","AIC","BIC","saBIC","Entropy","prob_min","prob_max","n_min","n_max","np_ratio","np_local"
2 | "1",1,2593.45206433169,978,9,-5168.90412866337,-5124.93454163306,-5153.51863999152,1,1,1,1,1,108.666666666667,108.666666666667
3 | "2",2,3875.58713484171,978,13,-7725.17426968341,-7661.66264397296,-7702.9507860463,0.94351568093713,0.966106928274199,0.989780274930564,0.244376278118609,0.755623721881391,75.2307692307692,39.8333333333333
4 | "3",3,4173.55026625932,978,17,-8313.10053251864,-8230.04686812805,-8284.03905391626,0.9262505572943,0.931653831467919,0.981343065260665,0.0644171779141104,0.679959100204499,57.5294117647059,12.6
5 | "4",4,4278.29739685106,978,21,-8514.59479370211,-8411.99909063138,-8478.69532013446,0.888994966996624,0.853368029947373,0.970952384464153,0.0368098159509202,0.620654396728016,46.5714285714286,8
6 | "5",5,4314.66839781618,978,25,-8579.33679563237,-8457.1990538815,-8536.59932709945,0.863709438308627,0.727184758772401,0.964821475088827,0.0408997955010225,0.587934560327198,39.12,9.52380952380952
7 |
--------------------------------------------------------------------------------
/vignettes/lcga_plot_fit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/lcga_plot_fit.png
--------------------------------------------------------------------------------
/vignettes/lcga_wald_tests.csv:
--------------------------------------------------------------------------------
1 | "Hypothesis","df","chisq","p"
2 | "Mean i",2,467.856962353796,2.54771864189546e-102
3 | "Mean step",2,69.3473812044565,8.73790873335339e-16
4 | "Mean slope",2,13.4467115558838,0.00120249612560228
5 |
--------------------------------------------------------------------------------
/vignettes/lpa_aux_model.RData:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/lpa_aux_model.RData
--------------------------------------------------------------------------------
/vignettes/lpa_aux_sex.RData:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/lpa_aux_sex.RData
--------------------------------------------------------------------------------
/vignettes/lpa_bivariate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/lpa_bivariate.png
--------------------------------------------------------------------------------
/vignettes/lpa_fit_compare.csv:
--------------------------------------------------------------------------------
1 | "Name","Classes","LL","n","Parameters","AIC","BIC","saBIC","Entropy","prob_min","prob_max","n_min","n_max","warning","np_ratio","np_local"
2 | "1",4,-1916.25349072508,513,23,3878.50698145017,3976.0333258891,3903.02758206743,0.754865828099863,0.814211637697702,0.915192606341117,0.155945419103314,0.34307992202729,NA,22.304347826087,16
3 | "2",4,111.618202638083,17,35,-153.236405276166,-124.073938234198,-231.412925067519,0.999999410332884,0.999999821716852,1,0.176470588235294,0.352941176470588,TRUE,0.485714285714286,0.375
4 |
--------------------------------------------------------------------------------
/vignettes/lpa_profiles.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/lpa_profiles.png
--------------------------------------------------------------------------------
/vignettes/lpa_tab_res.csv:
--------------------------------------------------------------------------------
1 | "label","est","se","confint","class"
2 | "Means.burdened","3.27","0.04","[3.18, 3.36]","class1"
3 | "Means.trapped","1.28","0.05","[1.18, 1.38]","class1"
4 | "Means.negaffect","2.31","0.06","[2.20, 2.42]","class1"
5 | "Means.loneliness","2.73","0.04","[2.64, 2.82]","class1"
6 | "Variances.burdened","0.23","0.02","[0.19, 0.27]","class1"
7 | "Variances.trapped","0.17","0.02","[0.14, 0.20]","class1"
8 | "Variances.negaffect","0.31","0.02","[0.27, 0.36]","class1"
9 | "Variances.loneliness","0.24","0.02","[0.20, 0.28]","class1"
10 | "Means.burdened","3.40","0.06","[3.28, 3.52]","class2"
11 | "Means.trapped","2.27","0.06","[2.15, 2.38]","class2"
12 | "Means.negaffect","2.81","0.06","[2.70, 2.93]","class2"
13 | "Means.loneliness","2.79","0.06","[2.66, 2.91]","class2"
14 | "Means.burdened","4.25","0.07","[4.12, 4.38]","class3"
15 | "Means.trapped","2.67","0.05","[2.58, 2.77]","class3"
16 | "Means.negaffect","2.92","0.06","[2.80, 3.03]","class3"
17 | "Means.loneliness","2.01","0.06","[1.89, 2.14]","class3"
18 | "Means.burdened","2.38","0.06","[2.26, 2.50]","class4"
19 | "Means.trapped","0.38","0.05","[0.28, 0.49]","class4"
20 | "Means.negaffect","1.78","0.07","[1.65, 1.91]","class4"
21 | "Means.loneliness","3.18","0.06","[3.07, 3.30]","class4"
22 | "mix4.weights[1,1]","1.00",NA,NA,NA
23 | "mix4.weights[1,2]","0.86","0.15","[0.56, 1.15]",NA
24 | "mix4.weights[1,3]","0.66","0.11","[0.44, 0.88]",NA
25 | "mix4.weights[1,4]","0.47","0.08","[0.32, 0.63]",NA
26 |
--------------------------------------------------------------------------------
/vignettes/lpatabfit.csv:
--------------------------------------------------------------------------------
1 | "Name","Classes","LL","n","Parameters","AIC","BIC","saBIC","Entropy","prob_min","prob_max","n_min","n_max","np_ratio","np_local"
2 | "equal var 1",1,-2241.98197541881,513,8,4499.96395083762,4533.88615759899,4508.49285540015,1,1,1,1,1,64.125,64.125
3 | "equal var 2",2,-2031.36515354747,513,13,4088.73030709494,4143.85389308216,4102.58977700905,0.740491226365564,0.91160438247409,0.929884515658971,0.419103313840156,0.580896686159844,39.4615384615385,35.8333333333333
4 | "equal var 3",3,-1951.34918567781,513,18,3938.69837135562,4015.02333656869,3957.8884066213,0.77972378314985,0.886099717098898,0.914691269078782,0.187134502923977,0.543859649122807,28.5,18
5 | "equal var 4",4,-1916.25349072508,513,23,3878.50698145017,3976.0333258891,3903.02758206743,0.754865828099863,0.814211637697702,0.915192606341117,0.155945419103314,0.34307992202729,22.304347826087,16
6 | "equal var 5",5,-1912.37046227939,513,28,3880.74092455877,3999.46864822356,3910.59209052762,0.787813919835775,0.81099984641931,0.91559513787854,0.00389863547758285,0.341130604288499,18.3214285714286,0.416666666666667
7 |
--------------------------------------------------------------------------------
/vignettes/lpatablmr.csv:
--------------------------------------------------------------------------------
1 | "null","alt","lr","df","p","w2","p_w2"
2 | "mix1","mix2",10.2464439268374,5,2.22044604925031e-16,0.823611514583856,5.84812787085554e-09
3 | "mix2","mix3",5.30478688025798,5,5.64023546501713e-08,0.443506591587362,4.96286678919322e-07
4 | "mix3","mix4",4.14050800643709,5,0.0000173268756347343,0.140049986248345,0.000239970237812082
5 | "mix4","mix5",0.884265341551457,5,0.188276496466948,0.0375888096035959,0.0000140755036172058
6 |
--------------------------------------------------------------------------------
/vignettes/pkgdown.txt:
--------------------------------------------------------------------------------
1 | FALSE
2 |
--------------------------------------------------------------------------------
/vignettes/plot_dist.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/plot_dist.png
--------------------------------------------------------------------------------
/vignettes/plot_fit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/plot_fit.png
--------------------------------------------------------------------------------
/vignettes/plot_gmm_desc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/plot_gmm_desc.png
--------------------------------------------------------------------------------
/vignettes/plot_gmm_desc_log.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/plot_gmm_desc_log.png
--------------------------------------------------------------------------------
/vignettes/plot_gmm_scatter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/plot_gmm_scatter.png
--------------------------------------------------------------------------------
/vignettes/plot_lpa_desc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/plot_lpa_desc.png
--------------------------------------------------------------------------------
/vignettes/plot_traj.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/plot_traj.png
--------------------------------------------------------------------------------
/vignettes/plot_trans.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/plot_trans.png
--------------------------------------------------------------------------------
/vignettes/res_gmm.RData:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/res_gmm.RData
--------------------------------------------------------------------------------
/vignettes/res_lpa.RData:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/res_lpa.RData
--------------------------------------------------------------------------------
/vignettes/res_step.RData:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/res_step.RData
--------------------------------------------------------------------------------
/vignettes/run_everything.txt:
--------------------------------------------------------------------------------
1 | FALSE
2 |
--------------------------------------------------------------------------------
/vignettes/spreadsheet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjvanlissa/tidySEM/698857abfc8897ac48fb299bc32b01ee076c5980/vignettes/spreadsheet.png
--------------------------------------------------------------------------------