ssn_simulate {SSN2} | R Documentation |
Simulate random variables on a stream network
Description
Simulate random variables on a stream
network with a specific mean and covariance structure. Designed to use
ssn_simulate()
, but individual simulation functions for each
resposne distribution also exist.
Usage
ssn_simulate(
family = "Gaussian",
ssn.object,
network = "obs",
tailup_params,
taildown_params,
euclid_params,
nugget_params,
additive,
mean = 0,
samples = 1,
dispersion = 1,
size = 1,
randcov_params,
partition_factor,
...
)
ssn_rbeta(
ssn.object,
network = "obs",
tailup_params,
taildown_params,
euclid_params,
nugget_params,
dispersion = 1,
mean = 0,
samples = 1,
additive,
randcov_params,
partition_factor,
...
)
ssn_rbinom(
ssn.object,
network = "obs",
tailup_params,
taildown_params,
euclid_params,
nugget_params,
mean = 0,
size = 1,
samples = 1,
additive,
randcov_params,
partition_factor,
...
)
ssn_rgamma(
ssn.object,
network = "obs",
tailup_params,
taildown_params,
euclid_params,
nugget_params,
dispersion = 1,
mean = 0,
samples = 1,
additive,
randcov_params,
partition_factor,
...
)
ssn_rinvgauss(
ssn.object,
network = "obs",
tailup_params,
taildown_params,
euclid_params,
nugget_params,
dispersion = 1,
mean = 0,
samples = 1,
additive,
randcov_params,
partition_factor,
...
)
ssn_rnbinom(
ssn.object,
network = "obs",
tailup_params,
taildown_params,
euclid_params,
nugget_params,
dispersion = 1,
mean = 0,
samples = 1,
additive,
randcov_params,
partition_factor,
...
)
ssn_rnorm(
ssn.object,
network = "obs",
tailup_params,
taildown_params,
euclid_params,
nugget_params,
mean = 0,
samples = 1,
additive,
randcov_params,
partition_factor,
...
)
ssn_rpois(
ssn.object,
network = "obs",
tailup_params,
taildown_params,
euclid_params,
nugget_params,
mean = 0,
samples = 1,
additive,
randcov_params,
partition_factor,
...
)
Arguments
family |
The response distribution family. The default is |
ssn.object |
A spatial stream network object with class |
network |
The spatial stream network to simulate on. Currently only
allowed to be |
tailup_params |
An object from |
taildown_params |
An object from |
euclid_params |
An object from |
nugget_params |
An object from |
additive |
The name of the variable in |
mean |
A numeric vector representing the mean. |
samples |
The number of independent samples to generate. The default
is |
dispersion |
The dispersion value (if relevant). |
size |
A numeric vector representing the sample size for each binomial trial.
The default is |
randcov_params |
A |
partition_factor |
A formula indicating the partition factor. |
... |
Other arguments. Not used (needed for generic consistency). |
Details
Random variables are simulated via the product of the covariance matrix's
square (Cholesky) root and independent standard normal random variables
on the link scale, which are then used to simulate a relevant variable on the response scale
according to family
.
Computing the square root is a significant
computational burden and likely unfeasible for sample sizes much past 10,000.
Because this square root only needs to be computed once, however, it is
nearly the sample computational cost to call ssn_rnorm()
for any value
of samples
.
If not using ssn_simulate()
, individual simulation functions for
each response distribution do exist:
-
ssn_rnorm()
: Simulate from a Gaussian distribution -
ssn_rpois()
: Simulate from a Poisson distribution -
ssn_rnbinom()
: Simulate from a negative binomial distribution -
ssn_rbinom()
: Simulate from a binomial distribution -
ssn_rbeta()
: Simulate from a beta distribution -
ssn_rgamma()
: Simulate from a gamma distribution -
ssn_rinvgauss()
: Simulate from an inverse Gaussian distribution
Value
If samples
is 1, a vector of random variables for each row of ssn.object$obs
is returned. If samples
is greater than one, a matrix of random variables
is returned, where the rows correspond to each row of ssn.object$obs
and the columns
correspond to independent samples.
References
Ver Hoef, J.M. and Peterson, E.E. (2010) A moving average approach for spatial statistical models of stream networks (with discussion). Journal of the American Statistical Association 105, 6–18. DOI: 10.1198/jasa.2009.ap08248. Rejoinder pgs. 22–24.
Examples
# Copy the mf04p .ssn data to a local directory and read it into R
# When modeling with your .ssn object, you will load it using the relevant
# path to the .ssn data on your machine
copy_lsn_to_temp()
temp_path <- paste0(tempdir(), "/MiddleFork04.ssn")
mf04p <- ssn_import(temp_path, overwrite = TRUE)
tailup <- tailup_params("exponential", de = 0.1, range = 200)
taildown <- taildown_params("exponential", de = 0.4, range = 300)
euclid <- euclid_params("spherical", de = 0.2, range = 1000, rotate = 0, scale = 1)
nugget <- nugget_params("nugget", nugget = 0.1)
ssn_simulate("gaussian", mf04p, "obs", tailup, taildown, euclid, nugget, additive = "afvArea")