Learn R Programming

VGAM (version 0.8-7)

Qvar: Quasi-variances Preprocessing Function

Description

Takes a vglm fit or a variance-covariance matrix, and preprocesses it for rcam and normal1 so that quasi-variances can be computed.

Usage

Qvar(object, factorname = NULL, coef.indices = NULL, labels = NULL,
     dispersion = NULL, reference.name = "(reference)", estimates = NULL)

Arguments

object
A "vglm" object or a variance-covariance matrix, e.g., vcov(vglm.object). The former is preferred since it contains all the information needed. If a matrix then fa
factorname
Character. If the vglm object contains more than one factor as explanatory variable then this argument should be the name of the factor of interest. If object is a variance-covariance matr
labels
Character. Optional, for labelling the variance-covariance matrix.
dispersion
Numeric. Optional, passed into vcov() with the same argument name.
reference.name
Character. Label for for the reference level.
coef.indices
Optional numeric vector of length at least 3 specifying the indices of the factor from the variance-covariance matrix.
estimates
an optional vector of estimated coefficients (redundant if object is a model).

Value

  • A $L$ by $L$ matrix whose $i$-$j$ element is the logarithm of the variance of the $i$th coefficient minus the $j$th coefficient, for all values of $i$ and $j$. The diagonal elements are abitrary and are set to zero.

    The matrix has an attribute that corresponds to the prior weight matrix; it is accessed by normal1 and replaces the usual weights argument. of vglm. This weight matrix has ones on the off-diagonals and some small positive number on the diagonals.

Warning

Negative quasi-variances may occur (one of them and only one), though they are rare in practice. If so then numerical problems may occur. See qvcalc() for more information.

Details

Suppose a factor with $L$ levels is an explanatory variable in a regression model. By default, R treats the first level as baseline so that its coefficient is set to zero. It estimates the other $L-1$ coefficients, and with its associated standard errors, this is the conventional output. From the complete variance-covariance matrix one can compute $L$ quasi-variances based on all pairwise difference of the coefficients. They are based on an approximation, and can be treated as uncorrelated. In minimizing the relative (not absolute) errors it is not hard to see that the estimation involves a RCAM (rcam) with an exponential link function (explink).

If object is a model, then at least one of factorname or coef.indices must be non-NULL. The value of coef.indices, if non-NULL, determines which rows and columns of the model's variance-covariance matrix to use. If coef.indices contains a zero, an extra row and column are included at the indicated position, to represent the zero variances and covariances associated with a reference level. If coef.indices is NULL, then factorname should be the name of a factor effect in the model, and is used in order to extract the necessary variance-covariance estimates.

Quasi-variances were first implemented in R with qvcalc. This implementation draws heavily from that.

References

Firth, D. (2003) Overcoming the reference category problem in the presentation of statistical models. Sociological Methodology 33, 1--18.

Firth, D. and de Menezes, R. X. (2004) Quasi-variances. Biometrika 91, 65--80.

See Also

rcam, vglm, normal1, explink, qvcalc() in qvcalc, ships.

Examples

Run this code
data("ships", package = "MASS")

Shipmodel <- vglm(incidents ~ type + year + period,
                  quasipoissonff, offset = log(service),
#                 trace = TRUE, model = TRUE,
                  data = ships, subset = (service > 0))

# Easiest form of input
fit1 <- rcam(Qvar(Shipmodel, "type"), normal1("explink"), maxit = 99)
(quasiVar <- exp(diag(fitted(fit1))) / 2)                 # Version 1
(quasiVar <- diag(predict(fit1)[, c(TRUE, FALSE)]) / 2)   # Version 2
(quasiSE  <- sqrt(quasiVar))

# Another form of input
fit2 <- rcam(Qvar(Shipmodel, coef.ind = c(0,2:5), reference.name = "typeA"),
             normal1("explink"), maxit = 99)
plotqvar(fit2, col = "orange", lwd = 3, scol = "blue", slwd = 2, las = 1)

# The variance-covariance matrix is another form of input (not recommended)
fit3 <- rcam(Qvar(cbind(0, rbind(0, vcov(Shipmodel)[2:5, 2:5])),
                  labels = c("typeA", "typeB", "typeC", "typeD", "typeE"),
                  estimates = c(typeA = 0, coef(Shipmodel)[2:5])),
             normal1("explink"), maxit = 99)
(QuasiVar <- exp(diag(fitted(fit3))) / 2)                 # Version 1
(QuasiVar <- diag(predict(fit3)[, c(TRUE, FALSE)]) / 2)   # Version 2
(QuasiSE  <- sqrt(quasiVar))
plotqvar(fit3)

Run the code above in your browser using DataLab