Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug-fixes for integrate_output #46

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Type: Package
Package: tinyVAST
Title: Vector Autoregressive Spatio-Temporal Model Using Minimal
Feature-Set
Version: 0.5.0
Date: 2024-04-01
Version: 0.6.0
Date: 2024-05-21
Authors@R: c(
person(c("James", "T."), "Thorson", , "[email protected]",
role = c("aut", "cre"),
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ importFrom(TMB,sdreport)
importFrom(abind,abind)
importFrom(checkmate,assertClass)
importFrom(checkmate,assertDataFrame)
importFrom(checkmate,checkInteger)
importFrom(checkmate,checkNumeric)
importFrom(corpcor,pseudoinverse)
importFrom(fmesher,fm_evaluator)
importFrom(fmesher,fm_fem)
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# tinyVAST 0.6.0

* Change `integrate_output` interface by splitting `W_gz` and `V_gz`
into four vectors `area`, `type`, `covariate`, and `weighting_index`
to simplify documentations and improve naming
* Fix bug where cloglog and logit links were not previously implemented
for use in `predict` and `integrate_output`

# tinyVAST 0.5.0

* Adding vignette showing how to fit multiple data types in an SDM
Expand Down
28 changes: 19 additions & 9 deletions R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
#' `dsem=NULL` disables the space-variable interaction; see
#' [make_dsem_ram()] or [make_eof_ram()].
#' @param family A function returning a class \code{family}, including [gaussian()],
#' [lognormal()], or [tweedie()]. Alternatively, can be a named list of
#' [lognormal()], [tweedie()], [binomial()], [Gamma()], or [poisson()].
#' Alternatively, can be a named list of
#' these functions, with names that match levels of
#' \code{data$distribution_column} to allow different
#' families by row of data. Delta model families are possible.
#' See \code{\link[tinyVAST:families]{Families}},
#' families by row of data. Delta model families are possible, and see
#' \code{\link[tinyVAST:families]{Families}} for delta-model options,
#' @param space_columns A string or character vector that indicates
#' the column(s) of `data` indicating the location of each sample.
#' When `spatial_graph` is an `igraph` object, `space_columns` is a string with
Expand Down Expand Up @@ -57,7 +58,7 @@
#' from `data$variables`.
#' @param delta_options a named list with slots for \code{delta_formula},
#' \code{delta_sem}, and \code{delta_dsem}. These follow the same format as
#' \code{family}, \code{sem}, and \code{dsem}, but specify options for the
#' \code{formula}, \code{sem}, and \code{dsem}, but specify options for the
#' second linear predictor of a delta model, and are only used (or estimable)
#' when a \code{\link[tinyVAST:families]{delta family}} is used for some samples.
#' @param control Output from [tinyVASTcontrol()], used to define user
Expand All @@ -75,7 +76,7 @@
#'
#' the default `dsem=NULL` turns off all multivariate and temporal indexing, such
#' that `spatial_graph` is then ignored, and the model collapses
#' to a standard model using \code{\link[mgcv]{gam}}. To specify a univeriate spatial model,
#' to a standard model using \code{\link[mgcv]{gam}}. To specify a univariate spatial model,
#' the user must specify both `spatial_graph` and `dsem=""`, where the latter
#' is then parsed to include a single exogenous variance for the single variable
#'
Expand All @@ -96,7 +97,7 @@
#' model.offset model.response na.omit nlminb optimHess pnorm rnorm terms
#' update.formula binomial poisson predict
#' @importFrom TMB MakeADFun sdreport
#' @importFrom checkmate assertClass assertDataFrame
#' @importFrom checkmate assertClass assertDataFrame checkInteger checkNumeric
#' @importFrom Matrix Cholesky solve
#' @importFrom abind abind
#'
Expand Down Expand Up @@ -156,6 +157,7 @@ function( formula,
#if( !is.data.frame(data) ) stop("`data` must be a data frame", call. = FALSE)
assertClass(control, "tinyVASTcontrol")
assertDataFrame(data)
if(inherits(data,"tbl")) stop("`data` must be a data.frame and cannot be a tibble")

##############
# input telescoping
Expand Down Expand Up @@ -205,6 +207,11 @@ function( formula,
c_i = integer(0)
}

# variables can't have commas, because it conflicts with how `sem` and `dsem` are parsed
if( grepl(pattern=",", x=variables, fixed=TRUE) ){
stop("`variables` cannot include any commas")
}

##############
# DSEM RAM constructor
##############
Expand Down Expand Up @@ -603,6 +610,9 @@ function( formula,
tmb_map$log_kappa = factor(NA)
}

#
tmb_random = c("gamma_k","epsilon_stc","omega_sc","gamma2_k","epsilon2_stc","omega2_sc")

##############
# Fit model
##############
Expand All @@ -616,7 +626,7 @@ function( formula,
obj = MakeADFun( data = tmb_data,
parameters = tmb_par,
map = tmb_map,
random = c("gamma_k","epsilon_stc","omega_sc","gamma2_k","epsilon2_stc","omega2_sc"),
random = tmb_random,
DLL = "tinyVAST",
profile = control$profile,
silent = control$silent ) #
Expand Down Expand Up @@ -689,7 +699,7 @@ function( formula,
opt = opt,
rep = obj$report(obj$env$last.par.best),
sdrep = sdrep,
tmb_inputs = list(tmb_data=tmb_data, tmb_par=tmb_par, tmb_map=tmb_map),
tmb_inputs = list(tmb_data=tmb_data, tmb_par=tmb_par, tmb_map=tmb_map, tmb_random=tmb_random),
call = match.call(),
spatial_graph = spatial_graph,
run_time = Sys.time() - start_time,
Expand Down Expand Up @@ -754,7 +764,7 @@ function( nlminb_loops = 1,
gmrf_parameterization = c("separable","projection"),
estimate_delta0 = FALSE,
getJointPrecision = FALSE,
calculate_deviance_explained = TRUE ){
calculate_deviance_explained = FALSE ){

gmrf_parameterization = match.arg(gmrf_parameterization)

Expand Down
Loading
Loading