From 9de329dd30acc9d50d44fbe1629af3c555add6e5 Mon Sep 17 00:00:00 2001 From: Jim Thorson Date: Fri, 6 Sep 2024 14:09:30 -0700 Subject: [PATCH] add abundance-expanded option --- DESCRIPTION | 2 +- R/predict.R | 11 +++++++++-- man/integrate_output.Rd | 9 ++++++++- src/tinyVAST.cpp | 4 ++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9932334..2558ce9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -60,6 +60,6 @@ Config/testthat/parallel: true Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 URL: https://vast-lib.github.io/tinyVAST/ BugReports: https://github.com/vast-lib/tinyVAST/issues diff --git a/R/predict.R b/R/predict.R index 9b143d6..7f9b57b 100644 --- a/R/predict.R +++ b/R/predict.R @@ -93,8 +93,13 @@ function( object, #' \item{\code{type=3}}{Abundance-weighted variable: weight predictor by #' proportion of total in a prior row of `newdata`. #' This option is used to weight a prediction for -#' one category based on predicted density of another category, e.g., +#' one category based on predicted proportional density of another category, e.g., #' to calculate abundance-weighted condition in a bivariate model.} +#' \item{\code{type=4}}{Abundance-expanded variable: weight predictor by +#' density in a prior row of `newdata`. +#' This option is used to weight a prediction for +#' one category based on predicted density of another category, e.g., +#' to calculate abundance-expanded consumption in a bivariate model.} #' \item{\code{type=0}}{Exclude from weighting: give weight of zero for #' a given row of `newdata`. Including a row of `newdata` with #' \code{type=0} is useful, e.g., when calculating abundance at that @@ -169,6 +174,8 @@ function( object, #' #' If \eqn{type_g = 3} then \eqn{\phi_g = \frac{\nu_{h_g}}{\nu^*} \mu_g } #' +#' If \eqn{type_g = 4} then \eqn{\phi_g = \nu_{h_g} \mu_g } +#' #' Finally, the total value from this second pass is calculated as: #' #' \deqn{ \phi^* = \sum_{g=0}^{G-1} \phi_g } @@ -221,7 +228,7 @@ function( object, }else if(length(type)==1){ type = rep(type, nrow(type)) } - checkInteger( type, lower=0, upper=3, len=nrow(newdata), any.missing=FALSE ) + checkInteger( type, lower=0, upper=4, len=nrow(newdata), any.missing=FALSE ) # Index for variable-weighted value if(missing(weighting_index)){ diff --git a/man/integrate_output.Rd b/man/integrate_output.Rd index ea7c150..08b5d72 100644 --- a/man/integrate_output.Rd +++ b/man/integrate_output.Rd @@ -40,8 +40,13 @@ proportion of total in each row of \code{newdata}} \item{\code{type=3}}{Abundance-weighted variable: weight predictor by proportion of total in a prior row of \code{newdata}. This option is used to weight a prediction for -one category based on predicted density of another category, e.g., +one category based on predicted proportional density of another category, e.g., to calculate abundance-weighted condition in a bivariate model.} +\item{\code{type=4}}{Abundance-expanded variable: weight predictor by +density in a prior row of \code{newdata}. +This option is used to weight a prediction for +one category based on predicted density of another category, e.g., +to calculate abundance-expanded consumption in a bivariate model.} \item{\code{type=0}}{Exclude from weighting: give weight of zero for a given row of \code{newdata}. Including a row of \code{newdata} with \code{type=0} is useful, e.g., when calculating abundance at that @@ -128,6 +133,8 @@ If \eqn{type_g = 2} then \eqn{\phi_g = x_g \frac{\nu_g}{\nu^*} } If \eqn{type_g = 3} then \eqn{\phi_g = \frac{\nu_{h_g}}{\nu^*} \mu_g } +If \eqn{type_g = 4} then \eqn{\phi_g = \nu_{h_g} \mu_g } + Finally, the total value from this second pass is calculated as: \deqn{ \phi^* = \sum_{g=0}^{G-1} \phi_g } diff --git a/src/tinyVAST.cpp b/src/tinyVAST.cpp index 6da9e83..0d41e84 100644 --- a/src/tinyVAST.cpp +++ b/src/tinyVAST.cpp @@ -868,6 +868,10 @@ Type objective_function::operator() (){ // density-weighted average of prediction phi_g(g) = (phi0_g(V_gz(g,1)) / sumphi0) * mu_g(g); } + if( (V_gz(g,0)==4) && (V_gz(g,1)>=0) && (V_gz(g,1)<=g) ){ + // density-weighted total of prediction + phi_g(g) = phi0_g(V_gz(g,1)) * mu_g(g); + } } //Type Metric = sum(phi_g); Type Metric = newton::Tag( sum(phi_g) ); // Set lowrank tag on Metric = sum(exp(x))