diff --git a/.Rbuildignore b/.Rbuildignore index eb78e23..0f76123 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -3,3 +3,4 @@ ^_pkgdown\.yml$ ^docs$ ^pkgdown$ +^scratch$ diff --git a/DESCRIPTION b/DESCRIPTION index e63e619..9e4769a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -40,7 +40,7 @@ LinkingTo: RcppEigen Description: Applies dynamic structural equation models to time-series data with generic and simplified specification for simultaneous and lagged - effects. Methods are described in Thorson et al. (In revision) + effects. Methods are described in Thorson et al. (In press) "Dynamic structural equation models synthesize ecosystem dynamics constrained by ecological mechanisms." License: GPL-3 diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..51f8702 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,8 @@ +# dsem 1.0.1 + +* Fix bug in `simulate.dsem` to keep up with changing interface in `dsem` +* Update CITATION to indicate accepted paper + +# dsem 1.0.0 + +* Initial public release diff --git a/R/dsem.R b/R/dsem.R index d311129..11a0216 100644 --- a/R/dsem.R +++ b/R/dsem.R @@ -442,10 +442,12 @@ function( object, tmp = rmvnorm_prec( newrep$delta_k + as.vector(newrep$xhat_tj), Q_kk, nsim=1 ) # Modify call newcall = object$call - newcall$parameters = newparfull - newcall$parameters$x_tj[] = tmp + # Get control + newcall$control = eval(newcall$control) + newcall$control$parameters = newparfull + newcall$control$parameters$x_tj[] = tmp # Rebuild model with new GMRF values - newcall$run_model = FALSE + newcall$control$run_model = FALSE newfit = eval(newcall) out[[r]] = newfit$obj$simulate()$y_tj }else{ diff --git a/README.md b/README.md index dc70f77..54dc8ce 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,28 @@ -# dsem -Dynamic structural equation models. - -[![](https://cranlogs.r-pkg.org/badges/dsem)](https://cran.r-project.org/package=dsem) - -[![DOI](https://zenodo.org/badge/656795688.svg)](https://zenodo.org/doi/10.5281/zenodo.10304770) - ## Dynamic structural equation models Package _dsem_ fits dynamic structural equation models, which includes as nested submodels: -* structural equation models -* vector autoregressive models -* dynamic factor analysis -* state-space autoregressive integrated moving average (ARIMA) models + +1. structural equation models +2. vector autoregressive models +3. dynamic factor analysis +4. state-space autoregressive integrated moving average (ARIMA) models The model has several advantages: -* It estimates direct, indirect, and total effects among system variables -* It can estimate the cumulative outcome from press or pulse experiments or initial conditions -* It jointly estimates structural linkages and imputes missing values -* It is rapidly fitted as a Gaussian Markov random field (GMRF) in a Generalized Linear Mixed Model (GLMM), with speed and asymptotics associated with each. -_phylosem_ is specifically intended as a minimal implementation, and uses standard packages for input/output formatting: +* It estimates direct, indirect, and total effects among system variables, including simultaneous and lagged effects and recursive (cyclic) dependencies +* It can estimate the cumulative outcome from press or pulse experiments or initial conditions that differ from the stationary distribution of system dynamics +* It estimates structural linkages as regression slopes while jointly imputing missing values and/or measurement errors +* It is rapidly fitted as a Gaussian Markov random field (GMRF) in a Generalized Linear Mixed Model (GLMM), with speed and asymptotics associated with each +* It allows granular control over the number of parameters (and restrictions on parameters) used to structure the covariance among variables and over time, + +_phylosem_ is specifically intended as a minimal implementation, and uses standard packages to simplify input/output formatting: + * Input: time-series defined using class _ts_, with `NA` for missing values * Input: structural trade-offs specified using syntax defined by package _sem_ * Output: visualizing estimated trade-offs using _igraph_ -* Output: access model output using standard S3-generic functions including `summary`, `predict`, `residuals`, and `simulate` +* Output: access model output using standard S3-generic functions including `summary`, `predict`, `residuals`, `simulate`, and `AIC` Please see package vignettes for more details regarding syntax and features. + +[![](https://cranlogs.r-pkg.org/badges/dsem)](https://cran.r-project.org/package=dsem) + +[![DOI](https://zenodo.org/badge/656795688.svg)](https://zenodo.org/doi/10.5281/zenodo.10304770) diff --git a/inst/CITATION b/inst/CITATION new file mode 100644 index 0000000..235b730 --- /dev/null +++ b/inst/CITATION @@ -0,0 +1,15 @@ +citHeader("For methodological details regarding dynamic structural equation models, please see Thorson et al. (2024).") + +bibentry(bibtype = "Article", + textVersion = "Thorson, J. T., Andrews, A. G., Essington, T., & Large, S. (In press). Dynamic structural equation models synthesize ecosystem dynamics constrained by ecological mechanisms. Methods in Ecology and Evolution.", + title = "Dynamic structural equation models synthesize ecosystem dynamics constrained by ecological mechanisms", + journal = "Methods in Ecology and Evolution", + year = "2024", + author = c(person(given = c("J.", "T."), + family = "Thorson"), + person(given = c("A.", "G."), + family = "Andrews"), + person(given = "T.", + family = "Essington"), + person(given = "S.", + family = "Large"))) \ No newline at end of file diff --git a/scratch/Upload_to_CRAN.R b/scratch/Upload_to_CRAN.R new file mode 100644 index 0000000..bd7ad17 --- /dev/null +++ b/scratch/Upload_to_CRAN.R @@ -0,0 +1,72 @@ + +root_dir = R'(C:\Users\James.Thorson\Desktop\Work files\Collaborations\2023 -- DSEM\CRAN submission)' + +library(devtools) +setwd( R'(C:\Users\James.Thorson\Desktop\Git\dsem)' ) + +# Compile +if( FALSE ){ + document() +} + +# Test install +install_local(force=TRUE, dep=TRUE, build_vignettes=TRUE, upgrade=FALSE) +#install_local(force=TRUE, dep=TRUE, build_vignettes=FALSE, upgrade=FALSE) +browseVignettes("dsem") + +# +if( FALSE ){ + library(TMB) + setwd( R'(C:\Users\James.Thorson\Desktop\Git\dsem\src)' ) + compile("dsem.cpp") +} + +# Try building vignetttes +if( FALSE ){ + library(rmarkdown) + setwd( R'(C:\Users\James.Thorson\Desktop\Git\dsem\vignettes)' ) + devtools::build_rmd("vignettes/vignette.Rmd") + render( file.path(getwd(),"vignette.Rmd"), pdf_document()) +} + +# Try mapping dependencies +if( FALSE ){ + # Simple way + library(renv) + x = dependencies() + + # Listed dependencies + tools::package_dependencies("dsem") + tools::package_dependencies("dynlm") + + # All + pack <- available.packages() + pack["dynlm","Depends"] + packrat:::recursivePackageDependencies("dynlm", ignore = "", lib.loc = .libPaths()[1], fields="Imports") +} + +# Run checks ... doesn't seem to work +file.remove( file.path("vignettes","vignette.pdf") ) +#check( remote = TRUE, manual=TRUE ) +check( manual=TRUE ) + +# Check manual +if( FALSE ){ + tools::texi2pdf +} + +# Check online but document first! +document() +check_win_devel() + +# Submit to CRAN via devtools .. not preferred! +if( FALSE ){ + file.remove( file.path("vignettes","vignette.pdf") ) + release() +} + +# Build for uploading via web interface +# https://cran.r-project.org/submit.html +build( path=root_dir, manual=TRUE ) + + diff --git a/scratch/build_pkgdown_website.R b/scratch/build_pkgdown_website.R new file mode 100644 index 0000000..e242872 --- /dev/null +++ b/scratch/build_pkgdown_website.R @@ -0,0 +1,39 @@ +# Author: Kevin See +# Purpose: Build a website for this package using pkgdown +# Created: 5/17/2021 +# Last Modified: 5/17/2021 +# Notes: Based on instructions found here: https://pkgdown.r-lib.org/index.html + +setwd(R'(C:\Users\James.Thorson\Desktop\Git\dsem)') + +#----------------------------------------------------------------- +# load needed libraries +library(pkgdown) + + +# Only needed once +if( FALSE ){ + # set up to automatically publish pkgdown site to GitHub + # usethis::create_github_token() + # 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 + # gitcreds::gitcreds_set(url = "https://github.com") + usethis::use_pkgdown_github_pages() + + + # Run once to configure your package to use pkgdown + usethis::use_pkgdown() + + # check that _pkgdown.yml looks good + pkgdown::check_pkgdown() +} + +# Run to build the website +pkgdown::build_site( examples=TRUE ) +# build_articles( lazy = FALSE ) + +# to look at the site +pkgdown::preview_site() + +#----------------------------------------------------------------- +# deploy site to gh-pages branch on GitHub +pkgdown::deploy_to_branch()