fit mlr

functions to fit a multiple linear regression model to experimental data.

friendly_doe.fit_mlr.fit_models(design: DoeSchema, response_names: list[str], model_settings: Settings, auto_tune: bool = False) tuple[list, list[~friendly_doe.doe_model.Model1], ~friendly_doe.doe_model.Model, [list[numpy.ndarray[tuple[int, ...], numpy.dtype[+_ScalarType_co]] | None]], int, list]

fit a model for one or more responses.

Parameters:

design: DoeSchema object containing the experimental design, factors, responses, and worksheet

response_names: list of response names to fit models for

model_settings: Settings object containing model fitting settings

auto_tune: boolean indicating whether to automatically tune the model terms

Returns:

models: list of fitted model objects (or None if fitting failed), used to get statistics

model_terms: list of Model1 objects containing the terms used in each model

model_field: Model object containing the model type and settings

x_matrices: list of numpy arrays containing the design matrices used for fitting each model

number_of_experiment: integer indicating the number of experiments in the worksheet

data_indexes: list of lists containing the indexes of the data points used for fitting each model

functions to get statistics from mlr model

friendly_doe.fit_statistics.anova(model) dict

get anova dict for the model

friendly_doe.fit_statistics.calculate_coefficients(model, factor_list: list[Factor], scaled: bool, normalized: bool, confidence_level: float)

get all coefficent type from model

friendly_doe.fit_statistics.coefficients(model, factor_list: list[Factor], scaled: bool = True, normalized: bool = False, confidence_level: float = 0.95) dict[str, Any]

calculate coefficients

Parameters:

model: the fitted model

factor_list: list of factors

scaled: if the coefficients should be scaled

normalized: if the coefficients should be normalized

confidence_level: confidence level for confidence interval

Returns:

a dictionary with keys:

names: list of coefficient names

abbreviations: list of coefficient abbreviations

coefficients: list of coefficient values

confidence: list of confidence interval values for the coefficients (None if not scaled or normalized)

friendly_doe.fit_statistics.predict(model, prediction_data: ndarray[tuple[int, ...], dtype[float64]]) ndarray[tuple[int, ...], dtype[float64]]

predicted values from model

Parameters:

model: the fitted model

prediction_data: the data to predict Returns:

the backed transformed predicted values as a numpy array

friendly_doe.fit_statistics.predict_transform(model, prediction_data: ndarray[tuple[int, ...], dtype[float64]]) ndarray[tuple[int, ...], dtype[float64]]

predicted values from model with out back transformation

returns a numpy array of predicted values

friendly_doe.fit_statistics.predict_with_confidence(model, prediction_data: ndarray[tuple[int, ...], dtype[float64]], confidence_type, confidence_level: float, tolerance_level: float) tuple[ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]]]

predict from model with confidence intervals return values that are not back transformed

Parameters:

model: the fitted model

prediction_data: the data to predict

confidence_type: type of confidence interval

confidence_level: confidence level for confidence interval

tolerance_level: tolerance level for prediction interval

Returns:

a tuple of two numpy arrays (predicted values, confidence interval values)

friendly_doe.fit_statistics.replicates(model, number_of_experiment: int, index: list[int]) list[int]

get replicates group

Parameters:

model: the fitted model

number_of_experiment: the number of experiments

index: the index of the data points used for fitting the model

Returns:

list of replicates group, each element represents the group of replicates for the corresponding data point.

friendly_doe.fit_statistics.residuals(model) dict[str, Any]

get residuals from model

returns the dictionary with keys:

raw: list of raw residuals

deletedStudentized: list of deleted studentized residuals

standardized: list of standardized residuals

normalDistributionSamples: list of expected values for a normal distribution

normalDistributionProbabilities: list of normal distribution probabilities for the samples

friendly_doe.fit_statistics.summary_of_fit(model, df: int) dict[str, Any]

get summary of fit from model

Parameters:

model: the fitted model

df: degrees of freedom

Returns:

a dictionary with keys:

r2, q2, modelValidity, reproducibility, conditionNumber