Extracts or replaces parts of an experiment object with new value(s).

Allows to build an object of class experiment from individual parts.

# S3 method for experiment
[(exp, i, j, ..., drop = TRUE)

experiment(parameters, obsrates, tmax, seed, experiment, model,
  dic = NULL)

is.experiment(exp)

Arguments

exp

object to be tested

i, j, ...

indices specifying elements to extract or replace. Indices are numeric or character vectors or empty (missing) or NULL.

drop

boolean, TRUE the result is coerced to the lowest possible dimension.

parameters

A data frame of numerical values giving the values of each parameter (in column), for each simulation (in row).

obsrates

A data frame of positive integer values giving the periods, in time steps, at which observed variables are observed. Should have the same number of rows as parameters.

tmax

A positive integer vector, the length of which is either 1 or equal to the number of parameters and obsrates: it gives the end of simulations, in numbers of time steps.

seed

A numerical vector, the length of which is either 1 or equal to the number of parameters and obsrates: it gives the seeds of the simulations.

experiment

The name of an experiment of the GAML file model.

model

The path to a GAML file.

dic

A named vector of character strings. The values and the names of this vector should be consistent with the names of parameters, obsrates as well as the variables and parameters defined in the model GAML file. See Details for more information.

Value

An object of class experiment

An object of class experiment.

The function returns `TRUE` or `FALSE` depending on whether its argument is of chatacter type or not

Details

The class experiment inherits from the class tibble (tbl_df). It contains parameters values as well as periods of observation of the observed variables and it connects to a GAML file that specifies the full model.

TO DO: Explains what dic is.

Examples

## experiment ## exp0 <- experiment( data.frame(S0 = 999, I0 = 1, R0 = 0, beta = 1.5, gamma = .15), data.frame(S = 1, I = 1, R = 1), 1000, 1, "sir", system.file("models", "sir.gaml", package = "gamar"))
#> Periods of observation ("obsrates") are converted into integers.
#>
#> Final time step ("tmax") is converted into integer.
#>
#> Parameters' types are cast according to model definition
#>
print(exp0)
#> Experiment with 1 simulation of 5 parameters and 3 observed variables #> experiment name: sir #> input gaml file: /Users/mac/Desktop/gamar/inst/models/sir.gaml #> model parameters: p_S0, p_I0, p_R0, p_beta, p_gamma #> observed variables: r_S, r_I, r_R #> Experiment overview: #> p_S0 p_I0 p_R0 p_beta p_gamma r_S r_I r_R tmax seed output #> 1 999 1 0 1.5 0.15 1 1 1 1000 1 NA
## is.experiment ## # to test if an object is a class `experiment` df <- data.frame("S0" = rep(999, 5), "I0" = rep(1, 5), "R0" = rep(0, 5), "beta" = rep(1.5, 5), "gamma" = runif (5, 0, 1), "S" = rep(1, 5), "I" = rep(1, 5), "R" = rep(1, 5), "a" = rep(1000, 5), "b" = rep(1, 5)) exp <- as_experiment(df, parameters = c("S0", "I0", "R0", "beta", "gamma"), obsrates = c("S", "I", "R"), tmax = "a", seed = "b", experiment = "sir", model = system.file("models", "sir.gaml", package = "gamar"))
#> Periods of observation ("obsrates") are converted into integers.
#>
#> Final time step ("tmax") is converted into integer.
#>
#> Parameters' types are cast according to model definition
#>
is.experiment(exp)
#> [1] TRUE
# Here is an experiment with 1 simulation: sir1 <- load_experiment("sir", system.file("models", "sir.gaml", package = "gamar"))
#> Loading experiment "sir" from file "sir.gaml"...
#>
#> Periods of observation ("obsrates") are converted into integers.
#>
#> Final time step ("tmax") is converted into integer.
#>
#> Seed is converted into numeric.
#>
#> Parameters' types are cast according to model definition
#>
sir1
#> Experiment with 1 simulation of 5 parameters and 3 observed variables #> experiment name: sir #> input gaml file: /Users/mac/Desktop/gamar/inst/models/sir.gaml #> model parameters: p_S0, p_I0, p_R0, p_beta, p_gamma #> observed variables: r_S, r_I, r_R #> Experiment overview: #> p_S0 p_I0 p_R0 p_beta p_gamma r_S r_I r_R tmax seed output #> 1 999 1 0 1.5 0.15 1 1 1 1000 1 NA
sir2 <- sir1 # If we now replace the values of "p_S0" of "sir2" by a single value: sir2$p_S0 <- 2 sir2
#> Experiment with 1 simulation of 5 parameters and 3 observed variables #> experiment name: sir #> input gaml file: /Users/mac/Desktop/gamar/inst/models/sir.gaml #> model parameters: p_S0, p_I0, p_R0, p_beta, p_gamma #> observed variables: r_S, r_I, r_R #> Experiment overview: #> p_S0 p_I0 p_R0 p_beta p_gamma r_S r_I r_R tmax seed output #> 1 2 1 0 1.5 0.15 1 1 1 1000 1 NA
# If you wish to delete one column: sir2$r_R <- NULL sir2
#> Experiment with 1 simulation of 5 parameters and 2 observed variables #> experiment name: sir #> input gaml file: /Users/mac/Desktop/gamar/inst/models/sir.gaml #> model parameters: p_S0, p_I0, p_R0, p_beta, p_gamma #> observed variables: r_S, r_I #> Experiment overview: #> p_S0 p_I0 p_R0 p_beta p_gamma r_S r_I tmax seed output #> 1 2 1 0 1.5 0.15 1 1 1000 1 NA