Run regression models with adjusting for covariates. `regression_each` is used for one outcome. In `regression`, several outcomes can be specified to run together.

## Usage

```
regression(
object,
phenoData = NULL,
model = NULL,
outcome = NULL,
covars = NULL,
factors = NULL,
feature_name = NULL,
time = NULL,
verbose = TRUE,
ncpus = 1,
p.adjust.method = "bonferroni",
...
)
regression_each(
object,
phenoData = NULL,
model = NULL,
formula = NULL,
outcome = NULL,
covars = NULL,
factors = NULL,
feature_name = NULL,
time = NULL,
verbose = TRUE,
ncpus = 1,
p.adjust.method = "bonferroni",
...
)
regression_each_as_outcome(
object,
phenoData = NULL,
exposure = NULL,
covars = NULL,
factors = NULL,
feature_name = NULL,
verbose = TRUE,
ncpus = 1,
p.adjust.method = "bonferroni",
...
)
```

## Arguments

- object
A Metabolite object.

- phenoData
A data.table with outcome and covariates. If `phenoData` is NULL, `@sampleData` will be used.

- model
Specify a regression model. See

`fit_lm`

for more details. 'auto' can be used to infer 'lm' or 'logistic' (with only 0, 1, and NA).- outcome
Column name of the outcome variable.

- covars
Column names of covariates.

- factors
Variables to be treated as factor.

- feature_name
A vector of selected metabolites to run. If both feature_name and random_select are NULL, will run regression for all features.

- time
Column name of survival time, used in cox regression, see

`coxph`

for more details.- verbose
Print log information.

- ncpus
Number of CPUS for parallele job.

- p.adjust.method
Adjust for P value method, see

`p.adjust`

.- ...
Further arguments passed to regression model.

- formula
A character or formula object to fit model (only used in `regression_each`)

## Examples

```
data(df_plasma)
fit_lm <- regression(object = df_plasma, phenoData = NULL, model = "lm",
outcome = "BMI", covars = c("AGE", "GENDER", "ETHNICITY"), factors = "ETHNICITY")
#> Regression for 1 outcome(s).
#>
#> Build formula using covars and outcomes.
#>
#> Run `lm` model for 758 features:
#> BMI ~ AGE + GENDER + ETHNICITY + `feature`
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
#> Failed to fit model: Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#>
```