Skip to content

Commit

Permalink
add abundance-expanded option
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Thorson committed Sep 6, 2024
1 parent 8f51512 commit 9de329d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 9 additions & 2 deletions R/predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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)){
Expand Down
9 changes: 8 additions & 1 deletion man/integrate_output.Rd

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

4 changes: 4 additions & 0 deletions src/tinyVAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,10 @@ Type objective_function<Type>::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))
Expand Down

0 comments on commit 9de329d

Please sign in to comment.