PropensityScore#
- class causalpy.pymc_models.PropensityScore[source]#
Custom PyMC model for inverse propensity score models
Defines the PyMC model
\[ \begin{align}\begin{aligned}\beta &\sim \mathrm{Normal}(0, 1)\\\sigma &\sim \mathrm{HalfNormal}(1)\\\mu &= X * \beta\\p &= logit^{-1}(mu)\\t &\sim \mathrm{Bernoulli}(p)\end{aligned}\end{align} \]Methods
PropensityScore.__init__([sample_kwargs])PropensityScore.add_coord(name[, values, ...])Registers a dimension coordinate with the model.
PropensityScore.add_coords(coords, *[, lengths])Vectorized version of
Model.add_coord.PropensityScore.add_named_variable(var[, dims])Add a random graph variable to the named variables of the model.
PropensityScore.build_model(X, t, coords)Defines the PyMC propensity model
Check that the starting values for MCMC do not cause the relevant log probability to evaluate to something invalid (e.g. Inf or NaN).
PropensityScore.compile_d2logp([vars, ...])Compiled log probability density hessian function.
PropensityScore.compile_dlogp([vars, jacobian])Compiled log probability density gradient function.
PropensityScore.compile_fn(outs, *[, ...])Compiles an PyTensor function
PropensityScore.compile_logp([vars, ...])Compiled log probability density function.
PropensityScore.create_value_var(rv_var, *, ...)Create a
TensorVariablethat will be used as the random variable's "value" in log-likelihood graphs.PropensityScore.d2logp([vars, jacobian, ...])Hessian of the models log-probability w.r.t.
PropensityScore.debug([point, fn, verbose])Debug model function at point.
PropensityScore.dlogp([vars, jacobian])Gradient of the models log-probability w.r.t.
Evaluates shapes of untransformed AND transformed free variables.
PropensityScore.fit(X, t, coords)Draw samples from posterior, prior predictive, and posterior predictive distributions.
PropensityScore.initial_point([random_seed])Computes the initial point of the model.
PropensityScore.logp([vars, jacobian, sum])Elemwise log-probability of the model.
Compile an PyTensor function that computes logp and gradient.
PropensityScore.make_obs_var(rv_var, data, ...)Create a TensorVariable for an observed random variable.
PropensityScore.name_for(name)Checks if name has prefix and adds if needed
PropensityScore.name_of(name)Checks if name has prefix and deletes if needed
PropensityScore.point_logps([point, round_vals])Computes the log probability of point for all random variables in the model.
Predict data given input data X
PropensityScore.profile(outs, *[, n, point, ...])Compiles and profiles an PyTensor function which returns
outsand takes values of model vars as a dict as an argument.PropensityScore.register_data_var(data[, dims])Register a data variable with the model.
PropensityScore.register_rv(rv_var, name, *)Register an (un)observed random variable with the model.
Clone and replace random variables in graphs with their value variables.
PropensityScore.score(X, y)Score the Bayesian \(R^2\) given inputs
Xand outputsy.PropensityScore.set_data(name, values[, coords])Changes the values of a data variable in the model.
PropensityScore.set_dim(name, new_length[, ...])Update a mutable dimension.
PropensityScore.set_initval(rv_var, initval)Sets an initial value (strategy) for a random variable.
PropensityScore.to_graphviz(*[, var_names, ...])Produce a graphviz Digraph from a PyMC model.
Update point a with b, without overwriting existing keys.
Attributes
basic_RVsList of random variables the model is defined in terms of (which excludes deterministics).
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
dim_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.