Learn R Programming

JWileymisc (version 1.4.1)

lm2: Modified lm() to use a specified design matrix

Description

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.

Usage

lm2(
  formula,
  data,
  subset,
  weights,
  na.action,
  model = TRUE,
  x = FALSE,
  y = FALSE,
  qr = TRUE,
  singular.ok = TRUE,
  contrasts = NULL,
  offset,
  designMatrix,
  yObserved,
  ...
)

Value

an lm class object

Arguments

formula

An object of class "formula" although it is only minimally used

data

the dataset

subset

subset

weights

any weights

na.action

Defaults to na.omit

model

defaults to TRUE

x

defaults to FALSE

y

defaults to FALSE

qr

defaults to TRUE

singular.ok

defaults to TRUE

contrasts

defaults to NULL

offset

missing by default

designMatrix

a model matrix / design matrix (all numeric, pre coded if applicable for discrete variables)

yObserved

the observed y values

...

additional arguments

See Also

lm

Examples

Run this code
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