Last active
May 20, 2020 10:32
-
-
Save dill/5419eec66b2490de8990f5fdbfa86e49 to your computer and use it in GitHub Desktop.
Projection matrices with fit=FALSE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(mgcv) | |
set.seed(2) ## simulate some data... | |
dat <- gamSim(1,n=400,dist="normal",scale=2) | |
b <- gam(y~s(x1), data=dat, fit=FALSE) | |
newpred <- data.frame(x1=seq(0, 10, length.out=100)) | |
# Lp for the data | |
lp_data <- PredictMat(b$smooth[[1]], dat) | |
# same? (ignore intercept) | |
all.equal(b$X[,-1], lp_data, check.attributes=FALSE) | |
# compare to actually fitting the model | |
bfit <- gam(y~s(x1),data=dat) | |
lp_data_fit <- predict(bfit, dat, type="lpmatrix") | |
# need to drop first column (intercept!) | |
all.equal(lp_data_fit[,-1], lp_data, check.attributes=FALSE) | |
# Lp for prediction grid | |
# unfit | |
lp_pred <- PredictMat(b$smooth[[1]], newpred) | |
# fit | |
lp_pred_fit <- predict(bfit, newpred, type="lpmatrix") | |
# same? | |
all.equal(lp_pred_fit[,-1], lp_pred, check.attributes=FALSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment