Neural Network Model Terms for GAMLSS

Description

Constructs a feed-forward neural network model term for use with gamlss2. The term is fitted using nnet with a linear output unit and is integrated into the iterative backfitting algorithm for distributional regression.

Usage

n(formula, ...)

Arguments

formula

A one-sided formula specifying the predictors entering the neural network, for example ~ x1 + x2. Numeric and factor predictors can be used.

Control arguments for the neural network fit. The currently supported arguments are size, the number of units in the hidden layer; maxit, the maximum number of iterations; decay, the weight-decay parameter; trace, indicating whether optimization progress should be printed; MaxNWts, the maximum allowable number of weights; and scale, indicating whether numeric predictors should be scaled before fitting.

Defaults are size = 50, maxit = 1000, decay = 0.1, trace = FALSE, MaxNWts = 10000, and scale = TRUE.

Details

Function n() defines a special neural network model term for gamlss2. At each backfitting update, the current working response and weights are passed to nnet and a feed-forward neural network is fitted with linout = TRUE. Hence, the neural network contributes a continuous additive predictor to the corresponding distributional parameter.

The formula supplied to n() defines the inputs to the network. For example, n(~ Temp + Wind) fits a neural network using Temp and Wind as inputs.

By default, each numeric predictor is scaled to the interval \([0,1]\) using its observed range before the network is fitted. Factor predictors are left unchanged. The same scaling information is stored with the fitted term and is applied automatically when predicting from new data. Scaling can be disabled with scale = FALSE.

The fitted effect is centered by subtracting its mean before it is returned to the additive predictor.

The effective degrees of freedom (edf) are approximated by the number of fitted neural network coefficients returned by nnet.

Value

The constructor n() returns an object of classes “special” and “n” containing the model formula, input data, neural network control arguments, and optional scaling information required for fitting.

See Also

gamlss2, special_terms, nnet

Examples

library("gamlss2")

## air quality data
air <- subset(airquality, !is.na(Ozone))
air <- air[order(air$Temp), ]

## Neural network effect of Temp and Wind for mu.
## A smaller hidden layer is used here for illustration.
set.seed(1328)
f <- Ozone ~ n(~ Temp + Wind, size = 10, decay = 0.05) | 1

## estimate model
m <- gamlss2(f, data = air, family = GA)

## model summary
summary(m)

## visualize estimated effects
plot(m)

## create new data:
## vary temperature while holding wind constant
nd <- with(air, data.frame(
  Temp = seq(min(Temp), max(Temp), length.out = 100),
  Wind = median(Wind)
))

## fitted conditional quantiles
pq <- quantile(
  m,
  newdata = nd,
  probs = c(0.05, 0.5, 0.95)
)

## visualize
plot(Ozone ~ Temp, data = air, pch = 19,
  col = rgb(0.1, 0.1, 0.1, alpha = 0.3),
  xlab = "Temperature (degrees F)",
  ylab = "Ozone (ppb)")
matlines(nd$Temp, pq,
  lwd = 2,
  lty = c(2, 1, 2),
  col = 4)