GeneralizedLinearRegression#

class causalpy.pymc_models.GeneralizedLinearRegression[source]#

Curated generalized linear regression with outcome-scale mu semantics.

Builds eta = X @ beta, applies the configured inverse link to obtain response-scale mu, and wires a family-specific y_hat likelihood.

Supported canonical family/link pairs are Gaussian/identity, Poisson/log, Negative Binomial/log, and Bernoulli/logit. Non-Gaussian families skip Bayesian \(R^2\) scoring because score() returns None.

Parameters:
  • family (Literal['gaussian', 'poisson', 'negative_binomial', 'bernoulli']) – Response family. Defaults to "gaussian". The canonical inverse link for the family is exposed read-only via link.

  • sample_kwargs (dict[str, Any] | None) – Keyword arguments forwarded to pymc.sample().

  • priors (dict[str, Any] | None) – User priors merged over family defaults. Negative Binomial models accept an "alpha" dispersion prior. Custom y_hat overrides are supported only for the Gaussian family.

Methods

GeneralizedLinearRegression.add_coord(name)

Register a dimension coordinate with the model.

GeneralizedLinearRegression.add_coords(coords, *)

Vectorized version of Model.add_coord.

GeneralizedLinearRegression.add_named_variable(var)

Add a random graph variable to the named variables of the model.

GeneralizedLinearRegression.build_model(X, ...)

Define the generalized linear regression PyMC graph.

GeneralizedLinearRegression.check_start_vals(...)

Check that the logp is defined and finite at the starting point.

GeneralizedLinearRegression.compile_d2logp([...])

Compiled log probability density hessian function.

GeneralizedLinearRegression.compile_dlogp([...])

Compiled log probability density gradient function.

GeneralizedLinearRegression.compile_fn(outs, *)

Compiles a PyTensor function.

GeneralizedLinearRegression.compile_logp([...])

Compiled log probability density function.

GeneralizedLinearRegression.copy()

Clone the model.

GeneralizedLinearRegression.create_value_var(...)

Create a TensorVariable that will be used as the random variable's "value" in log-likelihood graphs.

GeneralizedLinearRegression.d2logp([vars, ...])

Hessian of the models log-probability w.r.t.

GeneralizedLinearRegression.debug([point, ...])

Debug model function at point.

GeneralizedLinearRegression.dlogp([vars, ...])

Gradient of the models log-probability w.r.t.

GeneralizedLinearRegression.eval_rv_shapes()

Evaluate shapes of untransformed AND transformed free variables.

GeneralizedLinearRegression.fit(X, y[, coords])

Validate the outcome against the family support, then fit.

GeneralizedLinearRegression.get_context([...])

GeneralizedLinearRegression.initial_point([...])

Compute the initial point of the model.

GeneralizedLinearRegression.logp([vars, ...])

Elemwise log-probability of the model.

GeneralizedLinearRegression.logp_dlogp_function([...])

Compile a PyTensor function that computes logp and gradient.

GeneralizedLinearRegression.make_obs_var(...)

Create a TensorVariable for an observed random variable.

GeneralizedLinearRegression.name_for(name)

Check if name has prefix and adds if needed.

GeneralizedLinearRegression.name_of(name)

Check if name has prefix and deletes if needed.

GeneralizedLinearRegression.point_logps([...])

Compute the log probability of point for all random variables in the model.

GeneralizedLinearRegression.predict(X[, ...])

Predict data given input data X.

GeneralizedLinearRegression.print_coefficients(labels)

Print posterior summaries for regression coefficients and auxiliaries.

GeneralizedLinearRegression.priors_from_data(X, y)

Generate priors dynamically based on the input data.

GeneralizedLinearRegression.profile(outs, *)

Compile and profile a PyTensor function which returns outs and takes values of model vars as a dict as an argument.

GeneralizedLinearRegression.register_data_var(data)

Register a data variable with the model.

GeneralizedLinearRegression.register_rv(...)

Register an (un)observed random variable with the model.

GeneralizedLinearRegression.replace_rvs_by_values(...)

Clone and replace random variables in graphs with their value variables.

GeneralizedLinearRegression.score(X, y[, coords])

Score Bayesian \(R^2\) for Gaussian models; skip for other families.

GeneralizedLinearRegression.set_data(name, ...)

Change the values of a data variable in the model.

GeneralizedLinearRegression.set_dim(name, ...)

Update a mutable dimension.

GeneralizedLinearRegression.set_initval(...)

Set an initial value (strategy) for a random variable.

GeneralizedLinearRegression.shape_from_dims(dims)

GeneralizedLinearRegression.to_graphviz(*[, ...])

Produce a graphviz Digraph from a PyMC model.

Attributes

basic_RVs

List of random variables the model is defined in terms of.

continuous_value_vars

All the continuous value variables in the model.

coords

Coordinate values for model dimensions.

datalogp

PyTensor scalar of log-probability of the observed variables and potential terms.

default_priors

dim_lengths

The symbolic lengths of dimensions in the model.

discrete_value_vars

All the discrete value variables in the model.

family

Curated response family for the built-in GLM.

isroot

link

Read-only canonical inverse link for family.

observedlogp

PyTensor scalar of log-probability of the observed variables.

parent

potentiallogp

PyTensor scalar of log-probability of the Potential terms.

prefix

root

unobserved_RVs

List of all random variables, including deterministic ones.

unobserved_value_vars

List of all random variables (including untransformed projections), as well as deterministics used as inputs and outputs of the model's log-likelihood graph.

value_vars

List of unobserved random variables used as inputs to the model's log-likelihood (which excludes deterministics).

varlogp

PyTensor scalar of log-probability of the unobserved random variables (excluding deterministic).

varlogp_nojac

PyTensor scalar of log-probability of the unobserved random variables (excluding deterministic) without jacobian term.

__init__(family='gaussian', sample_kwargs=None, priors=None)[source]#
Parameters:
  • sample_kwargs (dict[str, Any] | None) – Dictionary of kwargs that get unpacked and passed to the pymc.sample() function. Defaults to an empty dictionary if None.

  • priors (dict[str, Any] | None) – Dictionary of priors for the model. Defaults to None, in which case default priors are used.

  • family (Literal['gaussian', 'poisson', 'negative_binomial', 'bernoulli'])

Return type:

None

classmethod __new__(*args, **kwargs)#