Section author: Ravi Selker, Jonathon Love, Damian Dropmann
Linear Regression (linReg)
Description
Linear regression is used to explore the relationship between a continuous dependent variable, and one or more continuous and/or categorical explanatory variables. Other statistical methods, such as ANOVA and ANCOVA, are in reality just forms of linear regression.
Usage
linReg(
data,
dep,
covs = NULL,
factors = NULL,
blocks = list(list()),
refLevels = NULL,
intercept = "refLevel",
r = TRUE,
r2 = TRUE,
r2Adj = FALSE,
aic = FALSE,
bic = FALSE,
rmse = FALSE,
modelTest = FALSE,
anova = FALSE,
ci = FALSE,
ciWidth = 95,
stdEst = FALSE,
ciStdEst = FALSE,
ciWidthStdEst = 95,
coefPlot = FALSE,
norm = FALSE,
qqPlot = FALSE,
resPlots = FALSE,
durbin = FALSE,
collin = FALSE,
cooks = FALSE,
emMeans = list(list()),
ciEmm = TRUE,
ciWidthEmm = 95,
emmPlots = TRUE,
emmTables = FALSE,
emmWeights = TRUE
)
Arguments
|
the data as a data frame |
|
the dependent variable from |
|
the covariates from |
|
the fixed factors from |
|
a list containing vectors of strings that name the predictors that are added to the model. The elements are added to the model according to their order in the list |
|
a list of lists specifying reference levels of the dependent variable and all the factors |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
a number between 50 and 99.9 (default: 95) specifying the confidence interval width |
|
|
|
|
|
a number between 50 and 99.9 (default: 95) specifying the confidence interval width |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
a formula containing the terms to estimate marginal means for, supports up to three variables per term |
|
|
|
a number between 50 and 99.9 (default: 95) specifying the confidence interval width for the estimated marginal means |
|
|
|
|
|
|
Output
A results object containing:
|
a table |
|
a table |
|
an array of model specific results |
Tables can be converted to data frames with asDF or
as.data.frame(). For example:
results$modelFit$asDF
as.data.frame(results$modelFit)
Examples
data('Prestige', package='carData')
linReg(data = Prestige, dep = income,
covs = vars(education, prestige, women),
blocks = list(list('education', 'prestige', 'women')))
#
# LINEAR REGRESSION
#
# Model Fit Measures
# ---------------------------
# Model R R²
# ---------------------------
# 1 0.802 0.643
# ---------------------------
#
#
# MODEL SPECIFIC RESULTS
#
# MODEL 1
#
#
# Model Coefficients
# --------------------------------------------------------
# Predictor Estimate SE t p
# --------------------------------------------------------
# Intercept -253.8 1086.16 -0.234 0.816
# women -50.9 8.56 -5.948 < .001
# prestige 141.4 29.91 4.729 < .001
# education 177.2 187.63 0.944 0.347
# --------------------------------------------------------
#