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 usebinary=0, use logistic regression model via fastglm if usebinary=1 (by default), and use logistic regression model via glm if usebinary>1.

clean

logical. If clean=TRUE (by default), remove additional storages that the predict function, "AIC" and "BIC" criteria do not need.

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)

[Package HTRX version 1.2.4 Index]