pathway_model: Pathway model

View source: R/pathway_model.R

pathway_modelR Documentation

Pathway model

Description

Estimates the number of potential founder populations (NPFP) of a pest in different regions, using N_{trade} data combined with additional user-defined parameters.

Usage

pathway_model(
  ntrade_data,
  IDs_col,
  values_col,
  expression,
  parameters,
  niter = 100
)

Arguments

ntrade_data

A data frame with the quantity of potentially infested commodities imported from third countries where the pest is present (N_{trade}). It can be calculated using the ntrade() function.

IDs_col

A string specifying the column name in ntrade_data with the country or region IDs of interest. See details on IDs - country or region identification codes.

values_col

A string specifying the column name in ntrade_data with the N_{trade} values (quantity of potentially infested commodity imports) to be used in the pathway model.

expression

A string of characters representing the equation for the pathway model. This expression must not include N_{trade}, since it is added multiplicatively to the entered equation by default. The resulting equation will be of the form:

NPFP = N_{trade_i} \cdot \; ``expression"

parameters

A named list specifying the distributions for each parameter used in expression. Each element of the list must be another list containing:

  • dist: A string indicating the distribution name (e.g., "norm", "beta").

  • Additional arguments required by the specified distribution (e.g., mean, sd for "norm").

See details on Parameter distributions for a list of available distributions and examples on how to specify them.

niter

The number of iterations to generate random samples from the distributions. The default is 100 iterations.

Details

IDs - country or region identification codes:

The use of ISO 3166 (alpha-2) codes (ISO 3166 Maintenance Agency), or NUTS codes in the case of European countries Nomenclature of territorial units for statistics, as country or region identifiers (IDs_col) is recommended for subsequent compatibility with other functions of the qPRAentry package.

Parameter distributions:

The following distributions are supported. For details on their parameters, refer to the linked R documentation:

Distribution ⁠ ⁠ Documentation
"beta" ⁠ ⁠ rbeta() (Beta distribution)
"binom" ⁠ ⁠ rbinom() (Binomial distribution)
"cauchy" ⁠ ⁠ rcauchy() (Cauchy distribution)
"chisq" ⁠ ⁠ rchisq() (Chi-squared distribution)
"exp" ⁠ ⁠ rexp() (Exponential distribution)
"f" ⁠ ⁠ rf() (F distribution)
"gamma" ⁠ ⁠ rgamma() (Gamma distribution)
"geom" ⁠ ⁠ rgeom() (Geometric distribution)
"lnorm" ⁠ ⁠ rlnorm() (Log-normal distribution)
"nbinom" ⁠ ⁠ rnbinom() (Negative Binomial distribution)
"norm" ⁠ ⁠ rnorm() (Normal distribution)
"pois" ⁠ ⁠ rpois() (Poisson distribution)
"t" ⁠ ⁠ rt() (Student's t distribution)
"unif" ⁠ ⁠ runif() (Uniform distribution)
"weibull" ⁠ ⁠ rweibull() (Weibull distribution)

For example, to specify a normal distribution with mean 0 and standard deviation 1:
list(dist = "norm", mean = 0, sd = 1)

Ensure that all parameters required by the chosen distribution are included.

Value

A data frame with the statistics (mean, SD, minimum, first quartile, median, third quartile, and maximum) resulting from the iterations of the NPFP for each country/region and for the total (i.e., the results for the set of all countries/regions).

See Also

ntrade()

Examples

## Example using Northern American countries and ntrade simulated data
data("datatrade_NorthAm")
# Extract country IDs and simulate ntrade data
IDs <- datatrade_NorthAm$internal_production$reporter
df <- data.frame(IDs = IDs,
                 ntrade_values = abs(rnorm(length(IDs), 10000, 2000)))
# Expression for the pathway model using 3 parameters
eq <- "(1/P1)*P2*P3"
# Distribution for each parameter
parameters <- list(
  P1 = list(dist = "beta", shape1 = 0.5, shape2 = 1),
  P2 = list(dist = "gamma", shape = 1.5, scale = 100),
  P3 = list(dist = "lnorm", mean = 5, sd = 2)
)
# Run pathway_model()
res_pathway <- pathway_model(ntrade_data = df,
                             IDs_col = "IDs",
                             values_col = "ntrade_values",
                             expression = eq,
                             parameters = parameters,
                             niter = 100)
head(res_pathway)
# summary of the total for all countries
res_pathway[res_pathway$IDs == "Total",]
# plot
plot_countries(res_pathway, "IDs", "Median")


qPRAentry documentation built on April 12, 2025, 1:12 a.m.