themodel {HTRX} | R Documentation |
Model fitting
Description
Model-agnostic functions for model fitting (both linear and generalized linear models).
Usage
themodel(formula, data, usebinary = 1, clean = TRUE)
Arguments
formula |
a formula for model-fitting, starting with outcome~. |
data |
a data frame contains all the variables included in the formula. The outcome must be the first column with colnames(data)[1]="outcome". |
usebinary |
a non-negative number representing different models.
Use linear model if |
clean |
logical. If |
Details
This function returns a fitted model (either linear model or logistic regression model).
For logistic regression, we use function fastglm
from fastglm
package, which is much faster than glm
.
Value
a fitted model.
Examples
## create the dataset for variables and outcome
x=matrix(runif(100,-2,2),ncol=5)
outcome=0.5*x[,2] - 0.8*x[,4] + 0.3*x[,5]
data1=data.frame(outcome,x)
## fit a linear model
themodel(outcome~.,data1,usebinary=0)
## create binary outcome
outcome=outcome>runif(100,-2,2)
outcome[outcome]=1
data2=data.frame(outcome,x)
## fit a logistic regression model
themodel(outcome~.,data2,usebinary=1)