Skip to content

Commit

Permalink
Merge pull request #175 from OHI-Science/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Melsteroni committed May 17, 2016
2 parents 548d7f1 + 52b829f commit c5f92a2
Show file tree
Hide file tree
Showing 42 changed files with 205 additions and 241 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ Collate:
'trace_git_csv_value.R'
'write_shortcuts.R'
'zzz.R'
RoxygenNote: 5.0.1
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by roxygen2 (4.1.1): do not edit by hand
# Generated by roxygen2: do not edit by hand

export(CalculateAll)
export(CalculateGoalIndex)
Expand Down
144 changes: 72 additions & 72 deletions R/CalculatePressuresMatrix.R
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
##' Calculate Pressures Matrix
##'
##' The pressures matrix model function computes a pressures weighting matrix
##' based on regional attributes per category.
##'
##'
##' Given:
##'
##' \itemize{
##'
##' \item \emph{g} is the goal or subgoal (e.g., AO, CW, LIV, ECO, ...), \item
##' \emph{i} is the region (e.g., 1, 2, 3, ...), \item \emph{j} is the
##' pressures layer or stressor (e.g., \code{cc_acid}, \code{fp_art_lb}, etc.).
##' \item \emph{k} is the category (e.g., habitat, sector, product, etc.)
##'
##' }
##'
##' There may be a component \emph{k} for a given goal \emph{g} such that
##' \eqn{p_w(g,i,j,k)} and \eqn{w(g,i,j,k)}.
##'
##' \deqn{p_{w}(g,i,j,k) = w(g,i,j,k) * p(i,j)}
##'
##' In these cases where there is a component \emph{k} for goal \emph{g},
##' there's an additional aggregation or formula to calculate \eqn{w(g,i,j)}
##' based on the core rank weight \eqn{\alpha(g,j,k)} from the original
##' pressures matrix (as written in Halpern et al. (2012)) and some
##' region-specific data for each category \code{k} \eqn{\beta(i,k)}.
##'
##' This function \code{CalculatePressuresMatrix} will aggregate a
##' category-specific weighting matrix \eqn{\alpha(g,j,k)} [category x
##' pressure] using region-specific data \eqn{\beta(g,i,k)} into a [region_id x
##' pressure] matrix \eqn{w(g,i,j)} used in \code{CalculatePressuresScore}, such
##' that:
##'
##' \deqn{w(g,i,j) = \frac{\sum_k \alpha({g,j,k}) * \beta({g,i,k})}{\sum_k
##' \beta({g,i,k})}}
##'
##' \enumerate{
##'
##' \item For the CP, CS goals, the weight depends on the extent \emph{A} of
##' habitat \emph{k} in region \emph{i}:
##'
##' \deqn{\beta(i,k) = A(i,k)}
##'
##' \item For the HAB goal, the weight depends on the presence of habitat
##' \emph{k} (i.e., if \eqn{A(i,k)>0}) in region \emph{i}:
##'
##' \deqn{\beta(i,k) = hasHabitat(i,k)}
##'
##' \item For the LIV and ECO goals, the weight depends on the presence of
##' sector \emph{k} if data available for region \emph{i} and sector \emph{k}:
##'
##' \deqn{\beta(i,k) = hasSector(i,k)}
##'
##' \item For the NP goal, the weight depends on the peak dollar value of each
##' product \emph{k} across all years (see \eqn{w_p} from SI Equation S27) if
##' data available for region \emph{i} and product \emph{k}:
##'
##' \deqn{\beta(i,k) = w_p(i,k)} }
##'
##' @param alpha the weighting matrix of the form [category x pressure]. Each
##' rank weight must be an integer between 0 and 3 inclusive, or NA.
##' @param beta the aggregation matrix of the form [region_id x category] to
##' collapse across each category.
##' @param calc type of calculation, whether avg (default), mean (diff't from
##' avg?) or presence (results in 1 or 0).
##' @return Returns a weight matrix \emph{w} [region_id x pressure] suitable
##' for \code{\link{CalculatePressuresScore}}.
##' @seealso \code{\link{CalculatePressuresScore}}
##' @keywords ohi
##' @export
#' Calculate Pressures Matrix
#'
#' The pressures matrix model function computes a pressures weighting matrix
#' based on regional attributes per category.
#'
#'
#' Given:
#'
#' \itemize{
#'
#' \item \emph{g} is the goal or subgoal (e.g., AO, CW, LIV, ECO, ...), \item
#' \emph{i} is the region (e.g., 1, 2, 3, ...), \item \emph{j} is the
#' pressures layer or stressor (e.g., \code{cc_acid}, \code{fp_art_lb}, etc.).
#' \item \emph{k} is the category (e.g., habitat, sector, product, etc.)
#'
#' }
#'
#' There may be a component \emph{k} for a given goal \emph{g} such that
#' \eqn{p_w(g,i,j,k)} and \eqn{w(g,i,j,k)}.
#'
#' \deqn{p_{w}(g,i,j,k) = w(g,i,j,k) * p(i,j)}
#'
#' In these cases where there is a component \emph{k} for goal \emph{g},
#' there's an additional aggregation or formula to calculate \eqn{w(g,i,j)}
#' based on the core rank weight \eqn{\alpha(g,j,k)} from the original
#' pressures matrix (as written in Halpern et al. (2012)) and some
#' region-specific data for each category \code{k} \eqn{\beta(i,k)}.
#'
#' This function \code{CalculatePressuresMatrix} will aggregate a
#' category-specific weighting matrix \eqn{\alpha(g,j,k)} [category x
#' pressure] using region-specific data \eqn{\beta(g,i,k)} into a [region_id x
#' pressure] matrix \eqn{w(g,i,j)} used in \code{CalculatePressuresScore}, such
#' that:
#'
#' \deqn{w(g,i,j) = \frac{\sum_k \alpha({g,j,k}) * \beta({g,i,k})}{\sum_k
#' \beta({g,i,k})}}
#'
#' \enumerate{
#'
#' \item For the CP, CS goals, the weight depends on the extent \emph{A} of
#' habitat \emph{k} in region \emph{i}:
#'
#' \deqn{\beta(i,k) = A(i,k)}
#'
#' \item For the HAB goal, the weight depends on the presence of habitat
#' \emph{k} (i.e., if \eqn{A(i,k)>0}) in region \emph{i}:
#'
#' \deqn{\beta(i,k) = hasHabitat(i,k)}
#'
#' \item For the LIV and ECO goals, the weight depends on the presence of
#' sector \emph{k} if data available for region \emph{i} and sector \emph{k}:
#'
#' \deqn{\beta(i,k) = hasSector(i,k)}
#'
#' \item For the NP goal, the weight depends on the peak dollar value of each
#' product \emph{k} across all years (see \eqn{w_p} from SI Equation S27) if
#' data available for region \emph{i} and product \emph{k}:
#'
#' \deqn{\beta(i,k) = w_p(i,k)} }
#'
#' @param alpha the weighting matrix of the form [category x pressure]. Each
#' rank weight must be an integer between 0 and 3 inclusive, or NA.
#' @param beta the aggregation matrix of the form [region_id x category] to
#' collapse across each category.
#' @param calc type of calculation, whether avg (default), mean (diff't from
#' avg?) or presence (results in 1 or 0).
#' @return Returns a weight matrix \emph{w} [region_id x pressure] suitable
#' for \code{\link{CalculatePressuresScore}}.
#' @seealso \code{\link{CalculatePressuresScore}}
#' @keywords ohi
#' @export
CalculatePressuresMatrix <- function(alpha, beta, calc='avg') {
#' Parameters:
# Parameters:
#' @param alpha weighting matrix of the form [category x pressure]
#' @param beta aggregation matrix of the form [region_id x category] to collapse across each category
#' @param calc type of calculation, whether avg (default), mean (diff't from avg?) or presence (results in 1 or 0)
Expand Down
20 changes: 10 additions & 10 deletions R/CalculatePressuresScore.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,18 @@
##'
##' @export
CalculatePressuresScore <- function(p, w, GAMMA=0.5, browse=F, pressures_categories=list(environmental=c('po','hd','fp','sp','cc'), social='ss')) {
#' Computation of pressure
#'
#' The weighting matrix and the pressure scores matrix are of the form
#' [region_id] x [pressure]
#'
#' The pressure names must be of the form "category"_"pressure".
#' Use "ss" to denote the social category.
#'
#' Parameters:
# Computation of pressure
#
# The weighting matrix and the pressure scores matrix are of the form
# [region_id] x [pressure]
#
# The pressure names must be of the form "category"_"pressure".
# Use "ss" to denote the social category.
#
# Parameters:
#' @param p is the pressures value matrix [region_id x pressure]
#' @param w is the weighting matrix of the form [region_id x pressure]
#'
#
#' @return pressures scores as a named vector.

# verify parameters
Expand Down
Binary file modified data/georegion_labels.rda
Binary file not shown.
3 changes: 2 additions & 1 deletion man/CalculateAll.Rd

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

18 changes: 10 additions & 8 deletions man/CalculateGoalIndex.Rd

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

2 changes: 1 addition & 1 deletion man/CalculatePressuresAll.Rd

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

4 changes: 2 additions & 2 deletions man/CalculatePressuresComponent.Rd

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

8 changes: 7 additions & 1 deletion man/CalculatePressuresMatrix.Rd

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

17 changes: 12 additions & 5 deletions man/CalculatePressuresScore.Rd

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

2 changes: 1 addition & 1 deletion man/CalculateResilienceAll.Rd

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

2 changes: 1 addition & 1 deletion man/CalculateResilienceComponent.Rd

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

Loading

0 comments on commit c5f92a2

Please sign in to comment.