# NOT RUN {
set.seed(1)
n <- 100; p <- 20
x <- matrix(rnorm(n * p), n, p)
beta <- matrix(c(rep(2, 5), rep(0, 15)), ncol = 1)
y <- x %*% beta + rnorm(n)
fit <- rgam(x, y)
# get the additive component for the feature 6, x as matrix
f6 <- getf(fit, x, 6) # last value of lambda
plot(x[, 6], f6)
f6 <- getf(fit, x, 6, index = 20) # f1 at 20th value of lambda
plot(x[, 6], f6)
# get the additive component for the feature 6, x as vector
new_x6 <- seq(-1, 1, length.out = 30)
new_f6 <- getf(fit, new_x6, 6) # last value of lambda
plot(new_x6, new_f6)
# }
Run the code above in your browser using DataLab