walsNBfitIterate {WALS}R Documentation

Iteratively fitting walsNB, internal function for walsNB.formula and walsNB.matrix.

Description

Wrapper around walsNBfit that allows iteratively (re-)fitting walsNB models.

Usage

walsNBfitIterate(
  y,
  X1,
  X2,
  link = "log",
  na.action = NULL,
  weights = NULL,
  offset = NULL,
  prior = weibull(),
  controlInitNB = controlNB(),
  keepY = TRUE,
  keepX = FALSE,
  iterate = FALSE,
  tol = 1e-06,
  maxIt = 50,
  nIt = NULL,
  verbose = FALSE,
  ...
)

Arguments

y

Count response as vector.

X1

Design matrix for focus regressors. Usually includes a constant (column full of 1s) and can be generated using model.matrix.

X2

Design matrix for auxiliary regressors. Usually does not include a constant column and can also be generated using model.matrix.

link

specifies the link function, currently only "log" is supported.

na.action

Not implemented yet.

weights

Not implemented yet.

offset

Not implemented yet.

prior

Object of class "familyPrior". For example weibull or laplace.

controlInitNB

Controls estimation of starting values for one-step ML, see controlNB.

keepY

If TRUE, then output keeps response.

keepX

If TRUE, then output keeps the design matrices.

iterate

if TRUE then the WALS algorithm is iterated using the previous estimates as starting values.

tol

Only used if iterate = TRUE and nIt = NULL. If the Euclidean distance between the previous and current coefficient vector divided by the square root of the length of the vector falls below tol and the absolute difference between the previous and current dispersion parameter falls below tol, then the algorithm stops. See below for more details.

maxIt

Only used if iterate = TRUE and nIt = NULL. Aborts iterative fitting when number of iterations exceed maxIt.

nIt

Only used if iterate = TRUE. If this is specified, then tol is ignored and the algorithm iterates nIt times.

verbose

If verbose = TRUE, then it prints the iteration process (only relevant if iterate = TRUE).

...

Arguments to be passed to the workhorse function walsNBfit.

Details

The parameter tol is used to control the convergence of the iterative fitting algorithm. Let i be the current iteration step for the coefficient vector \beta_{i} = (\beta_{i,1}, \ldots, \beta_{i,k})', k > 0, and dispersion parameter \rho_{i}. If

\frac{||\beta_{i} - \beta_{i-1}||_{2}}{\sqrt{k}} = \sqrt{\frac{\sum_{j = 1}^{k} (\beta_{i,j} - \beta_{i-1,j})^{2}}{k}} < \texttt{tol},

and

|\rho_{i} - \rho_{i-1}| < \texttt{tol},

then the fitting process is assumed to have converged and stops.

Value

A list containing all elements returned from walsNBfit and additionally the following elements:

y

If keepY = TRUE, contains the response vector.

x

list. If keepX = TRUE, then it is a list with elements x1 and x2 containing the design matrices of the focus and auxiliary regressors, respectively.

initialFit

List containing information (e.g. convergence) on the estimation of the starting values for walsNBfit. See return of fitNB2 for more information.

weights

returns the argument weights.

offset

returns the argument offset.

converged

Logical. Only relevant if iterate = TRUE. Equals TRUE if iterative fitting converged, else FALSE. Is NULL if iterate = FALSE.

it

Number of iterations run in the iterative fitting algorithm. NULL if iterate = FALSE.

deviance

Deviance of the fitted (conditional) NB2 regression model.

residuals

Raw residuals, i.e. response - fitted mean.

See Also

walsNB, walsNBfit.

Examples

data("NMES1988", package = "AER")
NMES1988 <- na.omit(NMES1988)
form <- (visits ~ health + chronic + age + insurance + adl + region + gender
         + married + income + school + employed)
X <- model.matrix(form, data = NMES1988)
focus <- c("(Intercept)", "healthpoor", "healthexcellent", "chronic", "age",
        "insuranceyes")
aux <- c("adllimited", "regionnortheast", "regionmidwest", "regionwest",
         "gendermale", "marriedyes", "income", "school", "employedyes")
X1 <- X[, focus]
X2 <- X[, aux]
y <- NMES1988$visits

str(walsNBfitIterate(y, X1, X2, prior = weibull(), link = "log",
                     method = "fullSVD", iterate = TRUE))


[Package WALS version 0.2.5 Index]