plot.AccurateGLM {aglm}R Documentation

Plot contribution of each variable and residuals

Description

Plot contribution of each variable and residuals

Usage

## S3 method for class 'AccurateGLM'
plot(
  x,
  vars = NULL,
  verbose = TRUE,
  s = NULL,
  resid = FALSE,
  smooth_resid = TRUE,
  smooth_resid_fun = NULL,
  ask = TRUE,
  layout = c(2, 2),
  only_plot = FALSE,
  main = "",
  add_rug = FALSE,
  ...
)

Arguments

x

A model object obtained from aglm() or cv.aglm().

vars

Used to specify variables to be plotted (NULL means all the variables). This parameter may have one of the following classes:

  • integer: specifying variables by index.

  • character: specifying variables by name.

verbose

Set to FALSE if textual outputs are not needed.

s

A numeric value specifying λ at which plotting is required. Note that plotting for multiple λ's are not allowed and s always should be a single value. When the model is trained with only a single λ value, just set it to NULL to plot for that value.

resid

Used to display residuals in plots. This parameter may have one of the following classes:

  • logical(single value): If TRUE, working residuals are plotted.

  • character(single value): type of residual to be plotted. See residuals.AccurateGLM for more details on types of residuals.

  • numerical(vector): residual values to be plotted.

smooth_resid

Used to display smoothing lines of residuals for quantitative variables. This parameter may have one of the following classes:

  • logical: If TRUE, smoothing lines are drawn.

  • character:

    • smooth_resid="both": Balls and smoothing lines are drawn.

    • smooth_resid="smooth_only": Only smoothing lines are drawn.

smooth_resid_fun

Set if users need custom smoothing functions.

ask

By default, plot() stops and waits inputs each time plotting for each variable is completed. Users can set ask=FALSE to avoid this. It is useful, for example, when using devices as bmp to create image files.

layout

Plotting multiple variables for each page is allowed. To achieve this, set it to a pair of integer, which indicating number of rows and columns, respectively.

only_plot

Set to TRUE if no automatic graphical configurations are needed.

main

Used to specify the title of plotting.

add_rug

Set to TRUE for rug plots.

...

Other arguments are currently not used and just discarded.

Value

No return value, called for side effects.

Author(s)

References

Suguru Fujita, Toyoto Tanaka, Kenji Kondo and Hirokazu Iwasawa. (2020) AGLM: A Hybrid Modeling Method of GLM and Data Science Techniques,
https://www.institutdesactuaires.com/global/gene/link.php?doc_id=16273&fg=1
Actuarial Colloquium Paris 2020

Examples


#################### using plot() and predict() ####################

library(MASS) # For Boston
library(aglm)

## Read data
xy <- Boston # xy is a data.frame to be processed.
colnames(xy)[ncol(xy)] <- "y" # Let medv be the objective variable, y.

## Split data into train and test
n <- nrow(xy) # Sample size.
set.seed(2018) # For reproducibility.
test.id <- sample(n, round(n/4)) # ID numbders for test data.
test <- xy[test.id,] # test is the data.frame for testing.
train <- xy[-test.id,] # train is the data.frame for training.
x <- train[-ncol(xy)]
y <- train$y
newx <- test[-ncol(xy)]
y_true <- test$y

## With the result of aglm()
model <- aglm(x, y)
lambda <- 0.1

plot(model, s=lambda, resid=TRUE, add_rug=TRUE,
     verbose=FALSE, layout=c(3, 3))

y_pred <- predict(model, newx=newx, s=lambda)
plot(y_true, y_pred)

## With the result of cv.aglm()
model <- cv.aglm(x, y)
lambda <- model@lambda.min

plot(model, s=lambda, resid=TRUE, add_rug=TRUE,
     verbose=FALSE, layout=c(3, 3))

y_pred <- predict(model, newx=newx, s=lambda)
plot(y_true, y_pred)



[Package aglm version 0.4.0 Index]