Skip to contents

At each z0 the weighted least-squares fit of y on (1, X) with weights K(|z - z0| / lambda) gives alpha(z0), beta(z0) (ESL eqs 6.16-6.17).

Usage

morie_esl_varying_coef(X, z, y, z0, lambda, kernel = "epanechnikov")

Arguments

X

Predictors, n by q.

z

Variable the coefficients vary with.

y

Response.

z0

Targets.

lambda

Bandwidth.

kernel

"epanechnikov", "tri-cube" or "gaussian".

Value

Named list: coefficients (one row per target), n_in_window.

References

Hastie, Tibshirani & Friedman (2009), sec. 6.4.2.

Examples

i <- 1:40
X <- cbind(cos(2 * i))
z <- ((7 * i) %% 40) / 40
morie_esl_varying_coef(X, z, 1 + z * X[, 1], c(0.3, 0.7), 0.35)$coefficients
#>           [,1]      [,2]
#> [1,] 1.0014045 0.3340463
#> [2,] 0.9870295 0.7236923