Learn R Programming

kDGLM: An R package for Bayesian analysis of Generalized Dynamic Linear Models

Welcome to the kDGLM GitHub repository! kDGLM is an innovative R package tailored for Bayesian analysis of Dynamic Generalized Linear Models (DGLM), catering to both uni- and multivariate exponential families. This package is your go-to tool for sequential inference on time series data, offering a broad spectrum of functionalities including fitting, smoothing, monitoring, and feed-forward interventions.

Developed based on the methodology proposed in Alves et al.(2024), kDGLM integrates seamlessly with established techniques in the literature, particularly those applied in Gaussian Dynamic Models. It supports various features such as discount strategies, autoregressive components, transfer functions, and more, leveraging the Kalman filter and smoothing properties for exceptional computational efficiency. With kDGLM, you can expect almost instantaneous fitting times that scale linearly with your time series length, making it an invaluable tool for analyzing extended time series datasets.

Currently, kDGLM supports a variety of distributions, including:

  • Univariate Normal (with unknown mean and observational variance);
  • Bivariate Normal (with unknown means, observational variances, and correlation);
  • Poisson;
  • Gamma (with known shape and unknown mean);
  • Multinomial (with known number of trials and unknown event probabilities).

Furthermore, kDGLM allows for the joint modeling of multiple time series, provided each series adheres to one of the supported distributions. Our ongoing development efforts are focused on continuously expanding the range of supported distributions to enhance the package's versatility.

Whether you are analyzing time series data for research, business intelligence, or any other purpose, kDGLM offers a powerful, efficient, and comprehensive solution for your needs. Explore our documentation to get started and join the community of users benefiting from the advanced capabilities of kDGLM!

Installation

Dependencies

Before installing kDGLM, ensure you have the following dependencies installed in your R environment:

  • extraDistr >= 1.9.1
  • cubature >= 2.1.0
  • Rfast >= 2.0.8
  • generics >= 0.1.3

Additionally, for an enhanced plotting experience, we recommend installing the ggplot2 and plotly packages, which augment the built-in plot methods provided by kDGLM.

Installing kDGLM

As of now, kDGLM is available directly from its GitHub repository. While we are in the process of submitting kDGLM to CRAN, you can install the latest version of the package by executing the following command in your R console:

remotes::install_github('silvaneojunior/kDGLM')

This command uses the remotes package to install kDGLM. If you do not have remotes installed, you can install it first by running install.packages("remotes").

Getting Started

After installation, load kDGLM into your R session:

library(kDGLM)

To test if the package is working properly, execute the following code exemple:

 # Poisson case
 data <- c(AirPassengers)

 level <- polynomial_block(rate = 1, order = 2, D = 0.95)
 season <- harmonic_block(rate = 1, order = 2, period = 12, D = 0.975)

 outcome <- Poisson(lambda = "rate", data = data)

 fitted.data <- fit(level, season,
   AirPassengers = outcome
 )
 summary(fitted.data)

plot(fitted.data, plot.pkg = "base")

Refer to the vignettes for detailed usage instructions. Also see the documentation of the fit method for basic examples for each type of outcome the kDGLM package offers.

Contributing

We welcome contributions! If you're interested in improving kDGLM, please consider submitting bug reports, feature requests, or pull requests.

Acknowledgements

  • Raíra Marotta, who gently provided the base code for the initial versions.

Contact

For support or to provide feedback, please contact Silvaneo dos Santos Jr. or open an issue on the GitHub repository.

Copy Link

Version

Install

install.packages('kDGLM')

Monthly Downloads

133

Version

1.2.12

License

GPL (>= 3)

Maintainer

Silvaneo dos Santos Jr.

Last Published

February 4th, 2026

Functions in kDGLM (1.2.12)

coefficients.fitted_dlm

coefficients.fitted_dlm
convert_Gamma_Normal

convert_Gamma_Normal
eval_dlm_log_like

Auxiliary function for evaluating the prior density of a DLM
convert_Multinom_Normal

convert_Multinom_Normal
eval_dlm_norm_const

