Skip to contents

Plot of k-step predictions from a ctsmTMB prediction object

Usage

# S3 method for class 'ctsmTMB.pred'
plot(
  x,
  y,
  k.ahead = unique(x[["states"]][["k.ahead"]]),
  state.name = NULL,
  type = "states",
  against = NULL,
  ...
)

Arguments

x

a ctsmTMB.pred object

y

not used

k.ahead

an integer indicating which k-ahead predictions to plot

state.name

a string indicating which states to plot

type

one of 'states' or 'observations', to plot

against

name of an observations to plot predictions against

...

additional arguments

Value

A plot of predicted states

Examples

library(ctsmTMB)
model <- ctsmTMB$new()

# create model
model$addSystem(dx ~ theta * (mu+u-x) * dt + sigma_x*dw)
model$addObs(y ~ x)
model$setVariance(y ~ sigma_y^2)
model$addInput(u)
model$setParameter(
  theta   = c(initial = 1, lower=1e-5, upper=50),
  mu      = c(initial=1.5, lower=0, upper=5),
  sigma_x = c(initial=1, lower=1e-10, upper=30),
  sigma_y = 1e-2
)
model$setInitialState(list(1,1e-1))

# fit model to data
fit <- model$estimate(Ornstein)
#> Checking model components...
#> Checking and setting data...
#> Constructing objective function and derivative tables...
#> Minimizing the negative log-likelihood...
#>   0:     160.35328:  1.00000  1.50000  1.00000
#>  10:     89.603625:  2.58436  2.91384  1.15608
#> 	 Optimization finished!:
#>             Elapsed time: 0.008 seconds.
#>             The objective value is: 7.387879e+01
#>             The maximum gradient component is: 9.9e-08
#>             The convergence message is: relative convergence (4)
#>             Iterations: 19
#>             Evaluations: Fun: 29 Grad: 20
#>             See stats::nlminb for available tolerance/control arguments.
#> Returning results...
#> Finished!

# perform moment predictions
pred <- model$predict(Ornstein)
#> Checking and setting data...
#> Predicting with R...
#> Returning results...
#> Finished!

# plot the k.ahead=10 predictions
plot(pred, against="y.data")


# plot filtered states
plot(fit, type="states", against="y")