plot.ctsmTMB.fit: This function creates residual plots for an estimated ctsmTMB...

View source: R/methods.R

plot.ctsmTMB.fitR Documentation

This function creates residual plots for an estimated ctsmTMB object

Description

This function creates residual plots for an estimated ctsmTMB object

Usage

## S3 method for class 'ctsmTMB.fit'
plot(
  x,
  print.plot = 1,
  type = "residuals",
  state.type = "prior",
  against.obs = NULL,
  ggtheme = getggplot2theme(),
  ...
)

Arguments

x

A R6 ctsmTMB fit object

print.plot

a single integer determining which element out of all states/observations (depending on the argument to type).

type

a character vector either 'residuals' or 'states' determining what to plot.

state.type

a character vector either 'prior', 'posterior' or 'smoothed' determining what kind of states to plot.

against.obs

name of an observation to plot state predictions against.

ggtheme

ggplot2 theme to use for creating the ggplot.

...

additional arguments

Value

a (list of) ggplot residual plot(s)

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)

# plot residuals
plot(fit)

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

ctsmTMB documentation built on April 12, 2025, 1:45 a.m.