plot_predict: Prediction intervals for walker object

View source: R/plot_predict.R

plot_predictR Documentation

Prediction intervals for walker object

Description

Plots sample quantiles and posterior means of the predictions of the predict.walker_fit output.

Usage

plot_predict(object, draw_obs = NULL, level = 0.05, alpha = 0.33)

Arguments

object

An output from predict.walker_fit().

draw_obs

Either "response", "mean", or "none", where "mean" is response variable divided by number of trials or exposures in case of binomial/poisson models.

level

Level for intervals. Default is 0.05, leading to 90% intervals.

alpha

Transparency level for ggplot2::geom_ribbon().

Examples

set.seed(1)
n <- 60
slope <- 0.0001 + cumsum(rnorm(n, 0, sd = 0.01))
beta <- numeric(n)
beta[1] <- 1
for(i in 2:n) beta[i] <- beta[i-1] + slope[i-1]
ts.plot(beta)                
x <- rnorm(n, 1, 0.5)
alpha <- 2
ts.plot(beta * x)

signal <- alpha + beta * x
y <- rnorm(n, signal, 0.25)
ts.plot(cbind(signal, y), col = 1:2)
data_old <- data.frame(y = y[1:(n-10)], x = x[1:(n-10)])

# note very small number of iterations for the CRAN checks!
rw2_fit <- walker(y ~ 1 + 
                    rw2(~ -1 + x,
                        beta = c(0, 10), 
                        nu = c(0, 10)),
                  beta = c(0, 10), data = data_old,
                  iter = 300, chains = 1, init = 0, refresh = 0)

pred <- predict(rw2_fit, newdata = data.frame(x=x[(n-9):n]))
data_new <- data.frame(t = (n-9):n, y = y[(n-9):n])
plot_predict(pred) + 
  ggplot2::geom_line(data = data_new, ggplot2:: aes(t, y), 
  linetype = "dashed", colour = "red", inherit.aes = FALSE)


walker documentation built on Sept. 11, 2024, 8:33 p.m.