| regress | R Documentation |
Fits an ordinary least-squares model. R4VN compact syntax allows models such
as regress(y, c.age, i.sex, i.sex*i.treatment) without ~ or +.
regress(
y,
...,
vars = NULL,
data = NULL,
noconstant = FALSE,
vce = c("model", "robust", "cluster"),
cluster = NULL,
weights = NULL,
subset = NULL,
ref = NULL,
standardized = FALSE,
vif = FALSE,
diagnosis = FALSE,
level = 0.95,
digits = 3,
p_digits = 3,
show = TRUE,
console = FALSE
)
y |
Formula or numeric outcome variable. |
... |
Predictors or model terms when |
vars |
Optional model terms written as |
data |
Data frame or |
noconstant |
Fit without an intercept. |
vce |
Model-based, HC1 robust, or cluster-robust covariance. |
cluster |
Cluster variable used when |
weights |
Optional non-negative analytic weights. |
subset |
Optional logical subset expression. |
ref |
Optional named list of factor reference levels. |
standardized |
Also display standardized coefficients for numeric columns. |
vif |
Also display coefficient-level variance inflation factors. |
diagnosis |
Logical; if |
level |
Confidence level. |
digits, p_digits |
Decimal places. |
show |
Logical; open the formatted result in the Viewer. Default |
console |
Logical; also print the traditional result in the Console. Default |
Compact model prefixes are c.x for continuous, i.x for categorical,
b2.x for the second factor level as reference, and ib2.x for value/level
2 as reference. Use * for main effects plus interaction and : for
interaction only.
Ordinary linear regression models should be compared with the usual nested
F test rather than lrtest().
An object of class r4vn_stat, returned invisibly. Its sections
component contains the formatted model summary, ANOVA, coefficient table,
and any requested standardized-coefficient or VIF tables. In raw,
model is the fitted lm object, vcov is the covariance matrix,
coefficients contains coefficient-level estimates and tests, overall
contains the overall model test, and vce and model.terms record the
covariance estimator and fitted terms.
d <- data.frame(score = c(60, 65, 68, 72, 75, 80, 77, 70),
age = c(20, 25, 30, 35, 40, 45, 50, 55),
bmi = c(20, 22, 24, 23, 26, 28, 27, 25),
sex = factor(rep(c("Female", "Male"), 4)))
regress(score, age, bmi, i.sex, data = d, show = FALSE)
regress(score, vars = vars(c.age, c.bmi, i.sex), data = d, show = FALSE)
# Full model diagnostics
m <- regress(score, c.age, c.bmi, i.sex, data = d, diagnosis = TRUE, show = FALSE)
m$sections$`Model diagnosis`
m$sections$`Influence diagnostics`
# Postestimation diagnostics can also be generated as variables
usedf(d)
regress(score, c.age, c.bmi, i.sex, diagnosis = FALSE, show = FALSE)
predict(newvar = stdres, type = "standardized", show = FALSE)
predict(newvar = cooksd, type = "cooksd", show = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.