This function is a minor modification of the lm() function
to allow the use of a pre-specified design matrix. It is not intended for
public use but only to support modelTest.lm
.
lm2(
formula,
data,
subset,
weights,
na.action,
model = TRUE,
x = FALSE,
y = FALSE,
qr = TRUE,
singular.ok = TRUE,
contrasts = NULL,
offset,
designMatrix,
yObserved,
...
)
an lm class object
An object of class "formula" although it is only minimally used
the dataset
subset
any weights
Defaults to na.omit
defaults to TRUE
defaults to FALSE
defaults to FALSE
defaults to TRUE
defaults to TRUE
defaults to NULL
missing by default
a model matrix / design matrix (all numeric, pre coded if applicable for discrete variables)
the observed y values
additional arguments
lm
mtcars$cyl <- factor(mtcars$cyl)
m <- lm(mpg ~ hp * cyl, data = mtcars)
x <- model.matrix(m)
y <- mtcars$mpg
m2 <- JWileymisc:::lm2(mpg ~ 1 + cyl + hp:cyl, data = mtcars,
designMatrix = x[, -2, drop = FALSE],
yObserved = y)
anova(m, m2)
rm(m, m2, x, y)
Run the code above in your browser using DataLab