Learn R Programming

⚠️There's a newer version (1.2.12) of this package.Take me there.

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 Generalized Dynamic Linear Models (GDLM), 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.0

License

GPL (>= 3)

Maintainer

Silvaneo Vieira dos Santos Junior

Last Published

May 25th, 2024

Functions in kDGLM (1.2.0)

block_rename

block_rename
convert_Normal_Multinom

convert_Normal_Multinom
block_superpos

Auxiliary function for block superposition
dmvnorm

dmvnorm
coef.fitted_dlm

coef.fitted_dlm
cornWheat

Corn and wheat prices from 1986 to 2014
convert_multi_NG_Normal

convert_multi_NG_Normal
convert_Poisson_Normal

convert_Poisson_Normal
create_G

create_G
block_mult

Auxiliary function to replicate blocks
coefficients.fitted_dlm

coefficients.fitted_dlm
convert_Normal_Poisson

convert_Normal_Poisson
bdiag

bdiag
convert_Multinom_Normal

convert_Multinom_Normal
convert_Normal_Gamma

convert_Normal_Gamma
eval_dlm_log_like

Auxiliary function for evaluating the prior density of a DLM
fit_model

Fitting kDGLM models
fit_model_single

Fitting one kDGLM models
if.nan

if.nan
if.na

if.na
f_root

f_root
f_joint_root

f_joint_root
colQuantile

colQuantile
convert_Gamma_Normal

convert_Gamma_Normal
eval_dlm_post

Auxiliary function for evaluating the posterior density of a DLM
eval_dlm_norm_const

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

if.null
array_transp

array_transp
eval_dlm_prior

Auxiliary function for evaluating the prior density of a DLM
print.searched_dlm

print.searched_dlm
print.fitted_dlm

print.fitted_dlm
evaluate_max

evaluate_max
intervention

An auxiliary function for model intervention
ginv

ginv
gastroBR

Hospital admissions from gastroenteritis in Brazil
harmonic_block

Structural blocks for seasonal trends and regressions
plot.dlm_coef

Visualizing latent states in a fitted kDGLM model
forecast.fitted_dlm

Auxiliary function for forecasting
plot.fitted_dlm

Visualizing a fitted kDGLM model
simulate.fitted_dlm

Draw samples from the distribution of the latent states
noticeSARI

SARI data from Belo Horizonte
normal_pred

normal_pred
print.dlm_distr

print.dlm_distr
multi_normal_gamma_pred

update_multi_NG_chol multi_normal_gamma_pred
print.dlm_block

print.dlm_block
joint_prior

Joint prior
summary.dlm_distr

Summary for a kDGLM outcome
gamma_pred

gamma_pred
noise_block

noise_block
*.dlm_block

*.fitted_dlm
generic_smoother

generic_smoother
summary.searched_dlm

Summary for a searched_dlm object
+.dlm_block

+.fitted_dlm
update_Poisson

update_Poisson
summary.fitted_dlm

Summary for a fitted kDGLM model
smoothing

Auxiliary function for model smoothing
reexports

Objects exported from other packages
regression_block

Structural blocks for regressions
lcm

lcm
poisson_pred

poisson_pred
rmvnorm

rmvnorm
multnom_pred

multnom_pred
polynomial_block

Structural blocks for polynomial trends and regressions
specify.dlm_block

Specify method for dlm blocks
var_decomp

var_decomp
rowQuantile

rowQuantile
update.fitted_dlm

update.fitted_dlm
update_Gamma

update_Gamma
update_Normal

update_Normal
summary.dlm_block

Summary for a kDGLM structure
update_multi_NG_correl

update_multi_NG_correl
update_NG2

update_NG
zero_sum_prior

Zero sum prior
update_Multinom

update_Multinom
update_NG

update_NG
array_collapse_right

array_collapse_right
Poisson

Poisson outcome for kDGLM models
Gamma

Gamma outcome for kDGLM models
Multinom

Multinom outcome for kDGLM models
Normal

Normal outcome for kDGLM models
CAR_prior

CAR prior
TF_block

Structural blocks for auto regressive trends and regressions
array_mult_left

array_mult_left
analytic_filter

analytic_filter
array_collapse_left

array_collapse_left
chickenPox

Hospital admissions by chicken pox in Brazil
check.block.status

check.block.status
array_mult_right

array_mult_right
base_ribbon

base_ribbon
base_block

Basic structural blocks