weightsvglm               package:VGAM               R Documentation

_P_r_i_o_r _a_n_d _W_o_r_k_i_n_g _W_e_i_g_h_t_s _o_f _a _V_G_L_M _f_i_t

_D_e_s_c_r_i_p_t_i_o_n:

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

_U_s_a_g_e:

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

_A_r_g_u_m_e_n_t_s:

  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.

_D_e_t_a_i_l_s:

     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.

_V_a_l_u_e:

     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.

_N_o_t_e:

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

_A_u_t_h_o_r(_s):

     Thomas W. Yee

_R_e_f_e_r_e_n_c_e_s:

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

     Chambers, J. M. and T. J. Hastie (eds) (1992) _Statistical Models
     in S_. Wadsworth & Brooks/Cole.

_S_e_e _A_l_s_o:

     'glm', 'vglmff-class', 'vglm'.

_E_x_a_m_p_l_e_s:

     data(pneumo)
     pneumo = transform(pneumo, let=log(exposure.time))
     (fit = vglm(cbind(normal, mild, severe) ~ let,
                cumulative(parallel=TRUE, reverse=TRUE), pneumo))
     fit@y                      # These are sample proportions 
     weights(fit, type="prior", matrix=FALSE) # Number of observations

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

     temp = weights(fit, type="working", deriv=TRUE)
     wz = m2adefault(temp$weights, M=M)  # In array format
     wzinv = array(apply(wz, 3, solve), c(M,M,n))
     wresid = matrix(NA, n, M)  # working residuals 
     for(i in 1:n)
         wresid[i,] = wzinv[,,i,drop=TRUE] %*% temp$deriv[i,]
     max(abs(c(resid(fit, type="w")) - c(wresid))) # Should be 0

     z = predict(fit) + wresid  # Adjusted dependent vector 
     z

