getf: Get RGAM model component for one feature

Description Usage Arguments Examples

Description

Returns the additive component of the RGAM model for a given feature at given data points, i.e. f_j(X_j).

Usage

1
getf(object, x, j, index)

Arguments

object

Fitted rgam object.

x

Data for which we want the additive component. If x is a matrix, it assumed that X_j is the jth column of this matrix. If x is a vector, it is assumed to be X_j itself.

j

The index of the original feature whose additive component we want.

index

Index of lambda value for which plotting is desired. Default is the last lambda value in object$lambda.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
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)

relgam documentation built on Jan. 13, 2020, 5:06 p.m.