Package version: 0.5.2.9002
Consider two linear models; the smaller is a submodel of the large:
##
## Call:
## lm(formula = y ~ x + I(x^2), data = dat)
##
## Coefficients:
## (Intercept) x I(x^2)
## -4.247 3.132 -0.468
##
## Call:
## lm(formula = y ~ x, data = dat)
##
## Coefficients:
## (Intercept) x
## -1.9067 0.7922
The corresponding model matrices are
## (Intercept) x I(x^2)
## 1 1 1 1
## 2 1 2 4
## 3 1 3 9
## 4 1 4 16
## attr(,"assign")
## [1] 0 1 2
## (Intercept) x
## 1 1 1
## 2 1 2
## 3 1 3
## 4 1 4
## attr(,"assign")
## [1] 0 1
Given the two model matrices, the restriction matrix which describes the restrictions that should be made to the model matrix of the large model to produce the model matrix of the small model:
## [,1] [,2] [,3]
## [1,] 0 0 -1
Given the model matrix of the large model and the restriction matrix, the model matrix of the small model can be constructed as:
## [,1] [,2]
## 1 1 1
## 2 2 1
## 3 3 1
## 4 4 1
The same operation can be made directly on model objects:
## [,1] [,2] [,3]
## [1,] 0 0 -1
Likewise, given the large model and the restriction matrix, the small model can be constructed:
##
## Call:
## lm(formula = y ~ .X1 + .X2 - 1, data = structure(list(.X1 = c(1,
## 2, 3, 4), .X2 = c(1, 1, 1, 1), y = c(-1.2863183971196, -0.742809671831416,
## 1.82638290097128, 0.497920314301363), x = 1:4, `I(x^2)` = structure(c(1,
## 4, 9, 16), class = "AsIs")), class = "data.frame", row.names = c(NA,
## 4L)))
##
## Coefficients:
## .X1 .X2
## 0.7922 -1.9067
## .X1 .X2
## 1 1 1
## 2 2 1
## 3 3 1
## 4 4 1
## attr(,"assign")
## [1] 1 2
Lastly, model matrices can be compared
## [1] 1
## [1] 0
## [1] -1