autoSolution: Calculate and itegrate probability functions for shape...

View source: R/customProbFunctions.R

autoSolutionR Documentation

Calculate and itegrate probability functions for shape functions

Description

Given the name of a shape function and the specific calculation requested, calculate either the PDF, CCDF, integration of the PDF or CCDF, or the integration of tau*PDF or tau*CCDF.

Usage

autoSolution(
  suffix,
  shape,
  tau_0,
  tau_n,
  tau,
  tau_b = NULL,
  ...,
  MoreArgs = list(),
  integrateArgs1 = list(),
  integrateArgs2 = list(),
  forceNumeric = F
)

fullSolution(
  suffix,
  shape,
  tau_0,
  tau_n,
  tau,
  tau_b = NULL,
  ...,
  MoreArgs = list()
)

numericalSolution(
  suffix,
  shape,
  tau_0,
  tau_n,
  tau,
  tau_b = NULL,
  ...,
  MoreArgs = list(),
  integrateArgs1 = list(),
  integrateArgs2 = list(),
  forceNumeric = T
)

Arguments

suffix

A character vector indicating the value to be returned; either "PDF", "CCDF", "IntPDF", "IntCCDF", "IntTau.PDF", or "IntTau.CCDF."

shape

A character vector of length(shape) == 1 naming the shape function (e.g., powerLaw) to be integrated numerically if solutions are not available used.

tau_0, tau_n

Minimum and maximum residence times of the definite integration.

tau

A vector of residence times for which PDF or CCDF values are requested, or the lower values of definate intergrals of the finite integral of the PDF, CCDF, tau*PDF, or tau*CCDF.

tau_b

The upper values of definite integrals of the PDF, CCDF, tau*PDF, or tau*CCDF. Ignored for calculating PDF or CCDF values.

...

Additional values required by the shape function.

integrateArgs1, integrateArgs2

When numerical integration is used, a named list of optional values for integrate function (e.g., subdivisions, rel.tol, etc.) can be passed via this argument. Any values in integrateArgs1 list will be applied to the integration used within the calculations for the PDF or CCDF. Values for integrateArgs2 will be used when the PDF or CCDF are integrated. Thus, integrateArgs1 are used regardless of the value of suffix. integrateArgs2 are used only when suffix is "IntPDF", "IntCCDF", "IntTau.PDF", or "inteTau.CCDF". When solutions functions are used (rather than numerical integration), these parameters are ignored.

forceNumeric

When set to T, numerical integration will be used by autoSolution even if solutions to the PDF, CCDF, IntPDF, IntCCDF, IntTau.PDF, and IntTau.CCDF are available.

Details

The function numericalSolution uses numerical integration of basic shape function (e.g., powerLaw, exponent) to return values of the probability density function (PDF) of the shape function, complementary cumulative distribution funtion (CCDF) of the shape function, finite integrals of the PDF or CCDF, or finite integrals of tau*PDF or tau*CCDF. Numerical integration to calculate the normalizing constant for the PDF and CCDF, and for integrating these functions.

The function fullSolution looks for a function with a name specified by the concatination of shape and suffix and checks to be sure any such function has the signature function(tau, tau_0, tau_n, ...) if suffix is "PDF" or "CCDF", or function(tau_a, tau_b, tau_0, tau_n, ...) for other values of suffix. Solutions for the "powerLaw" and "exponent" shapes are provided as part of this package as follows: PDF (e.g. powerLawPDF, exponentPDF), CCDF (e.g. powerLawCCDF, exponentCCDF), integral of the PFD (e.g. powerLawIntPDF, exponentIntPDF), integral of the CCDF (e.g. powerLawIntCCDF, exponentIntCCDF), integral of tau*PDF (e.g. powerLawIntTau.PDF, exponentIntTau.PDF) or integral of tau*CCDF (e.g. powerLawIntTau.CCDF, exponentIntTau.CCDF). These solution functions can also be called directly, but fullSolution is provided as a convenience wrapper that calls the functions using the convention shape and suffix.

The user can provide custom shape functions or solutions for other shapes, however the names of the custom solution functions must follow the convention of concatinating the shape name with the suffix as the name of the solution function (e.g., the solution function for the integral of tau*PDF of a shape called "foo" must be fooIntTau.PDF). For more information, see the documentation of powerLaw and powerLawPDF

The function autoSolution looks first for a solution function that matches the concatination of shape and suffix and, if found, calls fullSolution. If the solution functions are not found, autoSolution calls numericSolution.

Value

A vector of values representing either the PDF, CCDF, integration of the PDF, integration of the CCDF, integration of tau * PDF or the integration of tau * CCDF.


FluvialLandscapeLab/hydrogeom documentation built on May 13, 2022, 10 p.m.