Regression

CLARITE has several classes used for Regression.

Regression Classes

Base Class

class clarite.analyze.regression.Regression(data: pandas.core.frame.DataFrame, outcome_variable: str, covariates: Optional[List[str]] = None)

Abstract Base Class for Regression objects used in EWAS.

clarite.analyze.ewas

The regression_kind parameter can be set to use one of three regression classes, or a custom subclass of Regression can be created.

class clarite.analyze.regression.GLMRegression(data: pandas.core.frame.DataFrame, outcome_variable: str, covariates: Optional[List[str]] = None, min_n: int = 200, report_categorical_betas: bool = False, standardize_data: bool = False)

Statsmodels GLM Regression. This class handles running a regression for each variable of interest and collecting results.

Parameters
data:

The data to be analyzed, including the outcome, covariates, and any variables to be regressed.

outcome_variable:

The variable to be used as the output (y) of the regression

covariates:

The variables to be used as covariates. Any variables in the DataFrames not listed as covariates are regressed.

min_n:

Minimum number of complete-case observations (no NA values for outcome, covariates, or variable) Defaults to 200

report_categorical_betas: boolean
False by default.

If True, the results will contain one row for each categorical value (other than the reference category) and will include the beta value, standard error (SE), and beta pvalue for that specific category. The number of terms increases with the number of categories.

standardize_data: boolean
False by default.

If True, numeric data will be standardized using z-scores before regression. This will affect the beta values and standard error, but not the pvalues.

Notes

  • The family used is either Gaussian (continuous outcomes) or binomial(logit) for binary outcomes.

  • Covariates variables that are constant produce warnings and are ignored

  • The dataset is subset to drop missing values, and the same dataset is used for both models in the LRT

class clarite.analyze.regression.WeightedGLMRegression(data: pandas.core.frame.DataFrame, outcome_variable: str, covariates: Optional[List[str]], survey_design_spec: Optional[clarite.modules.survey.survey_design.SurveyDesignSpec] = None, min_n: int = 200, report_categorical_betas: bool = False, cov_method: Optional[str] = 'stata', standardize_data: bool = False)

Statsmodels GLM Regression with adjustments for survey design. This class handles running a regression for each variable of interest and collecing results. The statistical adjustments (primarily the covariance calculation) are designed to match results when running with the R survey library.

Parameters
data:

The data to be analyzed, including the outcome, covariates, and any variables to be regressed.

outcome_variable:

The variable to be used as the output (y) of the regression

covariates:

The variables to be used as covariates. Any variables in the DataFrames not listed as covariates are regressed.

survey_design_spec:

A SurveyDesignSpec object is used to create SurveyDesign objects for each regression.

min_n:

Minimum number of complete-case observations (no NA values for outcome, covariates, variable, or weight) Defaults to 200

report_categorical_betas: boolean
False by default.

If True, the results will contain one row for each categorical value (other than the reference category) and will include the beta value, standard error (SE), and beta pvalue for that specific category. The number of terms increases with the number of categories.

cov_method:

Covariance calculation method (if survey_design_spec is passed in). ‘stata’ by default. Warning: jackknife is untested and may not be accurate

standardize_data: boolean
False by default.

If True, numeric data will be standardized using z-scores before regression. This will affect the beta values and standard error, but not the pvalues.

Notes

  • The family used is Gaussian for continuous outcomes or binomial(logit) for binary outcomes.

  • Covariates variables that are constant (after dropping rows due to missing data or applying subsets) produce warnings and are ignored

  • Rows missing a weight but not missing the tested variable will cause an error unless the SurveyDesignSpec specifies drop_unweighted as True (in which case those rows are dropped)

  • Categorical variables run with a survey design will not report Diff_AIC as it may not be possible to calculate it accurately

class clarite.analyze.regression.RSurveyRegression(data: pandas.core.frame.DataFrame, outcome_variable: str, covariates: Optional[List[str]], survey_design_spec: Optional[clarite.modules.survey.survey_design.SurveyDesignSpec] = None, min_n: int = 200, report_categorical_betas: bool = False, standardize_data: bool = False)

Run regressions by calling R from Python When a SurveyDesignSpec is provided, the R survey library is used. Results should match those run with either GLMRegression or WeightedGLMRegression.

Parameters
data:

The data to be analyzed, including the outcome, covariates, and any variables to be regressed.

outcome_variable:

The variable to be used as the output (y) of the regression

covariates:

The variables to be used as covariates. Any variables in the DataFrames not listed as covariates are regressed.

survey_design_spec:

A SurveyDesignSpec object is used to create SurveyDesign objects for each regression. Use None if unweighted regression is desired.

min-n:

Minimum number of complete-case observations (no NA values for outcome, covariates, variable, or weight) Defaults to 200

report_betas: boolean
False by default.

If True, the results will contain one row for each categorical value (other than the reference category) and will include the beta value, standard error (SE), and beta pvalue for that specific category. The number of terms increases with the number of categories.

standardize_data: boolean
False by default.

If True, numeric data will be standardized using z-scores before regression. This will affect the beta values and standard error, but not the pvalues.

clarite.analyze.interactions

class clarite.analyze.regression.InteractionRegression(data, outcome_variable, covariates, min_n=200, interactions=None, report_betas=False)

Statsmodels GLM Regression. This class handles running regressions and calculating LRT pvalues based on including interaction terms

Parameters
data: pd.DataFrame

The data to be analyzed, including the outcome, covariates, and any variables to be regressed.

outcome_variable: string

The variable to be used as the output (y) of the regression

covariates: list (strings),

The variables to be used as covariates. Any variables in the DataFrames not listed as covariates are regressed.

min_n: int or None

Minimum number of complete-case observations (no NA values for outcome, covariates, or variable) Defaults to 200

interactions: list(tuple(strings)), str, or None

Valid variables are those in the data that are not the outcome variable or a covariate. None: Test all pairwise interactions between valid variables String: Test all interactions of this valid variable with other valid variables List of tuples: Test specific interactions of valid variables

report_betas: boolean
False by default.

If True, the results will contain one row for each interaction term and will include the beta value for that term. The number of terms increases with the number of categories in each interacting term.

Notes

  • The family used is either Gaussian (continuous outcomes) or binomial(logit) for binary outcomes.

  • Covariates variables that are constant produce warnings and are ignored

  • The dataset is subset to drop missing values, and the same dataset is used for both models in the LRT