spatialvi.external.PPIInference#

class spatialvi.external.PPIInference[source]#

Bases: object

Static methods for prediction-powered inference.

This class does not derive from the spatial model base because PPI operates on numerical arrays rather than AnnData objects. It exposes simple wrappers around commonly used estimands in the ppi_py package, raising informative errors if the package is not installed.

Examples

>>> import numpy as np
>>> from spatialvi.external import PPIInference
>>> # Small labeled sample
>>> y_labeled = np.array([1.2, 0.8, 1.1, 0.9, 1.0])
>>> yhat_labeled = np.array([1.1, 0.9, 1.0, 0.85, 1.05])
>>> # Large unlabeled sample with predictions
>>> yhat_unlabeled = np.random.normal(1.0, 0.2, 1000)
>>> # Compute confidence interval for mean
>>> ci = PPIInference.mean_ci(y_labeled, yhat_labeled, yhat_unlabeled)
>>> print(f"95% CI for mean: [{ci[0]:.3f}, {ci[1]:.3f}]")
__init__()#

Methods

__init__()

classical_mean_ci(y[, alpha])

Compute classical confidence interval for the mean (no predictions).

mean_ci(y, yhat, yhat_unlabeled[, alpha])

Compute a prediction-powered confidence interval for the mean.

mean_pointestimate(y, yhat, yhat_unlabeled)

Compute a prediction-powered point estimate for the mean.

ols_ci(X, y, yhat, X_unlabeled, yhat_unlabeled)

Compute prediction-powered CI for OLS regression coefficients.

ols_pointestimate(X, y, yhat, X_unlabeled, ...)

Compute prediction-powered point estimates for OLS coefficients.

static mean_ci(y, yhat, yhat_unlabeled, alpha=0.1)[source]#

Compute a prediction-powered confidence interval for the mean.

Parameters:
Return type:

tuple[float, float]

Returns:

ci_low, ci_high – Lower and upper bounds of the confidence interval.

static mean_pointestimate(y, yhat, yhat_unlabeled)[source]#

Compute a prediction-powered point estimate for the mean.

Parameters:
Return type:

float

Returns:

estimate – The estimated mean of the outcome variable.

static ols_ci(X, y, yhat, X_unlabeled, yhat_unlabeled, alpha=0.1)[source]#

Compute prediction-powered CI for OLS regression coefficients.

Parameters:
Return type:

tuple[ndarray, ndarray]

Returns:

ci_low, ci_high – Lower and upper bounds for each regression coefficient.

static ols_pointestimate(X, y, yhat, X_unlabeled, yhat_unlabeled)[source]#

Compute prediction-powered point estimates for OLS coefficients.

Parameters:
Return type:

ndarray

Returns:

coefficients – Point estimates for each regression coefficient.

static classical_mean_ci(y, alpha=0.1)[source]#

Compute classical confidence interval for the mean (no predictions).

This is a utility method for comparison with PPI intervals.

Parameters:
Return type:

tuple[float, float]

Returns:

ci_low, ci_high – Lower and upper bounds of the confidence interval.