Fitting Vector Generalized Linear Models

vglm is used to fit vector generalized linear models (VGLMs). This is a very large class of models that includes generalized linear models (GLMs) as a special case.

models, regression
vglm(formula, family = stop("argument 'family' needs to be assigned"),
     data = list(), weights = NULL, subset = NULL,
     na.action =, etastart = NULL, mustart = NULL,
     coefstart = NULL, control = vglm.control(...), offset = NULL,
     method = "", model = FALSE, x.arg = TRUE, y.arg = TRUE,
     contrasts = NULL, constraints = NULL, extra = list(),
     form2 = NULL, qr.arg = TRUE, smart = TRUE, ...)

a symbolic description of the model to be fit. The RHS of the formula is applied to each linear predictor. Different variables in each linear predictor can be chosen by specifying constraint matrices.


a function of class "vglmff" (see vglmff-class) describing what statistical model is to be fitted. This is called a ``VGAM family function''. See CommonVGAMffArguments for general information about many types of arguments found in this type of function. The argument name "family" is used loosely and for the ease of existing glm users; there is no concept of a formal ``error distribution'' for VGLMs. Possibly the argument name should be better "model" but unfortunately that name has already been taken.


an optional data frame containing the variables in the model. By default the variables are taken from environment(formula), typically the environment from which vglm is called.


an optional vector or matrix of (prior fixed and known) weights to be used in the fitting process. If the VGAM family function handles multiple responses (\(Q > 1\) of them, say) then weights can be a matrix with \(Q\) columns. Each column matches the respective response. If it is a vector (the usually case) then it is recycled into a matrix with \(Q\) columns. The values of weights must be positive; try setting a very small value such as 1.0e-8 to effectively delete an observation.

Currently the weights argument does not support sampling weights from complex sampling designs. And currently sandwich estimators are not computed in any shape or form. The present weights are multiplied by the corresponding log-likelihood contributions.


an optional logical vector specifying a subset of observations to be used in the fitting process.


a function which indicates what should happen when the data contain NAs. The default is set by the na.action setting of options, and is if that is unset. The ``factory-fresh'' default is na.omit.


starting values for the linear predictors. It is a \(M\)-column matrix with the same number of rows as the response. If \(M = 1\) then it may be a vector. Note that etastart and the output of predict(fit) should be comparable. Here, fit is the fitted object.


starting values for the fitted values. It can be a vector or a matrix; if a matrix, then it has the same number of rows as the response. Usually mustart and the output of fitted(fit) should be comparable. Some family functions do not make use of this argument.


starting values for the coefficient vector. The length and order must match that of coef(fit).


a list of parameters for controlling the fitting process. See vglm.control for details.


a vector or \(M\)-column matrix of offset values. These are a priori known and are added to the linear/additive predictors during fitting.


the method to be used in fitting the model. The default (and presently only) method uses iteratively reweighted least squares (IRLS).


a logical value indicating whether the model frame should be assigned in the model slot.

x.arg, y.arg

logical values indicating whether the model matrix and response vector/matrix used in the fitting process should be assigned in the x and y slots. Note the model matrix is the LM model matrix; to get the VGLM model matrix type model.matrix(vglmfit) where vglmfit is a vglm object.


an optional list. See the contrasts.arg of model.matrix.default.


an optional list of constraint matrices. The components of the list must be named with the term it corresponds to (and it must match in character format exactly). There are two types of input: "lm"-type and "vlm"-type. The former is a subset of the latter. The former has a matrix for each term of the LM matrix. The latter has a matrix for each column of the VLM matrix. After fitting, the constraints extractor function may be applied; it returns the "vlm"-type list of constraint matrices by default. If "lm"-type are returned by constraints then these can be fed into this argument and it should give the same model as before.

Each constraint matrix must have \(M\) rows, and be of full-column rank. By default, constraint matrices are the \(M\) by \(M\) identity matrix unless arguments in the family function itself override these values, e.g., parallel (see CommonVGAMffArguments). If constraints is used it must contain all the terms; an incomplete list is not accepted.


an optional list with any extra information that might be needed by the VGAM family function.


The second (optional) formula. If argument xij is used (see vglm.control) then form2 needs to have all terms in the model. Also, some VGAM family functions such as micmen use this argument to input the regressor variable. If given, the slots @Xm2 and @Ym2 may be assigned. Note that smart prediction applies to terms in form2 too.


logical value indicating whether the slot qr, which returns the QR decomposition of the VLM model matrix, is returned on the object.


logical value indicating whether smart prediction (smartpred) will be used.

further arguments passed into vglm.control.


A vector generalized linear model (VGLM) is loosely defined as a statistical model that is a function of \(M\) linear predictors. The central formula is given by $$\eta_j = \beta_j^T x$$ where \(x\) is a vector of explanatory variables (sometimes just a 1 for an intercept), and \(\beta_j\) is a vector of regression coefficients to be estimated. Here, \(j=1,\ldots,M\), where \(M\) is finite. Then one can write \(\eta=(\eta_1,\ldots,\eta_M)^T\) as a vector of linear predictors.

Most users will find vglm similar in flavour to glm. The function actually does the work.


An object of class "vglm", which has the following slots. Some of these may not be assigned to save space, and will be recreated if necessary later.


the list extra at the end of fitting.


the family function (of class "vglmff").


the number of IRLS iterations used.


a \(M\)-column matrix of linear predictors.


a named list which matches the columns and the (LM) model matrix terms.


the matched call.


a named vector of coefficients.


a named list of constraint matrices used in the fitting.


the contrasts used (if any).


list of control parameter used in the fitting.


