Skip to content

Commit

Permalink
Fix bug in simulate.dsem ..
Browse files Browse the repository at this point in the history
... to keep up with improved interface in `dsem`
  • Loading branch information
James-Thorson committed Jan 4, 2024
1 parent 54b879f commit f5583ed
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 21 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
^_pkgdown\.yml$
^docs$
^pkgdown$
^scratch$
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
8 changes: 5 additions & 3 deletions R/dsem.R
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 15 additions & 0 deletions inst/CITATION
Original file line number Diff line number Diff line change
@@ -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")))
72 changes: 72 additions & 0 deletions scratch/Upload_to_CRAN.R
Original file line number Diff line number Diff line change
@@ -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 )


39 changes: 39 additions & 0 deletions scratch/build_pkgdown_website.R
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit f5583ed

Please sign in to comment.