1 |
n_bins |
|
n_stations |
|
SpatialScale |
|
SD_omega |
|
SD_nu |
|
SD_delta |
|
SD_extra |
|
rho |
|
logMeanDens |
|
Loc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (n_bins = 10, n_stations = 20, SpatialScale = 0.1, SD_omega = 0.5,
SD_nu = 0.2, SD_delta = 0.2, SD_extra = 0.1, rho = 0.8, logMeanDens = 1,
Loc = NULL)
{
require(RandomFields)
if (is.null(Loc))
Loc = cbind(x = runif(n_stations, min = 0, max = 1),
y = runif(n_stations, min = 0, max = 1))
model_omega <- RMgauss(var = SD_omega^2, scale = SpatialScale)
model_delta <- RMgauss(var = SD_delta^2, scale = SpatialScale)
Nu_b = logMeanDens - (1 - rho) * 1:n_bins
Delta_s = RFsimulate(model = model_delta, x = Loc[, "x"],
y = Loc[, "y"])@data[, 1]
Omega_sb = matrix(NA, nrow = n_stations, ncol = n_bins)
Omega_sb[, 1] = RFsimulate(model = model_omega, x = Loc[,
"x"], y = Loc[, "y"])@data[, 1]
for (b in 2:n_bins) {
Omega_sb[, b] = rho * Omega_sb[, b - 1] + RFsimulate(model = model_omega,
x = Loc[, "x"], y = Loc[, "y"])@data[, 1]
}
log_chat_sb = outer(rep(1, n_stations), Nu_b) + outer(Delta_s,
rep(1, n_bins)) + Omega_sb
c_sb = matrix(rbinom(n_stations * n_bins, size = 1, prob = 1 -
exp(-1 * exp(log_chat_sb))), nrow = n_stations, ncol = n_bins)
c_sb = ifelse(c_sb == 1, rlnorm(n_stations * n_bins, meanlog = log_chat_sb,
sdlog = 1), 0)
ReturnList = list(Loc = Loc, Nu_b = Nu_b, Delta_s = Delta_s,
Omega_sb = Omega_sb, c_sb = c_sb)
return(ReturnList)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.