Description Usage Arguments Author(s) References See Also Examples
View source: R/hier_basis_additive.R
This function plots individual component functions for a specified value of
lambda
for an object of class addHierBasis
.
1 2 |
x |
An object of class |
ind.func |
The index of the component function to plot. |
ind.lam |
The index of the lambda value to plot. |
... |
Other arguments passed on to function |
Asad Haris (aharis@uw.edu), Ali Shojaie and Noah Simon
Haris, A., Shojaie, A. and Simon, N. (2018). Nonparametric Regression with Adaptive Smoothness via a Convex Hierarchical Penalty. Available on request by authors.
AdditiveHierBasis
, predict.addHierBasis
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | require(Matrix)
set.seed(1)
# Generate the points x.
n <- 100
p <- 30
x <- matrix(rnorm(n*p), ncol = p)
# A simple model with 3 non-zero functions.
y <- rnorm(n, sd = 0.1) + sin(x[, 1]) + x[, 2] + (x[, 3])^3
mod <- AdditiveHierBasis(x, y, nbasis = 50, max.lambda = 30,
beta.mat = NULL,
nlam = 50, alpha = 0.5,
lam.min.ratio = 1e-4, m.const = 3,
max.iter = 300, tol = 1e-4)
# Plot the individual functions.
xs <- seq(-3,3,length = 300)
plot(mod,1,30, type ="l",col = "red", lwd = 2, xlab = "x", ylab = "f_1(x)",
main = "Estimating the Sine function")
lines(xs, sin(xs), type = "l", lwd = 2)
legend("topleft", c("Estimated Function", "True Function"),
col = c("red", "black"), lwd = 2, lty = 1)
plot(mod,2,30, type ="l",col = "red", lwd = 2, xlab = "x", ylab = "f_2(x)",
main = "Estimating the Linear function")
lines(xs, xs, type = "l", lwd = 2)
legend("topleft", c("Estimated Function", "True Function"),
col = c("red", "black"), lwd = 2, lty = 1)
plot(mod,3,30, type ="l",col = "red", lwd = 2, xlab = "x", ylab = "f_3(x)",
main = "Estimating the cubic polynomial")
lines(xs, xs^3, type = "l", lwd = 2)
legend("topleft", c("Estimated Function", "True Function"),
col = c("red", "black"), lwd = 2, lty = 1)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.