Auxiliary function for evaluating normalizing constant for the posterior of a fitted DLM.
colQuantile

colQuantile
convert_Normal_Poisson

convert_Normal_Poisson
forecast.fitted_dlm

Auxiliary function for forecasting
ffs_block

Structural blocks for free-form seasonal trends and regressions
formula.to.structure

formula.to.structure
bdiag

bdiag
create_G

create_G
convert_Normal_Gamma

convert_Normal_Gamma
dmvnorm

dmvnorm
convert_Poisson_Normal

convert_Poisson_Normal
convert_Normal_Multinom

convert_Normal_Multinom
f_root

f_root
f_joint_root

f_joint_root
evaluate_max

evaluate_max
harmonic_block

Structural blocks for seasonal trends and regressions
if.na

if.na
multi_normal_gamma_pred

update_multi_NG_chol multi_normal_gamma_pred
gastroBR

Hospital admissions from gastroenteritis in Brazil
kdglm

Fitting kDGLM models
gamma_pred

gamma_pred
noise_block

noise_block
multnom_pred

multnom_pred
intervention

An auxiliary function for model intervention
fit_model_single

Fitting one kDGLM models
fit_model

Fitting kDGLM models
eval_dlm_prior

Auxiliary function for evaluating the prior density of a DLM
plot.fitted_dlm

Visualizing a fitted kDGLM model
+.dlm_block

+.fitted_dlm
print.fitted_dlm

print.fitted_dlm
print.searched_dlm

print.searched_dlm
cornWheat

Corn and wheat prices from 1986 to 2014
eval_dlm_post

Auxiliary function for evaluating the posterior density of a DLM
convert_multi_NG_Normal

convert_multi_NG_Normal
smoothing

Auxiliary function for model smoothing
simulate.fitted_dlm

Draw samples from the distribution of the latent states
joint_prior

Joint prior
polynomial_block

Structural blocks for polynomial trends and regressions
poisson_pred

poisson_pred
specify.dlm_block

Specify method for dlm blocks
rmvnorm

rmvnorm
summary.dlm_block

Summary for a kDGLM structure
lcm

lcm
update_NG

update_NG
print.dlm_block

print.dlm_block
update_NG2

update_NG
print.dlm_distr

print.dlm_distr
update_Multinom

update_Multinom
update_Gamma

update_Gamma
update_Normal

update_Normal
rowQuantile

rowQuantile
update_Poisson

update_Poisson
generic_smoother

generic_smoother
ginv

ginv
if.nan

if.nan
summary.fitted_dlm

Summary for a fitted kDGLM model
TF_block

Structural blocks for auto regressive trends and regressions
zero_sum_prior

Zero sum prior
summary.dlm_distr

Summary for a kDGLM outcome
summary.searched_dlm

Summary for a searched_dlm object
if.null

if.null
normal_pred

normal_pred
noticeSARI

SARI data from Belo Horizonte
regression_block

Structural blocks for regressions
plot.dlm_coef

Visualizing latent states in a fitted kDGLM model
reexports

Objects exported from other packages
*.dlm_block

*.fitted_dlm
update.fitted_dlm

update.fitted_dlm
update_multi_NG_correl

update_multi_NG_correl
var_decomp

var_decomp
array_collapse_right

array_collapse_right
Gamma

Gamma outcome for kDGLM models
Normal

Normal outcome for kDGLM models
Multinom

Multinom outcome for kDGLM models
Poisson

Poisson outcome for kDGLM models
CAR_prior

CAR prior
block_rename

block_rename
block_mult

Auxiliary function to replicate blocks
coef.fitted_dlm

coef.fitted_dlm
array_mult_left

array_mult_left
chickenPox

Hospital admissions by chicken pox in Brazil
analytic_filter

analytic_filter
array_mult_right

array_mult_right
array_collapse_left

array_collapse_left
base_block

Basic structural blocks
array_transp

array_transp
base_ribbon

base_ribbon
block_superpos

Auxiliary function for block superposition
check.block.status

check.block.status