Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

regress

Regression analysis.


Description

Regression analysis.

Usage

regress(
  formula,
  data,
  family = NULL,
  nsmall = 3,
  robust = FALSE,
  cluster = NULL,
  level2.predictors = "",
  vartypes = NULL,
  test.rand = FALSE
)

Arguments

formula

Model formula like y ~ x1 + x2 (for lm, glm) or y ~ x1 + x2 + (1 | group) (for lmer, glmer).

data

Data frame.

family

[optional] The same as in glm and glmer (e.g., family=binomial will fit a logistic model).

nsmall

Number of decimal places of output. Default is 3.

robust

[only for lm and glm] FALSE (default), TRUE (then the default is "HC1"), "HC0", "HC1", "HC2", "HC3", "HC4", "HC4m", or "HC5". It will add a table with heteroskedasticity-robust standard errors (aka. Huber-White standard errors). For details, see ?sandwich::vcovHC and ?jtools::summ.lm.

*** "HC1" is the default of Stata, whereas "HC3" is the default suggested by the sandwich package.

cluster

[only for lm and glm] Cluster-robust standard errors are computed if cluster is set to the name of the input data's cluster variable or is a vector of clusters. If you specify cluster, you may also specify the type of robust. If you do not specify robust, "HC1" will be set as default.

level2.predictors

[only for lmer] [optional] Default is NULL. If you have predictors at level 2, besides putting them into the formula in the lmer function as usual, you may also define here the level-2 grouping/clustering variables and corresponding level-2 predictor variables.

*** Example: level2.predictors="School: W1 + W2; House: 1", where School and House are two grouping variables, W1 & W2 are school-level predictors, and there is no house-level predictor.

*** If there is no level-2 predictor in the formula of lmer, just leave this parameter blank.

vartypes

[only for lmer] Manually setting variable types. Needless in most situations.

test.rand

[only for lmer] TRUE or FALSE (default). Test random effects (i.e., variance components) by using the likelihood-ratio test (LRT), which is asymptotically chi-square distributed. For large datasets, it is much time-consuming.

Value

No return value.

Examples

## lm
regress(Temp ~ Month + Day + Wind + Solar.R, data=airquality, robust=TRUE)

## glm
regress(case ~ age + parity + education + spontaneous + induced,
        data=infert, family=binomial, robust="HC1", cluster="stratum")

## lmer
library(lmerTest)
regress(Reaction ~ Days + (Days | Subject), data=sleepstudy)
regress(Preference ~ Sweetness + Gender + Age + Frequency +
          (1 | Consumer), data=carrots)

## glmer
library(lmerTest)
data.glmm=MASS::bacteria
regress(y ~ trt + week + (1 | ID), data=data.glmm, family=binomial)
regress(y ~ trt + week + hilo + (1 | ID), data=data.glmm, family=binomial)

bruceR

Broadly Useful Convenient and Efficient R Functions

v0.6.2
GPL-3
Authors
Han-Wu-Shuang Bao [aut, cre]
Initial release
2021-04-08

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.