dllm: Fit a Dynamic Local Level Model (DLM)

View source: R/dllm.R

dllmR Documentation

Fit a Dynamic Local Level Model (DLM)

Description

Fits a dynamic linear model (DLM) using maximum likelihood estimation.

Usage

dllm(
  data,
  obs_cols,
  S = c("univariate", "kvariate"),
  log10 = FALSE,
  date = NULL,
  prior = list(),
  equal.state.var = FALSE,
  equal.obs.var = FALSE,
  init_params = NULL,
  auto_init = TRUE,
  control = list(maxit = 500)
)

Arguments

data

A data frame containing observed time series data.

obs_cols

Character vector of column names in data to be used as observations.

S

Character; the structure of latent states.

log10

logical; if TRUE, a log10 transformation is applied to the whole data.

date

Optional; the name of the column in data representing date or time.

prior

A list of prior specifications. Default priors are used if not supplied.

equal.state.var

logical; if TRUE the variance is the same across all wastewater state.

equal.obs.var

logical; if TRUE the variance is the same across all wastewater observation.

init_params

Optional numeric vector of initial parameters.

auto_init

Logical; if TRUE (default) and init_params is NULL, initial parameters are estimated automatically.

control

List of control parameters for the optimization routine (dlmMLE).

Details

The function prepares the data, validates inputs, and (if necessary) automatically initializes parameters. It then defines a helper function to build the model via build_dlm and fits the model using maximum likelihood estimation (dlmMLE). Filtering and smoothing are applied to obtain state estimates.

Value

An object of class dllm containing the fitted model, filtered and smoothed estimates, along with fit statistics (log-likelihood, AIC, BIC) and other diagnostic information.

data

The input data.

date

The input vector of date.

obs_cols

Character vector of column names in data to be used as observations.

S

Character; the structure of latent states.

parameters

A list of estimated parameters by maximum likelihood estimation.

logLik

The loglikelihood of the fitted model.

aic

AIC of the fitted model.

bic

BIC of the fitted model.

convergence

An integer code returned by optim

model

An dlm object of the fitted dynamic linear model.

filter

The corresponding dynamic linear filter returned by dlmFilter

smoother

The corresponding dynamic linear smoother returned by dlmSmooth

yf

A matrix of the filtered observed response variables.

ys

A matrix of the smoothed observed response variables.

Examples

data<- wastewater[wastewater$Code == "TC",]
data$SampleDate <- as.Date(data$SampleDate)
fit <- dllm(
equal.state.var=TRUE,
equal.obs.var=FALSE,
log10=TRUE,
data = data,
date = "SampleDate",
obs_cols = c("ORFlab", "Nlab"),
S = 'kvariate')
summary(fit)
plot(fit, type='smoother', plot_data = TRUE)


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