HierarchicalLaunchITS#
- class causalpy.pymc_models.HierarchicalLaunchITS[source]#
Hierarchical Bayesian interrupted time series model for multi-unit panels with unit-specific treatment (launch) times.
Each unit (e.g. a product) has its own launch time. Per-unit intercepts, covariate effects and launch “lift” are partially pooled toward shared population-level hyperparameters, which lets sparse units borrow strength from well-observed ones and yields a posterior distribution over the population lift that can be used to forecast the effect of a new unit.
Three effect parameterizations are supported via the experiment layer:
"instant": a single post-launch level shift per unit,lift[unit] ~ Normal(mu_lift, sigma_lift)."event_study": per-unit dynamic coefficientsdelta[unit, event_bin]over user-specified post-launch event-time bins (pre-launch is the implicit reference)."placebo": the event-study form extended with pre-launch leads; the most negative leads serve as placebos that should be indistinguishable from zero if the no-anticipation assumption holds.
All hierarchical parameters use a non-centered parametrization.
Expected inputs#
X:xr.DataArraywith dims["obs_ind", "coeffs"]holding the standardized covariate design (built by the experiment from a patsy formula, without an intercept — the hierarchicalalphaplays that role).y:xr.DataArraywith dims["obs_ind", "treated_units"]; the singletreated_unitsentry is retained for API consistency with the rest of CausalPy — the per-unit hierarchy is indexed via theunitcoord instead.aux(passed tofit()/predict()) : dict with keyseffect_type,unit_idx(int array of lengthn_obs) and, as appropriate,F(Fourier basis),post(0/1 indicator) andD(one-hot event-bin design).
See
causalpy.experiments.hierarchical_interrupted_time_series.HierarchicalInterruptedTimeSeriesfor the user-facing experiment wrapper that assemblesauxfrom a long panel DataFrame.Methods
HierarchicalLaunchITS.add_coord(name[, ...])Register a dimension coordinate with the model.
HierarchicalLaunchITS.add_coords(coords, *)Vectorized version of
Model.add_coord.Add a random graph variable to the named variables of the model.
HierarchicalLaunchITS.build_model(X, y, coords)Calculate the causal impact as the difference between observed and predicted values.
Check that the logp is defined and finite at the starting point.
HierarchicalLaunchITS.compile_d2logp([vars, ...])Compiled log probability density hessian function.
HierarchicalLaunchITS.compile_dlogp([vars, ...])Compiled log probability density gradient function.
HierarchicalLaunchITS.compile_fn(outs, *[, ...])HierarchicalLaunchITS.compile_logp([vars, ...])Compiled log probability density function.
Clone the model.
Create a
TensorVariablethat will be used as the random variable's "value" in log-likelihood graphs.HierarchicalLaunchITS.d2logp([vars, ...])Hessian of the models log-probability w.r.t.
HierarchicalLaunchITS.debug([point, fn, verbose])Debug model function at point.
HierarchicalLaunchITS.dlogp([vars, jacobian])Gradient of the models log-probability w.r.t.
Evaluate shapes of untransformed AND transformed free variables.
HierarchicalLaunchITS.fit(X, y[, coords, aux])Fit the hierarchical launch ITS model.
Compute the initial point of the model.
HierarchicalLaunchITS.logp([vars, jacobian, sum])Elemwise log-probability of the model.
Compile a PyTensor function that computes logp and gradient.
HierarchicalLaunchITS.make_obs_var(rv_var, ...)Create a TensorVariable for an observed random variable.
Check if name has prefix and adds if needed.
Check if name has prefix and deletes if needed.
HierarchicalLaunchITS.point_logps([point, ...])Compute the log probability of point for all random variables in the model.
HierarchicalLaunchITS.predict(X[, coords, ...])Posterior predictive using the supplied
auxbundle.Print the model coefficients with their labels.
Data-adaptive priors keyed to the scale of
y.HierarchicalLaunchITS.profile(outs, *[, n, ...])Compile and profile a PyTensor function which returns
outsand takes values of model vars as a dict as an argument.Register a data variable with the model.
HierarchicalLaunchITS.register_rv(rv_var, ...)Register an (un)observed random variable with the model.
Clone and replace random variables in graphs with their value variables.
HierarchicalLaunchITS.score(X, y[, coords])Score the Bayesian \(R^2\) given inputs
Xand outputsy.HierarchicalLaunchITS.set_data(name, values)Change the values of a data variable in the model.
HierarchicalLaunchITS.set_dim(name, new_length)Update a mutable dimension.
HierarchicalLaunchITS.set_initval(rv_var, ...)Set an initial value (strategy) for a random variable.
HierarchicalLaunchITS.to_graphviz(*[, ...])Produce a graphviz Digraph from a PyMC model.
Attributes
basic_RVsList of random variables the model is defined in terms of.
continuous_value_varsAll the continuous value variables in the model.
coordsCoordinate values for model dimensions.
datalogpPyTensor scalar of log-probability of the observed variables and potential terms.
default_priorsdim_lengthsThe symbolic lengths of dimensions in the model.
discrete_value_varsAll the discrete value variables in the model.
isrootobservedlogpPyTensor scalar of log-probability of the observed variables.
parentpotentiallogpPyTensor scalar of log-probability of the Potential terms.
prefixrootunobserved_RVsList of all random variables, including deterministic ones.
unobserved_value_varsList of all random variables (including untransformed projections), as well as deterministics used as inputs and outputs of the model's log-likelihood graph.
value_varsList of unobserved random variables used as inputs to the model's log-likelihood (which excludes deterministics).
varlogpPyTensor scalar of log-probability of the unobserved random variables (excluding deterministic).
varlogp_nojacPyTensor scalar of log-probability of the unobserved random variables (excluding deterministic) without jacobian term.
- classmethod __new__(*args, **kwargs)#