LinearRegression

linear_regression.LinearRegression(self, alpha, p, phi=1)

Covariate adjusted t-tests from Lindon et al. (2024).

Coefficients and covariance matrix are calculated using the Recursive Least Squares algorithm.

Parameters

Name Type Description Default
alpha float Probability of Type I error \(\alpha\). required
p int Number of covariates \(p\). required
phi float Prior scale \(\phi\). 1

Attributes

Name Description
Xty Sum of products of covariates and response \(X^T y\).
beta Estimate of regression coefficients \(\hat{\beta}\).
covariance Estimate of covariance matrix \(\hat{\Sigma}\).
phi Prior scale \(\phi\).
yty Sum of squared response values \(y^T y\).

Methods

Name Description
nu Degrees of freedom.
predict Predict values for given covariates.
sigma Estimate the standard deviation of the error term.
sse Compute the Sum of Squared Errors (SSE).
standard_errors Estimate the standard errors of the coefficients.
t_stats Calculate the t statistics of the coefficients.
update Update the model with new data.
z2 Calculate the squared z-scores.

nu

linear_regression.LinearRegression.nu()

Degrees of freedom.

Returns

Name Type Description
int

predict

linear_regression.LinearRegression.predict(X)

Predict values for given covariates.

Parameters

Name Type Description Default
X np.ndarray Matrix of covariates. required

Returns

Name Type Description
np.ndarray

sigma

linear_regression.LinearRegression.sigma()

Estimate the standard deviation of the error term.

Returns

Name Type Description
float

sse

linear_regression.LinearRegression.sse()

Compute the Sum of Squared Errors (SSE).

Returns

Name Type Description
float

standard_errors

linear_regression.LinearRegression.standard_errors()

Estimate the standard errors of the coefficients.

Returns

Name Type Description
np.ndarray

t_stats

linear_regression.LinearRegression.t_stats()

Calculate the t statistics of the coefficients.

Returns

Name Type Description
np.ndarray

update

linear_regression.LinearRegression.update(yx)

Update the model with new data.

Parameters

Name Type Description Default
yx np.ndarray Array of response and covariate values \([y, x_1, \dots, x_p]\). required

z2

linear_regression.LinearRegression.z2()

Calculate the squared z-scores.

Returns

Name Type Description
np.ndarray

References

Lindon, Michael, Dae Woong Ham, Martin Tingley, and Iavor Bojinov. 2024. “Anytime-Valid Linear Models and Regression Adjusted Causal Inference in Randomized Experiments.” https://arxiv.org/abs/2210.08589.