Skip to content

Commit

Permalink
Dev (#396)
Browse files Browse the repository at this point in the history
* Update DESCRIPTION

* Update DESCRIPTION

* Update R-CMD-check.yml

* Update R-CMD-check.yml

* try removing ThorsonUtilities

* Update R-CMD-check.yml

* try to make Actions happy

* try at getting INLA dependency to work in Actions

* Update test-zeroinfl-against-pscl.R

* another attempt at making R_CMD_check happy

* another attempt

* another attempt

* another attempt

* another attempt

* another attempt

* remove Linux from github Actions

* update NEWS

* Update test-multi-species-examples.R

---------

Co-authored-by: Jim Thorson <James.T.Thorson@gmail.com>
  • Loading branch information
James-Thorson-NOAA and James-Thorson authored Jan 17, 2025
1 parent 395970d commit 431621f
Show file tree
Hide file tree
Showing 18 changed files with 97 additions and 26 deletions.
17 changes: 4 additions & 13 deletions .github/workflows/R-CMD-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,20 @@ jobs:
config:
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@master
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}

- uses: r-lib/actions/setup-pandoc@master
- uses: r-lib/actions/setup-pandoc@v2

- name: Query dependencies
run: |
Expand All @@ -41,14 +39,6 @@ jobs:
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install system dependencies for Linux
if: runner.os == 'Linux'
run: |
Expand Down Expand Up @@ -85,6 +75,7 @@ jobs:
if: runner.os == 'Linux'
run: |
devtools::install_local()
devtools::install_deps(dependencies=TRUE)
out <- devtools::test(stop_on_failure=TRUE)
print(getwd())
print(ls())
Expand Down
10 changes: 4 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: VAST
Type: Package
Title: Vector-Autoregressive Spatio-Temporal (VAST) Model
Version: 3.11.2
Date: 2024-07-15
Version: 3.11.3
Date: 2025-01-16
Authors@R:
c(person(given = "James",
family = "Thorson",
Expand All @@ -23,14 +23,13 @@ Imports:
abind,
effects,
stats,
ThorsonUtilities,
utils,
fmesher,
remotes,
devtools
Depends:
TMB (>= 1.8.0),
FishStatsUtils (>= 2.13.1),
FishStatsUtils (>= 2.13.2),
R (>= 3.5.0)
Suggests:
testthat,
Expand All @@ -42,11 +41,10 @@ Suggests:
lme4,
Remotes:
james-thorson-NOAA/FishStatsUtils,
james-thorson/utilities
License: file LICENSE
LazyData: true
Encoding: UTF-8
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
ByteCompile: true
URL: http://github.com/James-Thorson-NOAA/VAST
BugReports: http://github.com/James-Thorson-NOAA/VAST/issues
Expand Down
35 changes: 35 additions & 0 deletions R/list_parameters.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@


#' List fixed and random effects
#'
#' \code{list_parameters} lists all fixed and random effects
#'
#' @param Obj Compiled TMB object
#' @return Return Tagged-list of fixed and random effects (returned invisibly)

#' @export
list_parameters = function( Obj, verbose=TRUE ){
Return = list()
Table = data.frame()
if( length(Obj$env$random)>0 ){
Return[["Fixed_effects"]] = names(Obj$env$last.par[-Obj$env$random])
Return[["Random_effects"]] = names(Obj$env$last.par[Obj$env$random])
Table = data.frame( "Coefficient_name"=names(table(Return[["Fixed_effects"]])),
"Number_of_coefficients"=as.numeric(table(Return[["Fixed_effects"]])),
"Type"="Fixed")
Table = rbind( Table,
data.frame("Coefficient_name"=names(table(Return[["Random_effects"]])),
"Number_of_coefficients"=as.numeric(table(Return[["Random_effects"]])),
"Type"="Random"))
}else{
Return[["Fixed_effects"]] = names(Obj$env$last.par)
Table = data.frame( "Coefficient_name"=names(table(Return[["Fixed_effects"]])),
"Number_of_coefficients"=as.numeric(table(Return[["Fixed_effects"]])),
"Type"="Fixed")
}
if( verbose==TRUE ){
message("List of estimated fixed and random effects:")
print(Table)
}
return( invisible(Table) )
}
2 changes: 1 addition & 1 deletion R/make_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ function( TmbData,
Obj$env$inner.control$grad.tol <- c(1e-8,1e-12,1e-15)[ConvergeTol] # # Default : 1e-8 # Maximum gradient limit inner optimization

# Print number of parameters
ThorsonUtilities::list_parameters( Obj )
list_parameters( Obj )

# Return stuff
Return = list("Obj"=Obj, "Upper"=Bounds[,'Upper'], "Lower"=Bounds[,'Lower'], "Parameters"=Parameters, "Map"=Map, "Random"=Random)
Expand Down
5 changes: 3 additions & 2 deletions R/project_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#'
#' The function specifically simulates new values for random effects occurring
#' during forecasted years. This includes some combination of intercepts
#' {beta1/beta2} and spatio-temporal terms {epsilon1/epsilon2} depending on which
#' \code{beta1} or \code{beta2} and spatio-temporal terms
#' \code{epsilon1} or \code{epsilon2} depending on which
#' are treated as random during estimation. It does *not* generate new values of
#' covariates or random-effects that are not indexed by time {omega1/omega2}
#' covariates or random-effects that are not indexed by time \code{omega1} or \code{omega2}
#'
#' Note that the model may behave poorly when \code{historical_uncertainty="both"}
#' and the estimation model includes an AR1 process for any component.
Expand Down
17 changes: 17 additions & 0 deletions man/list_parameters.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified manual/NEWS.docx
Binary file not shown.
Binary file modified manual/NEWS.pdf
Binary file not shown.
4 changes: 4 additions & 0 deletions tests/testthat/test-EOF.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ test_that("EOF is working ", {
# Previously worked with CI, but not anymore
#skip_on_ci()
skip_if(skip_local)
if(!require("INLA")){
install.packages("INLA", dep=TRUE, repos=c( CRAN="https://cloud.r-project.org",
INLA="https://inla.r-inla-download.org/R/stable") )
}

test_path = file.path(multispecies_example_path,"EOF")
load( file.path(test_path,"parameter_estimates.RData") )
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-Tweedie-against-mgcv.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ test_that("Tweedie gives identical results to mgcv::gam(.) ", {
# Previously worked with CI, but not anymore
#skip_on_ci()
skip_if(skip_local)
if(!require("INLA")){
install.packages("INLA", dep=TRUE, repos=c( CRAN="https://cloud.r-project.org",
INLA="https://inla.r-inla-download.org/R/stable") )
}
library(mgcv)

#library(tweedie) # Installed from locally from tweedie_2.3.2.tar.gz here: https://cran.r-project.org/web/packages/tweedie/index.html
Expand Down Expand Up @@ -64,6 +68,10 @@ test_that("Tweedie gives identical results to mgcv::gam(.) ", {
test_that("Covariate effects when using a smoother gives identical results to mgcv::gam(.) ", {
#skip_on_ci()
skip_if(skip_local)
if(!require("INLA")){
install.packages("INLA", dep=TRUE, repos=c( CRAN="https://cloud.r-project.org",
INLA="https://inla.r-inla-download.org/R/stable") )
}
library(mgcv)

# Simulate
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-catchability_against_glm.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ test_that("Catchability covariates give identical results to glm(.) ", {
# Previously worked with CI, but not anymore
#skip_on_ci()
skip_if(skip_local)
if(!require("INLA")){
install.packages("INLA", dep=TRUE, repos=c( CRAN="https://cloud.r-project.org",
INLA="https://inla.r-inla-download.org/R/stable") )
}

# load data set
example = load_example( data_set="covariate_example" )
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-condition-and-density.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ context("Testing examples")
test_that("Condition-and-density example is working ", {
skip_on_ci()
skip_if(skip_local)

# Prepping
test_path = file.path(multispecies_example_path,"Condition_and_density")
load( file.path(test_path,"saved_estimates.RData") )
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-covariates_against_glm.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ test_that("Density covariates give identical results to glm(.) ", {
# Previously worked with CI, but not anymore
#skip_on_ci()
skip_if(skip_local)
if(!require("INLA")){
install.packages("INLA", dep=TRUE, repos=c( CRAN="https://cloud.r-project.org",
INLA="https://inla.r-inla-download.org/R/stable") )
}

# load data set
example = load_example( data_set="covariate_example" )
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-multi-species-examples.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test_that("Eastern Bering Sea 3-species is working ", {
TmbData = make_data("Version"=Version_VAST, "OverdispersionConfig"=rep(VesselConfig[2],2), "FieldConfig"=FieldConfig, "RhoConfig"=RhoConfig, "ObsModel"=ObsModel, "c_i"=Data_Geostat[,'spp']-1, "b_i"=Data_Geostat[,'Catch_KG'], "a_i"=Data_Geostat[,'AreaSwept_km2'], "v_i"=as.numeric(factor(paste(Data_Geostat[,'Vessel'],Data_Geostat[,'Year'])))-1, "t_i"=Data_Geostat[,'Year'], "spatial_list"=Spatial_List )
TmbList = make_model("build_model"=TRUE, "TmbData"=TmbData, "RunDir"=test_path, "Version"=Version_VAST, "RhoConfig"=RhoConfig, "loc_x"=Spatial_List$loc_x)
#on.exit( dyn.unload(paste0(system.file("executables", package = "VAST"),"/",TMB::dynlib(Version_VAST))), add=TRUE )
Opt = TMBhelper::fit_tmb( obj=TmbList[["Obj"]], getsd=FALSE, lower=TmbList[["Lower"]], upper=TmbList[["Upper"]] )
Opt = fit_tmb( obj=TmbList[["Obj"]], getsd=FALSE, lower=TmbList[["Lower"]], upper=TmbList[["Upper"]] )
# Comparisons
expect_equal( abs(Opt$par)[-which(names(Opt$par)%in%c("beta1_tf","beta2_tf","beta1_ct","beta2_ct","beta1_ft","beta2_ft"))], abs(opt$par)[-which(names(opt$par)%in%c("beta1_tf","beta2_tf","beta1_ct","beta2_ct","beta1_ft","beta2_ft"))], tolerance=1e-3 )
expect_equal( Opt$objective, opt$objective, tolerance=1e-3 )
Expand All @@ -33,6 +33,7 @@ test_that("Eastern Bering Sea 3-species is working ", {
test_that("Eastern Bering Sea 5-species is working ", {
skip_on_ci()
skip_if(skip_local)

# Prepping
test_path = file.path(multispecies_example_path,"EBS_5species")
load( file.path(test_path,"opt.RData") )
Expand All @@ -48,7 +49,7 @@ test_that("Eastern Bering Sea 5-species is working ", {
TmbData = make_data("Version"=Version_VAST, "OverdispersionConfig"=rep(VesselConfig[2],2), "FieldConfig"=FieldConfig, "RhoConfig"=RhoConfig, "ObsModel"=ObsModel, "c_i"=Data_Geostat[,'spp']-1, "b_i"=Data_Geostat[,'Catch_KG'], "a_i"=Data_Geostat[,'AreaSwept_km2'], "v_i"=as.numeric(factor(paste(Data_Geostat[,'Vessel'],Data_Geostat[,'Year'])))-1, "t_i"=Data_Geostat[,'Year'], "spatial_list"=Spatial_List )
TmbList = make_model("TmbData"=TmbData, "RunDir"=test_path, "Version"=Version_VAST, "RhoConfig"=RhoConfig, "loc_x"=Spatial_List$loc_x)
#on.exit( dyn.unload(paste0(system.file("executables", package = "VAST"),"/",TMB::dynlib(Version_VAST))), add=TRUE )
Opt = TMBhelper::fit_tmb( obj=TmbList[["Obj"]], getsd=FALSE, lower=TmbList[["Lower"]], upper=TmbList[["Upper"]] )
Opt = fit_tmb( obj=TmbList[["Obj"]], getsd=FALSE, lower=TmbList[["Lower"]], upper=TmbList[["Upper"]] )
# Comparisons
expect_equal( abs(Opt$par)[-which(names(Opt$par)%in%c("beta1_tf","beta2_tf","beta1_ct","beta2_ct","beta1_ft","beta2_ft"))], abs(opt$par)[-which(names(opt$par)%in%c("beta1_tf","beta2_tf","beta1_ct","beta2_ct","beta1_ft","beta2_ft"))], tolerance=1e-3 )
expect_equal( Opt$objective, opt$objective, tolerance=1e-3 )
Expand Down
6 changes: 5 additions & 1 deletion tests/testthat/test-single-species-examples.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ test_that("Eastern Bering Sea pollock is working ", {
# Previously worked with CI, but not anymore
#skip_on_ci()
skip_if(skip_local)
if(!require("INLA")){
install.packages("INLA", dep=TRUE, repos=c( CRAN="https://cloud.r-project.org",
INLA="https://inla.r-inla-download.org/R/stable") )
}

# Prepping
test_path = file.path(singlespecies_example_path,"EBS_pollock")
Expand All @@ -36,7 +40,7 @@ test_that("Eastern Bering Sea pollock is working ", {
TmbData = make_data("Version"=Version_VAST, "OverdispersionConfig"=rep(VesselConfig[2],2), "FieldConfig"=FieldConfig, "RhoConfig"=RhoConfig, "ObsModel"=c(ObsModel,0), "c_i"=rep(0,nrow(Data_Geostat)), "b_i"=Data_Geostat[,'Catch_KG'], "a_i"=Data_Geostat[,'AreaSwept_km2'], "v_i"=as.numeric(factor(paste(Data_Geostat[,'Vessel'],Data_Geostat[,'Year'])))-1, "t_i"=Data_Geostat[,'Year'], "spatial_list"=Spatial_List )
TmbList = make_model("TmbData"=TmbData, "build_model"=TRUE, "RunDir"=test_path, "Version"=Version_VAST, "RhoConfig"=RhoConfig, "loc_x"=Spatial_List$loc_x ) #, "Parameters"=Params)
#on.exit( dyn.unload(paste0(system.file("executables", package = "VAST"),"/",TMB::dynlib(Version_VAST))), add=TRUE )
Opt = TMBhelper::fit_tmb( obj=TmbList[["Obj"]], getsd=FALSE, lower=TmbList[["Lower"]], upper=TmbList[["Upper"]] ) # , rel.tol=1e-20
Opt = fit_tmb( obj=TmbList[["Obj"]], getsd=FALSE, lower=TmbList[["Lower"]], upper=TmbList[["Upper"]] ) # , rel.tol=1e-20
# Comparisons
Par1 = Opt$par[names(Opt$par)%in%c("ln_H_input","beta1_ct","beta1_ft","logkappa1","beta2_ct","beta2_ft","logkappa1","logSigmaM")]
Par2 = opt$par[names(opt$par)%in%c("ln_H_input","beta1_t","logkappa1","beta2_t","logkappa1","logSigmaM")]
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-spatially-varying-coefficient.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ test_that("Spatially varying coefficient example is working ", {
skip_on_ci()
skip_if(skip_local)


# Prepping
test_path = file.path(multispecies_example_path,"Spatially_varying_coefficient")
load( file=file.path(test_path,"Data.RData") )
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-zeroinfl-against-pscl.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ context("Testing examples")
test_that("Zero-inflated Poisson gives identical results to pscl::zeroinfl(.) ", {
#skip_on_ci()
skip_if(skip_local)
if(!require("INLA")){
install.packages("INLA", dep=TRUE, repos=c( CRAN="https://cloud.r-project.org",
INLA="https://inla.r-inla-download.org/R/stable") )
}

## Simulate
set.seed(101)
Expand Down
Binary file added tests/testthat/testthat-problems.rds
Binary file not shown.

0 comments on commit 431621f

Please sign in to comment.