Learn R Programming

SimInf (version 6.5.1)

run_outer: Run SimInf_model on scaled parameters

Description

Run SimInf_model on scaled parameters

Usage

run_outer(x, y, model, formula = NULL, FUN = NULL, ...)

Arguments

x

Scale the model gdata parameter values on the right hand side of the formula with x before calling FUN with the scaled model as argument.

y

Scale the model gdata parameter values on the left hand side of the formula with y before calling FUN with the scaled model as argument.

model

The siminf model to scale parameters on and run.

formula

The parameters in the gdata vector matching the left hand side of the formula a + b ~ c will be scaled by y. The parameters in the gdata vector matching the right hand side of the formula a + b ~ c will be scaled by x.

FUN

A function to use on the scaled model 'gdata' parameters.

...

Optional arguments to be passed to FUN.

Value

Array with dimension c(dim(x), dim(y)).

Examples

Run this code
# NOT RUN {
## Create an SIR-model with 100 nodes of 99 susceptible individuals
## and one infected individuals.
u0 <- data.frame(S = rep(99, 100), I = rep(1, 100), R = rep(0, 100))
model <- SIR(u0, 1:75, beta = 0.16, gamma = 0.077)

## Define scaling parameters
x <- seq(from = 0.2, to = 1.8, by = 0.1)
y <- seq(from = 0.2, to = 1.1, by = 0.1)

## Utility function to run the model and estimate the population
## prevalence on day 75.
pop_prev <- function(model) {
    result <- run(model)
    prevalence(result, I~., type = "pop", as.is = TRUE)[75]
}

## Scale 'gamma' with 'y' and 'beta' with 'x' and
## run the model and determine the population prevalence on day
## 500. For each combination of 'x' and 'y', the model parameters
## are scaled and the function 'pop_prev' called with the
## perturbed model.
pop <- run_outer(x, y, model, gamma ~ beta, pop_prev)

## Plot result
contour(x * model@gdata["beta"], y * model@gdata["gamma"],
        pop, method = "edge", bty = "l")

## Utility function to run the model and estimate the node
## prevalence on day 75.
node_prev <- function(model) {
    result <- run(model)
    prevalence(result, I~., type = "nop", as.is = TRUE)[75]
}

## Scale 'gamma' with 'y' and 'beta' with 'x' and
## run the model and determine the node prevalence on day
## 500. For each combination of 'x' and 'y', the model parameters
## are scaled and the function 'node_prev' called with the
## perturbed model.
nop <- run_outer(x, y, model, gamma ~ beta, node_prev)

## Plot result
contour(x * model@gdata["beta"], y * model@gdata["gamma"],
        nop, method = "edge", bty = "l")
# }

Run the code above in your browser using DataLab