define_dglm
is a simple helper function to initialize a model. The primary arguments to pass in to define_dglm
are:
Y
andX
: The observations and predictorsfamily
: The observation family, which can be 'poisson', 'bernoulli', 'normal', or 'binomial'prior_length
: The number of observations to use for defining the model
You can pass in many other arguments, including anything accepted by dglm.__init__
, such as the number of trend components, the seasonal components, and the number of holidays. The number of regression predictors, nregn
, is automatically inferred from the number of columns in X
.
Below is a simple example of using define_dglm
to initialize a Poisson DGLM. In most PyBATS use cases, this function is called indirectly through analysis
. However, it can be useful to call directly to gain more control over customizing the model definition.
import numpy as np
import pandas as pd
from pybats.shared import load_sales_example
from pybats.define_models import define_dglm
data = load_sales_example()
Y = data['Sales'].values
X = data['Advertising'].values
mod = define_dglm(Y, X,
family='poisson',
prior_length=21,
ntrend=1,
nhol=0,
seasPeriods=[7],
seasHarmComponents=[[1,2,3]]
)
mod.get_coef()
These functions are the core of define_dglm
. They take the first prior_length
data points and fit a static, non-dynamic, generalized linear model (GLM), to initialize the DGLM.
Dynamic Count Mixture Models are the combination of a Bernoulli and Poisson DGLM. define_dcmm
is a convenient wrapper to help initialize both components of the dcmm
together, and is called automatically by analysis_dcmm
.
Dynamic Binary Cascade Models are the combination of a DCMM and a cascade of binomial DGLMs. define_dbcm
is a convenient wrapper to help initialize all of the components of a dbcm
together, and is called automatically by analysis_dbcm
.
Dynamic Linear Mixture Models are the combination of a Bernoulli DGLM and a Normal DLM. define_dlmm
is a convenient wrapper to help initialize both components of the dlmm
together, and is called automatically by analysis_dlmm
.