weightsvglm: Prior and Working Weights of a VGLM fit

Description Usage Arguments Details Value Note Author(s) See Also Examples

View source: R/family.basics.R

Description

Returns either the prior weights or working weights of a VGLM object.

Usage

1
2
3
weightsvglm(object, type = c("prior", "working"),
            matrix.arg = TRUE, ignore.slot = FALSE,
            deriv.arg = FALSE, ...)

Arguments

object

a model object from the VGAM R package that inherits from a vector generalized linear model (VGLM), e.g., a model of class "vglm".

type

Character, which type of weight is to be returned? The default is the first one.

matrix.arg

Logical, whether the answer is returned as a matrix. If not, it will be a vector.

ignore.slot

Logical. If TRUE then object@weights is ignored even if it has been assigned, and the long calculation for object@weights is repeated. This may give a slightly different answer because of the final IRLS step at convergence may or may not assign the latest value of quantities such as the mean and weights.

deriv.arg

Logical. If TRUE then a list with components deriv and weights is returned. See below for more details.

...

Currently ignored.

Details

Prior weights are usually inputted with the weights argument in functions such as vglm and vgam. It may refer to frequencies of the individual data or be weight matrices specified beforehand.

Working weights are used by the IRLS algorithm. They correspond to the second derivatives of the log-likelihood function with respect to the linear predictors. The working weights correspond to positive-definite weight matrices and are returned in matrix-band form, e.g., the first M columns correspond to the diagonals, etc.

If one wants to perturb the linear predictors then the fitted.values slots should be assigned to the object before calling this function. The reason is that, for some family functions, the variable mu is used directly as one of the parameter estimates, without recomputing it from eta.

Value

If type = "working" and deriv = TRUE then a list is returned with the two components described below. Otherwise the prior or working weights are returned depending on the value of type.

deriv

Typically the first derivative of the log-likelihood with respect to the linear predictors. For example, this is the variable deriv.mu in vglm.fit(), or equivalently, the matrix returned in the "deriv" slot of a VGAM family function.

weights

The working weights.

Note

This function is intended to be similar to weights.glm (see glm).

Author(s)

Thomas W. Yee

See Also

glm, vglmff-class, vglm.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
pneumo <- transform(pneumo, let = log(exposure.time))
(fit <- vglm(cbind(normal, mild, severe) ~ let,
             cumulative(parallel = TRUE, reverse = TRUE), data = pneumo))
depvar(fit)  # These are sample proportions
weights(fit, type = "prior", matrix = FALSE)  # Number of observations

# Look at the working residuals
nn <- nrow(model.matrix(fit, type = "lm"))
M <- ncol(predict(fit))

wwt <- weights(fit, type = "working", deriv = TRUE)  # In matrix-band format
wz <- m2a(wwt$weights, M = M)  # In array format
wzinv <- array(apply(wz, 3, solve), c(M, M, nn))
wresid <- matrix(NA, nn, M)  # Working residuals
for (ii in 1:nn)
  wresid[ii, ] <- wzinv[, , ii, drop = TRUE] %*% wwt$deriv[ii, ]
max(abs(c(resid(fit, type = "work")) - c(wresid)))  # Should be 0

(zedd <- predict(fit) + wresid)  # Adjusted dependent vector

Example output

Loading required package: stats4
Loading required package: splines

Call:
vglm(formula = cbind(normal, mild, severe) ~ let, family = cumulative(parallel = TRUE, 
    reverse = TRUE), data = pneumo)


Coefficients:
(Intercept):1 (Intercept):2           let 
    -9.676093    -10.581725      2.596807 

Degrees of Freedom: 16 Total; 13 Residual
Residual deviance: 5.026826 
Log-likelihood: -25.09026 
     normal       mild     severe
1 1.0000000 0.00000000 0.00000000
2 0.9444444 0.03703704 0.01851852
3 0.7906977 0.13953488 0.06976744
4 0.7291667 0.10416667 0.16666667
5 0.6274510 0.19607843 0.17647059
6 0.6052632 0.18421053 0.21052632
7 0.4285714 0.21428571 0.35714286
8 0.3636364 0.18181818 0.45454545
[1] 98 54 43 48 51 38 28 11
[1] 1.437464e-05
  logit(P[Y>=2]) logit(P[Y>=3])
1     -6.1173043     -7.0193456
2     -2.8183563     -3.8962823
3     -1.2774948     -2.5900103
4     -0.9888700     -1.5560630
5     -0.5211240     -1.5385773
6     -0.4224572     -1.3017459
7      0.2876506     -0.5873817
8      0.5596158     -0.1803636

VGAM documentation built on Jan. 16, 2021, 5:21 p.m.