# Fits a local level model for the Nile data
library(datasets)
y <- matrix(Nile)
fit <- statespacer(initial = 10, y = y, local_level_ind = TRUE)
# Obtain random sample using the fitted model
sim <- SimSmoother(fit, nsim = 1, components = TRUE)
# Plot the simulated level against the smoothed level of the original data
plot(sim$level[, 1, 1], type = 'p')
lines(fit$smoothed$level, type = 'l')
Run the code above in your browser using DataLab