list of convergence criterion evaluated at the final IRLS iteration.


the residual degrees of freedom.

the total degrees of freedom.


the scaling parameter.


the effects.


the fitted values, as a matrix. This is often the mean but may be quantiles, or the location parameter, e.g., in the Cauchy model.


a list to hold miscellaneous parameters.


the model frame.


a list holding information about missing values.


if non-zero, a \(M\)-column matrix of offsets.


a list where post-analysis results may be put.


used by plotvgam, the plotting parameters may be put here.


initially supplied weights (the weights argument). Also see weightsvglm.


the QR decomposition used in the fitting.


the R matrix in the QR decomposition used in the fitting.


numerical rank of the fitted model.


the working residuals at the final IRLS iteration.


residual sum of squares at the final IRLS iteration with the adjusted dependent vectors and weight matrices.


a list of data-dependent parameters (if any) that are used by smart prediction.


the terms object used.


the working weight matrices at the final IRLS iteration. This is in matrix-band form.


the model matrix (linear model LM, not VGLM).


the levels of the factors, if any, used in fitting.


the response, in matrix form.

This slot information is repeated at vglm-class.


This function can fit a wide variety of statistical models. Some of these are harder to fit than others because of inherent numerical difficulties associated with some of them. Successful model fitting benefits from cumulative experience. Varying the values of arguments in the VGAM family function itself is a good first step if difficulties arise, especially if initial values can be inputted. A second, more general step, is to vary the values of arguments in vglm.control. A third step is to make use of arguments such as etastart, coefstart and mustart.

Some VGAM family functions end in "ff" to avoid interference with other functions, e.g., binomialff, poissonff, gaussianff, gammaff. This is because VGAM family functions are incompatible with glm (and also gam in the gam library and gam in the mgcv library).

The smart prediction (smartpred) library is incorporated within the VGAM library.

The theory behind the scaling parameter is currently being made more rigorous, but it it should give the same value as the scale parameter for GLMs.

In Example 5 below, the xij argument to illustrate covariates that are specific to a linear predictor. Here, lop/rop are the ocular pressures of the left/right eye (artificial data). Variables leye and reye might be the presence/absence of a particular disease on the LHS/RHS eye respectively. See vglm.control and fill for more details and examples.


See warnings in vglm.control. Also, see warnings under weights above regarding sampling weights from complex sampling designs.


Yee, T. W. (2015) Vector Generalized Linear and Additive Models: With an Implementation in R. New York, USA: Springer.

Yee, T. W. and Hastie, T. J. (2003) Reduced-rank vector generalized linear models. Statistical Modelling, 3, 15--41.

Yee, T. W. and Wild, C. J. (1996) Vector generalized additive models. Journal of the Royal Statistical Society, Series B, Methodological, 58, 481--493.

Yee, T. W. (2014) Reduced-rank vector generalized linear models with two linear predictors. Computational Statistics and Data Analysis, 71, 889--902.

Yee, T. W. (2008) The VGAM Package. R News, 8, 28--39.

See Also

vglm.control, vglm-class, vglmff-class, smartpred,, fill, rrvglm, vgam. Methods functions include AICvlm, coefvlm, confintvglm, constraints.vlm, fittedvlm, hatvaluesvlm, hdeff.vglm, linkfun.vglm, lrp.vglm, nobs.vlm, npred.vlm, plotvglm, predictvglm, summaryvglm, lrtest_vglm, etc.

  • vglm
# Example 1. See help(glm)
print(d.AD <- data.frame(treatment = gl(3, 3),
                         outcome = gl(3, 1, 9),
                         counts = c(18,17,15,20,10,20,25,13,12)))
vglm.D93 <- vglm(counts ~ outcome + treatment, family = poissonff,
                 data = d.AD, trace = TRUE)

# Example 2. Multinomial logit model
pneumo <- transform(pneumo, let = log(exposure.time))
vglm(cbind(normal, mild, severe) ~ let, multinomial, data = pneumo)

# Example 3. Proportional odds model
fit3 <- vglm(cbind(normal, mild, severe) ~ let, propodds, data = pneumo)
coef(fit3, matrix = TRUE)
model.matrix(fit3, type = "lm")  # LM model matrix
model.matrix(fit3)               # Larger VGLM (or VLM) model matrix

# Example 4. Bivariate logistic model
fit4 <- vglm(cbind(nBnW, nBW, BnW, BW) ~ age, binom2.or, coalminers)
coef(fit4, matrix = TRUE)
depvar(fit4)  # Response are proportions
weights(fit4, type = "prior")

# Example 5. The use of the xij argument (simple case).
# The constraint matrix for 'op' has one column.
nn <- 1000
eyesdat <- round(data.frame(lop = runif(nn),
                            rop = runif(nn),
                             op = runif(nn)), digits = 2)
eyesdat <- transform(eyesdat, eta1 = -1 + 2 * lop,
                              eta2 = -1 + 2 * lop)
eyesdat <- transform(eyesdat,
           leye = rbinom(nn, size = 1, prob = logit(eta1, inverse = TRUE)),
           reye = rbinom(nn, size = 1, prob = logit(eta2, inverse = TRUE)))
fit5 <- vglm(cbind(leye, reye) ~ op,
             binom2.or(exchangeable = TRUE, zero = 3),
             data = eyesdat, trace = TRUE,
             xij = list(op ~ lop + rop + fill(lop)),
             form2 = ~  op + lop + rop + fill(lop))
coef(fit5, matrix = TRUE)
# }
Documentation reproduced from package VGAM, version 1.0-4, License: GPL-3

Community examples

Looks like there are no examples yet.