damultinom: Discriminant Adaptive Multinomial Log-linear Models

Description Usage Arguments Details Value References See Also Examples

View source: R/damultinom.R

Description

A local version of multinomial regression from package nnet that puts increased emphasis on a good model fit near the decision boundary.

Usage

1
2
damultinom(formula, data, weights, subset, na.action, contrasts = NULL,
  Hess = FALSE, censored = FALSE, model = FALSE, ...)

Arguments

formula

A formula expression as for regression models, of the form response ~ predictors. The response should be a factor or a matrix with K columns. If censored = FALSE this is required to be a zero-one indicator matrix. A log-linear model is fitted, with coefficients zero for the first class. An offset can be included: it should be a numeric matrix with K columns if the response is either a matrix with K columns or a factor with K > 2 classes, or a numeric vector for a response factor with 2 levels. See the documentation of formula() for other details.

data

An optional data frame in which to interpret the variables occurring in formula.

weights

Initial case weights in fitting (defaults to a vector of 1s).

subset

Expression saying which subset of the rows of the data should be used in the fit. All observations are included by default.

na.action

A function to filter missing data.

contrasts

A list of contrasts to be used for some or all of the factors appearing as variables in the model formula.

Hess

Logical for whether the Hessian (the observed/expected information matrix) should be returned.

censored

Logical. If the response is a matrix with K > 2 classes, interpret the entries as one for possible classes, zero for impossible classes. Defaults to FALSE.

model

Logical. If TRUE, the model frame is saved as component model of the returned object.

...

Additional arguments for dannet, including the window function and bandwidth parameters used to generate observation weights:

wf

A window function which is used to calculate weights that are introduced into the fitting process. Either a character string or a function, e.g. wf = function(x) exp(-x). For details see the documentation for wfs.

bw

(Required only if wf is a string.) The bandwidth parameter of the window function. (See wfs.)

k

(Required only if wf is a string.) The number of nearest neighbors of the decision boundary to be used in the fitting process. (See wfs.)

nn.only

(Required only if wf is a string indicating a window function with infinite support and if k is specified.) Should only the k nearest neighbors or all observations receive positive weights? (See wfs.)

itr

Number of iterations for model fitting, defaults to 3. See also the Details section.

Details

The idea of Hand and Vinciotti (2003) to put increased weight on observations near the decision boundary is generalized to the multiclass case and applied to multinomial regression. Since the decision boundary is not known in advance an iterative procedure is required. First, an unweighted multinomial regression model is fitted to the data. Based on the differences between the two largest estimated posterior probabilities observation weights are calculated. Then a weighted multinomial regression model (see multinom) is fitted using these weights. Calculation of weights and model fitting is done several times in turn. The number of iterations is determined by the itr-argument that defaults to 3.

The name of the window function (wf) can be specified as a character string. In this case the window function is generated internally in damultinom. Currently supported are "biweight", "cauchy", "cosine", "epanechnikov", "exponential", "gaussian", "optcosine", "rectangular" and "triangular".

Moreover, it is possible to generate the window functions mentioned above in advance (see wfs) and pass them to damultinom.

Any other function implementing a window function can also be used as wf argument. This allows the user to try own window functions. See help on wfs for details.

damultinom calls dannet. The variables on the rhs of the formula should be roughly scaled to [0,1] or the fit will be slow or may not converge at all.

Observation weights that reflect the importance of training observations for the fit at a particular test observation are calculated internally in damultinom. For this reason not all types of response in formula are allowed and damultinom does not take all arguments that can be passed to multinom. As response in formula factors and matrices are allowed. If censored = FALSE only zero-one class indicator matrices are allowed. Argument summ that specifies a method to summarize rows of the model matrix is missing since this requires adjustment of the case weights.

Value

A "damultinom" object (that inherits from "dannet" and "nnet") with additional components:

deviance

The residual deviance, compared to the full saturated model (that explains individual observations exactly). Also, minus twice log-likelihood.

edf

The (effective) number of degrees of freedom used by the model.

AIC

The AIC for this fit.

Hessian

(if Hess is true).

model

(if model is true).

References

Hand, D. J., Vinciotti, V. (2003), Local versus global models for classification problems: Fitting models where it matters, The American Statistician, 57(2) 124–130.

Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.

See Also

multinom, dannet, nnet, predict.damultinom.

Examples

1
2
3
4
5
6
7
fit <- damultinom(Species ~ Sepal.Length + Sepal.Width, data = iris, wf = "gaussian", bw = 0.5, Hess=TRUE)
pred <- predict(fit)
mean(pred$class != iris$Species)

fit <- damultinom(Species ~ Sepal.Length + Sepal.Width, data = iris, wf = "gaussian", bw = 0.5, weights=1:nrow(iris), trace=FALSE)
pred <- predict(fit)
mean(pred$class != iris$Species)

schiffner/locClass documentation built on May 29, 2019, 3:39 p.m.