View source: R/pathway_model.R
pathway_model | R Documentation |
Estimates the number of potential founder populations (NPFP
) of a pest
in different regions, using N_{trade}
data combined with additional user-defined
parameters.
pathway_model(
ntrade_data,
IDs_col,
values_col,
expression,
parameters,
niter = 100
)
ntrade_data |
A data frame with the quantity of potentially infested commodities
imported from third countries where the pest is present ( |
IDs_col |
A string specifying the column name in |
values_col |
A string specifying the column name in |
expression |
A string of characters representing the equation for the pathway model.
This expression must not include
|
parameters |
A named list specifying the distributions for each parameter
used in
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. |
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.
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.
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).
ntrade()
## 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.