model.matrix.gam.RdObtains the model matrix from a fitted gam object.
# S3 method for class 'gam'
model.matrix(object, ...)fitted model object of class gam as produced by gam().
other arguments, passed to predict.gam.
Calls predict.gam with no newdata argument and
type="lpmatrix" in order to obtain the model matrix of object.
A model matrix.
Wood S.N. (2006b) Generalized Additive Models: An Introduction with R. Chapman and Hall/CRC Press.
require(mgcv)
n <- 15
x <- runif(n)
y <- sin(x*2*pi) + rnorm(n)*.2
mod <- gam(y~s(x,bs="cc",k=6),knots=list(x=seq(0,1,length=6)))
model.matrix(mod)
#> (Intercept) s(x).1 s(x).2 s(x).3 s(x).4
#> 1 1 -0.0358161296 -0.33951467 0.40292056 -0.20338750
#> 2 1 -0.1511081574 0.02367616 0.37146746 -0.53320915
#> 3 1 -0.0005642836 -0.33414082 0.14450034 0.24976392
#> 4 1 -0.2073061920 0.51270884 0.07937145 -0.45410792
#> 5 1 0.7249323915 0.45481408 -0.14502251 0.04368054
#> 6 1 0.0336404468 0.90061386 -0.25533091 -0.14142693
#> 7 1 -0.0447503891 -0.32536544 0.42443596 -0.26136803
#> 8 1 -0.1970396830 -0.29531387 -0.78682890 -0.45932791
#> 9 1 -0.0064550624 -0.35181695 0.24410579 0.10263867
#> 10 1 -0.0111464836 -0.25727535 -0.14017063 0.55758337
#> 11 1 -0.0253097872 -0.22643407 -0.24895348 0.62951795
#> 12 1 -0.1110647308 -0.14194338 0.43851807 -0.49126124
#> 13 1 0.0570589268 0.89770798 -0.25860284 -0.12884496
#> 14 1 -0.0036005108 -0.28432113 -0.04662778 0.47420937
#> 15 1 -0.0214703556 -0.23339524 -0.22378257 0.61553983
#> attr(,"model.offset")
#> [1] 0