setVars: Assign Values to State Variables

Description Arguments Value Note Author(s) See Also Examples

Description

Assign values to state variables of a rodeo-based model.

Arguments

x

A numeric vector or array, depending on the model's spatial dimensions. See details below.

Value

NULL (invisible). The assigned numeric data are stored in the object and can be accessed by the getVars method.

Note

For a 0-dimensional model (i.e. a model without spatial resolution), x must be a numeric vector whose length equals the number of state variables. The element names of x must match those returned by the object's namesVars method. See the examples for how to bring the vector elements into required order.

For models with a spatial resolution, x must be a numeric array of proper dimensions. The last dimension (cycling slowest) corresponds to the variables and the first dimension (cycling fastest) corresponds to the models' highest spatial dimension. Thus, dim(x) must be equal to c(rev(obj$getDim()), obj$namesVars()) where obj is the object whose variables are to be assigned. The names of the array's last dimension must match the return value of obj$namesVars().

In the common 1-dimensional case, this just means that x must be a matrix with column names matching the return value of obj$namesVars() and as many rows as given by obj$getDim().

Author(s)

david.kneis@tu-dresden.de

See Also

The corresponding 'get' method is getVars. Use setPars to assign values to parameters rather than variables.

Examples

 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
data(vars, pars, funs, pros, stoi)
x0 <- c(bac=0.1, sub=0.5)

# 0-dimensional model
model <- rodeo$new(vars, pars, funs, pros, stoi, dim=c(1))
model$setVars(x0)
print(model$getVars())

# How to sort vector elements
x0 <- c(sub=0.5, bac=0.1)              # doesn't match order of variables
model$setVars(x0[model$namesVars()])

# 1-dimensional model with 3 boxes
nBox <- 3
model <- rodeo$new(vars, pars, funs, pros, stoi, dim=c(nBox))
x1 <- matrix(rep(x0, each=nBox), nrow=nBox, ncol=model$lenVars(),
  dimnames=list(NULL, model$namesVars()))
model$setVars(x1)
print(model$getVars())
print(model$getVars(asArray=TRUE))

# 2-dimensional model with 3 x 4 boxes
model <- rodeo$new(vars, pars, funs, pros, stoi, dim=c(3,4))
x2 <- array(rep(x0, each=3*4), dim=c(4,3,model$lenVars()),
  dimnames=list(dim2=NULL, dim1=NULL, variables=model$namesVars()))
model$setVars(x2)
print(model$getVars())
print(model$getVars(asArray=TRUE))

Example output

bac sub 
0.1 0.5 
bac.1 bac.2 bac.3 sub.1 sub.2 sub.3 
  0.5   0.5   0.5   0.1   0.1   0.1 
           variable
dimension.1 bac sub
          1 0.5 0.1
          2 0.5 0.1
          3 0.5 0.1
bac.1.1 bac.1.2 bac.1.3 bac.1.4 bac.2.1 bac.2.2 bac.2.3 bac.2.4 bac.3.1 bac.3.2 
    0.5     0.5     0.5     0.5     0.5     0.5     0.5     0.5     0.5     0.5 
bac.3.3 bac.3.4 sub.1.1 sub.1.2 sub.1.3 sub.1.4 sub.2.1 sub.2.2 sub.2.3 sub.2.4 
    0.5     0.5     0.1     0.1     0.1     0.1     0.1     0.1     0.1     0.1 
sub.3.1 sub.3.2 sub.3.3 sub.3.4 
    0.1     0.1     0.1     0.1 
, , variable = bac

           dimension.1
dimension.2   1   2   3
          1 0.5 0.5 0.5
          2 0.5 0.5 0.5
          3 0.5 0.5 0.5
          4 0.5 0.5 0.5

, , variable = sub

           dimension.1
dimension.2   1   2   3
          1 0.1 0.1 0.1
          2 0.1 0.1 0.1
          3 0.1 0.1 0.1
          4 0.1 0.1 0.1

rodeo documentation built on March 28, 2021, 1:09 a.m.