pdlm: Build a Predictive Dynamic Linear Model (pdlm) for...

View source: R/pdlm.R

pdlmR Documentation

Build a Predictive Dynamic Linear Model (pdlm) for wastewater-based epidemiology

Description

Constructs a dynamic linear model (DLM) object using the dlm package.

Usage

pdlm(
  data,
  formula,
  lags = 0,
  log10 = TRUE,
  date = NULL,
  prior = list(),
  equal.state.var = TRUE,
  equal.obs.var = TRUE,
  init_params = list(),
  auto_init = TRUE,
  control = list(maxit = 500)
)

Arguments

data

A data frame containing the variables in the model.

formula

An object of class "formula" describing the model to be fitted.

lags

A nonnegative integer indicating the lag of the latent state in the model.

log10

Logical; if TRUE, a log10 transformation is applied to the entire dataset.

date

An optional vector of date indices of the data.

prior

An optional list specifying the prior mean vector and covariance structure of the latent state. If not provided, a naive prior is used.

equal.state.var

Logical; if TRUE, the same variance is assumed across all state components.

equal.obs.var

Logical; if TRUE, the same variance is assumed across all observation components.

init_params

An optional list of initial parameters for the model. Should include Ft, Wt, and Vt: transition coefficients, state variance, and observation variance components respectively.

auto_init

Logical; if TRUE, naive initial parameters are used.

control

An optional list of control parameters for optim().

Value

A dlm object with additional attributes:

formula

The fitted formula.

lags

Number of lags.

data

The input data.

date

The input vector of dates.

parameters

A list of estimated parameters.

logLik

Log-likelihood of the fitted model.

aic

Akaike Information Criterion.

bic

Bayesian Information Criterion.

convergence

The convergence code from optim.

model

The final dlm object.

filter

Output from dlmFilter.

ypred

One-step-ahead predictions.

var.pred

Variance of the predictions.

Examples


data <- wastewaterhealthworker[wastewaterhealthworker$Code == "TC",]
data$SampleDate <- as.Date(data$SampleDate)
fit <- pdlm(
  formula=HealthWorkerCaseCount~WW.tuesday+WW.thursday,
  data = data,
  lags = 2,
  equal.state.var=FALSE,
  equal.obs.var=FALSE,
  log10=TRUE,
  date = "SampleDate")
summary(fit)
plot(fit, conf.int = TRUE)



dlmwwbe documentation built on June 8, 2025, 10:07 a.m.