plot.ctKalmanDF: Plots Kalman filter output from ctKalman.

Description Usage Arguments Value Examples

View source: R/ctKalman.R

Description

Plots Kalman filter output from ctKalman.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## S3 method for class 'ctKalmanDF'
plot(
  x,
  subjects = unique(x$Subject),
  kalmanvec = c("y", "yprior"),
  errorvec = "auto",
  errormultiply = 1.96,
  plot = TRUE,
  elementNames = NA,
  polygonsteps = 10,
  polygonalpha = 0.1,
  facets = vars(Variable),
  ...
)

Arguments

x

Output from ctKalman. In general it is easier to call ctKalman directly with the plot=TRUE argument, which calls this function.

subjects

vector of integers denoting which subjects (from 1 to N) to plot predictions for.

kalmanvec

string vector of names of any elements of the output you wish to plot, the defaults of 'y' and 'ysmooth' plot the original data, 'y', and the estimates of the 'true' value of y given all data. Replacing 'y' by 'eta' will plot latent states instead (though 'eta' alone does not exist) and replacing 'smooth' with 'upd' or 'prior' respectively plots updated (conditional on all data up to current time point) or prior (conditional on all previous data) estimates.

errorvec

vector of names indicating which kalmanvec elements to plot uncertainty bands for. 'auto' plots all possible.

errormultiply

Numeric denoting the multiplication factor of the std deviation of errorvec objects. Defaults to 1.96, for 95% intervals.

plot

if FALSE, plots are not generated and the ggplot object is simply returned invisibly.

elementNames

if NA, all relevant object elements are included – e.g. if yprior is in the kalmanvec argument, all manifest variables are plotted, and likewise for latent states if etasmooth was specified. Alternatively, a character vector specifying the manifest and latent names to plot explicitly can be specified.

polygonsteps

Number of steps to use for uncertainty band shading.

polygonalpha

Numeric for the opacity of the uncertainty region.

facets

when multiple subjects are included in multivariate plots, the default is to facet plots by variable type. This can be set to NA for no facets, or vars(Subject) for facetting by subject.

...

not used.

Value

A ggplot2 object. Side effect – Generates plots.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
if(w32chk()){


### Get output from ctKalman
x<-ctKalman(ctstantestfit,subjects=2,timestep=.01)

### Plot with plot.ctKalmanDF
plot(x, subjects=2)

###Single step procedure:
ctKalman(ctstantestfit,subjects=2,
  kalmanvec=c('y','yprior'),
  elementNames=c('Y1','Y2'), 
  plot=TRUE,timestep=.01)
}

ctsem documentation built on July 23, 2021, 5:07 p.m.