View source: R/MC.analysis_generic.R
MC.analysis_generic | R Documentation |
General function for running the analysis of the Monte Carlo simulation.
MC.analysis_generic(x, delta, qUpper, data.det, sim.det, event.ini, event.end,
ntick, summ.data = NULL)
x |
A |
delta |
A |
qUpper |
A |
data.det |
A |
sim.det |
A |
.
event.ini |
A time-date string in |
event.end |
A time-date string in |
ntick |
A |
summ.data |
A |
A list
of length 2:
summ |
A |
variance |
A |
J.A. Torres-Matallana
See also setup-class
, MC.setup-methods
, MC.sim-methods
.
## Creating meta-model
Model <- function(A, B, variable.1, variable.2){
lum <- A*variable.1 + B*variable.2
}
## Model input and parameter set-up
time <- data.frame(time = seq.POSIXt(from = as.POSIXct("2019-01-01"),
to = as.POSIXct("2019-01-02"), by = 60*60*6))
data <- cbind(time, data = 25)
data
new.setup <- setup(id = "MC_1",
nsim = 10,
seed = 123,
mcCores = 1,
ts.input = data,
rng = rng <- list(
A = 1.25,
B = 0.75,
variable.1 = c(pdf = "uni", min = 0, max = 4),
variable.2 = c(pdf = "uni", min = 2.2, max = 3.2)
)
)
str(new.setup)
## Monte Carlo simulation set-up
set.seed(slot(new.setup, "seed"))
new.mc.setup <- MC.setup(new.setup)
str(new.mc.setup)
## Monte Carlo simulation
output <- data.frame(time = new.mc.setup$ts.input[,1])
output[,2:(new.mc.setup$nsim + 1)] <- NA
for(i in 1:new.mc.setup$nsim){
for(j in 1:nrow(new.mc.setup$ts.input)){
## model parameter definition
A <- new.mc.setup$par$A
B <- new.mc.setup$par$B
## model input definition
variable.1 <- new.mc.setup$par$variable.1[i,j]
variable.2 <- new.mc.setup$par$variable.2[i,j]
## model evaluation
output[j,i+1] <- Model(A, B, variable.1, variable.2)
}
}
output <- list(output1 = output)
output
## Deterministic simulation
# model parameter definition
A <- new.mc.setup$par$A
B <- new.mc.setup$par$B
# model input definition
variable.1.det <- apply(X = new.mc.setup$par$variable.1, MARGIN = 2, FUN = mean)
variable.2.det <- apply(X = new.mc.setup$par$variable.2, MARGIN = 2, FUN = mean)
output.det <- Model(A, B, variable.1.det, variable.2.det)
output.det <- cbind(time, output.det)
output.det <- list(out1 = output.det)
str(output.det)
## Monte Carlo analysis
delta <- 60*6 # minutes
qUpper <- "q95"
event.ini <- data$time[1]
event.end <- data$time[nrow(data)]
ntick <- 1
analysis <- MC.analysis_generic(x = output, delta = delta, qUpper = qUpper, data.det = data,
sim.det = output.det, event.ini = event.ini, event.end = event.end,
ntick = ntick)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.