ahat.fit_linear_a_hat_model

fit_linear_a_hat_model(X, y, xlog=False, ylog=False)

Fits a simple linear regression model according to the standard a-hat vs a method.

Enforces a linear fit and a constant variance (homoskedasticity) assumption across all inputs. It allows for optional logarithmic transformations to help linearize the data.

Parameters

Name Type Description Default
X np.ndarray 1D array of input parameter values (e.g., flaw size, a). required
y np.ndarray 1D array of observed responses (e.g., signal amplitude, a-hat). required
xlog bool If True, applies a natural logarithm transformation to X. False
ylog bool If True, applies a natural logarithm transformation to y. False

Returns

Name Type Description
Tuple[LinearRegression, float] Tuple[LinearRegression, float]: - model: The fitted sklearn LinearRegression object. - tau: The constant standard deviation of the residuals.

Examples

import numpy as np
X = np.linspace(1, 10, 50)
y = 2.5 * np.log(X) + np.random.normal(0, 0.5, 50)

# Fit the standard model, taking the log of X to achieve linearity
model, tau = fit_linear_a_hat_model(X, y, xlog=True, ylog=False)
print(f"Constant Standard Deviation: {tau:.4f}")