visualize_boosting: Visualize Boosting Iterations

visualize_boostingR Documentation

Visualize Boosting Iterations

Description

This function plots the NGeDSboost fit to the data at the beginning of a given boosting iteration and then plots the subsequent NGeDS fit on the corresponding residual (negative gradient). Note: Applicable only for NGeDSboost models with one covariate and family = mboost::Gaussian().

Usage

## S3 method for class 'GeDSboost'
visualize_boosting(M, object)

Arguments

M

Numeric, specifies the iteration number.

object

A GeDSboost-Class object.

Examples

# Load packages
library(GeDS)

# Generate a data sample for the response variable
# Y and the single covariate X
set.seed(123)
N <- 500
f_1 <- function(x) (10*x/(1+100*x^2))*4+4
X <- sort(runif(N, min = -2, max = 2))
# Specify a model for the mean of Y to include only a component
# non-linear in X, defined by the function f_1
means <- f_1(X)
# Add (Normal) noise to the mean of Y
Y <- rnorm(N, means, sd = 0.2)
data = data.frame(X, Y)
object <- NGeDSboost(Y ~ f(X), data = data, normalize_data = TRUE)

# Plot
plot(X, Y, pch=20, col=c("darkgrey"))
lines(X, sapply(X, f_1), col = "black", lwd = 2)
lines(X, object$predictions$pred_linear, col = "green4", lwd = 2)
lines(X, object$predictions$pred_quadratic, col="red", lwd=2)
lines(X, object$predictions$pred_cubic, col="purple", lwd=2)
legend("topright",
legend = c("Order 2 (degree=1)", "Order 3 (degree=2)", "Order 4 (degree=3)"),
col = c("green4", "red", "purple"),
lty = c(1, 1),
lwd = c(2, 2, 2),
cex = 0.75,
bty="n",
bg = "white")
# Visualize boosting iterations
par(mfrow=c(2,2))
visualize_boosting(0, object)
visualize_boosting(1, object)
par(mfrow=c(1,1))


alattuada/GeDS documentation built on April 26, 2024, 11:36 a.m.