runUnivariate: Run "univarite" regressions for each variable in a model

View source: R/runUnivariate.R

runUnivariateR Documentation

Run "univarite" regressions for each variable in a model

Description

Based on the input model, a series of models are run that predict the dependant variable using each of the independant variables, one at a time.

Usage

runUnivariate(mod, returnIntercept = TRUE)

Arguments

mod

A model object. Support types include lm, glm, polr.

returnIntercept

(optional) if set to TRUE will also include a column for the intercept value (or for an ordinal logit regression, it will return columns for each boundary)

Details

Loops over each independent variable in the input model, predicting the dependent variable using that IV alone.

This is useful for comparing against the results of a regression with all IV's included together. The univariate results show the individual impact of each IV, while the full regression shows how they might interact. For example if two IV's are correlated, they might both come out as significant predictors in a univariate regression, but in a full regression their betas may impact each other in unpredictable ways (they may be suppressed or exagerated depending on the nature of their interaction). For lm and glm regressions you should also refer to the "tolerance" outputted by getOutput to identify collinearity.

NB: For categorical/factor variables, each level is outputted on its own line (except the baseline), even though only one model was run for that IV. For example, consider an "Income" variable with levels "Low", "Med" and "High" predicting age as an IV. The univariate model run would be lm(age ~ Income), but there would be two betas (and p-values added to the result table), for "IncomeMed" and "IncomeHigh". If returnIntercept is set to TRUE, there is only one model intecept, so this would be returned on each row i.e. the same value is repeated.

See Also

See also getUnivariate which directly copies the result to the clipboard

Examples


# Running a linear regression using the built in mtcars data set...
m1 = lm(mpg ~ gear + factor(carb) + hp, mtcars)
# to run unvariate results for each IV:
u1 = runUnivariate(m1)

# to also return the intercept for each univariate model, run:
u1 = runUnivariate(m1, returnIntercept = T)




Dectech/DectechR documentation built on Feb. 15, 2024, 9:17 a.m.