diff --git a/.github/workflows/R-CMD-check.yml b/.github/workflows/R-CMD-check.yml index 133052b..becb60b 100644 --- a/.github/workflows/R-CMD-check.yml +++ b/.github/workflows/R-CMD-check.yml @@ -17,8 +17,6 @@ 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 @@ -26,13 +24,13 @@ jobs: 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: | @@ -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: | @@ -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()) diff --git a/DESCRIPTION b/DESCRIPTION index c7e5fad..fcf0165 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", @@ -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, @@ -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 diff --git a/R/list_parameters.R b/R/list_parameters.R new file mode 100644 index 0000000..0f5bfc9 --- /dev/null +++ b/R/list_parameters.R @@ -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) ) +} diff --git a/R/make_model.R b/R/make_model.R index 7554d5b..d27d9b1 100644 --- a/R/make_model.R +++ b/R/make_model.R @@ -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) diff --git a/R/project_model.R b/R/project_model.R index 0c6c547..efeffc9 100644 --- a/R/project_model.R +++ b/R/project_model.R @@ -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. diff --git a/man/list_parameters.Rd b/man/list_parameters.Rd new file mode 100644 index 0000000..8361ac6 --- /dev/null +++ b/man/list_parameters.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/list_parameters.R +\name{list_parameters} +\alias{list_parameters} +\title{List fixed and random effects} +\usage{ +list_parameters(Obj, verbose = TRUE) +} +\arguments{ +\item{Obj}{Compiled TMB object} +} +\value{ +Return Tagged-list of fixed and random effects (returned invisibly) +} +\description{ +\code{list_parameters} lists all fixed and random effects +} diff --git a/manual/NEWS.docx b/manual/NEWS.docx index 01ce727..7d42f0c 100644 Binary files a/manual/NEWS.docx and b/manual/NEWS.docx differ diff --git a/manual/NEWS.pdf b/manual/NEWS.pdf index e13779d..7b1e5c2 100644 Binary files a/manual/NEWS.pdf and b/manual/NEWS.pdf differ diff --git a/tests/testthat/test-EOF.R b/tests/testthat/test-EOF.R index b031481..ffe2840 100644 --- a/tests/testthat/test-EOF.R +++ b/tests/testthat/test-EOF.R @@ -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") ) diff --git a/tests/testthat/test-Tweedie-against-mgcv.R b/tests/testthat/test-Tweedie-against-mgcv.R index d81cd5f..52e06d6 100644 --- a/tests/testthat/test-Tweedie-against-mgcv.R +++ b/tests/testthat/test-Tweedie-against-mgcv.R @@ -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 @@ -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 diff --git a/tests/testthat/test-catchability_against_glm.R b/tests/testthat/test-catchability_against_glm.R index 2fae170..76db27d 100644 --- a/tests/testthat/test-catchability_against_glm.R +++ b/tests/testthat/test-catchability_against_glm.R @@ -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" ) diff --git a/tests/testthat/test-condition-and-density.R b/tests/testthat/test-condition-and-density.R index 9b9735f..915f81c 100644 --- a/tests/testthat/test-condition-and-density.R +++ b/tests/testthat/test-condition-and-density.R @@ -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") ) diff --git a/tests/testthat/test-covariates_against_glm.R b/tests/testthat/test-covariates_against_glm.R index bafe65f..9ca4a96 100644 --- a/tests/testthat/test-covariates_against_glm.R +++ b/tests/testthat/test-covariates_against_glm.R @@ -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" ) diff --git a/tests/testthat/test-multi-species-examples.R b/tests/testthat/test-multi-species-examples.R index cdf2e02..399fe88 100644 --- a/tests/testthat/test-multi-species-examples.R +++ b/tests/testthat/test-multi-species-examples.R @@ -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 ) @@ -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") ) @@ -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 ) diff --git a/tests/testthat/test-single-species-examples.R b/tests/testthat/test-single-species-examples.R index 5e46b0f..b577b5a 100644 --- a/tests/testthat/test-single-species-examples.R +++ b/tests/testthat/test-single-species-examples.R @@ -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") @@ -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")] diff --git a/tests/testthat/test-spatially-varying-coefficient.R b/tests/testthat/test-spatially-varying-coefficient.R index 4fb81c2..1584950 100644 --- a/tests/testthat/test-spatially-varying-coefficient.R +++ b/tests/testthat/test-spatially-varying-coefficient.R @@ -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") ) diff --git a/tests/testthat/test-zeroinfl-against-pscl.R b/tests/testthat/test-zeroinfl-against-pscl.R index 4dc3b76..7254b09 100644 --- a/tests/testthat/test-zeroinfl-against-pscl.R +++ b/tests/testthat/test-zeroinfl-against-pscl.R @@ -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) diff --git a/tests/testthat/testthat-problems.rds b/tests/testthat/testthat-problems.rds new file mode 100644 index 0000000..8640985 Binary files /dev/null and b/tests/testthat/testthat-problems.rds differ