
Last chance! 50% off unlimited learning
Sale ends in
Returns the additive component of the RGAM model for a given feature at given data points, i.e. f_j(X_j).
getf(object, x, j, index)
Fitted rgam
object.
Data for which we want the additive component. If x
is a
matrix, it assumed that X_j
is the j
th column of this matrix.
If x
is a vector, it is assumed to be X_j
itself.
The index of the original feature whose additive component we want.
Index of lambda value for which plotting is desired. Default is
the last lambda value in object$lambda
.
# 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