delnx.models.LinearRegression¶

class delnx.models.LinearRegression(maxiter=100, tol=1e-06, optimizer='BFGS', skip_stats=False)[source]¶

Linear regression with Ordinary Least Squares estimation.

This class implements a basic linear regression model using OLS, with support for including offset terms. For linear models, offsets are applied by subtracting from the response variable rather than adding to the linear predictor.

Parameters:
  • maxiter (int (default: 100)) – Maximum number of iterations for optimization (inherited from Regression).

  • tol (float (default: 1e-06)) – Convergence tolerance (inherited from Regression).

  • optimizer (str (default: 'BFGS')) – Optimization method (inherited from Regression).

  • skip_stats (bool (default: False)) – Whether to skip calculating Wald test statistics (inherited from Regression).

Examples

>>> import jax.numpy as jnp
>>> from delnx.models import LinearRegression
>>> X = jnp.array([[1.0, 0.5], [1.0, 1.5], [1.0, 2.5]])  # Design matrix with intercept
>>> y = jnp.array([1.0, 2.0, 3.0])  # Response variable
>>> model = LinearRegression()
>>> result = model.fit(X, y)
>>> print(f"Coefficients: {result['coef']}")

Attributes table¶

Methods table¶

fit(X, y[, offset])

Fit linear regression model.

get_llf(X, y, params[, offset])

Get log-likelihood at fitted parameters.

predict(X, params[, offset])

Predict response variable using fitted model.

Attributes¶

LinearRegression.maxiter: int = 100¶
LinearRegression.optimizer: str = 'BFGS'¶
LinearRegression.skip_stats: bool = False¶
LinearRegression.tol: float = 1e-06¶

Methods¶

LinearRegression.fit(X, y, offset=None)[source]¶

Fit linear regression model.

Parameters:
  • X (Array) – Design matrix of shape (n_samples, n_features).

  • y (Array) – Response vector of shape (n_samples,).

  • offset (Array | None (default: None)) – Offset term to include in the model. If provided, overrides the offset set during class initialization.

Return type:

dict

Returns:

Dictionary containing:

  • coef: Parameter estimates

  • llf: Log-likelihood at fitted parameters

  • se: Standard errors (None if skip_stats=True)

  • stat: Test statistics (None if skip_stats=True)

  • pval: P-values (None if skip_stats=True)

LinearRegression.get_llf(X, y, params, offset=None)¶

Get log-likelihood at fitted parameters.

This method converts the negative log-likelihood to a log-likelihood value, which is useful for model comparison and likelihood ratio tests.

Parameters:
  • X (Array) – Design matrix of shape (n_samples, n_features).

  • y (Array) – Response vector of shape (n_samples,).

  • params (Array) – Parameter estimates.

  • offset (Array | None (default: None)) – Offset term to include in the model.

Return type:

float

Returns:

float Log-likelihood value.

LinearRegression.predict(X, params, offset=None)[source]¶

Predict response variable using fitted model.

Parameters:
  • X (Array) – Design matrix of shape (n_samples, n_features).

  • offset (Array | None (default: None)) – Offset term to include in the prediction. If provided, overrides the offset set during class initialization.

Return type:

Array

Returns:

jnp.ndarray Predicted response variable.