margeff                 package:VGAM                 R Documentation

_M_a_r_g_i_n_a_l _e_f_f_e_c_t_s _f_o_r _t_h_e _m_u_l_t_i_n_o_m_i_a_l _l_o_g_i_t _a_n_d _c_u_m_u_l_a_t_i_v_e _m_o_d_e_l_s

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

     Marginal effects for the multinomial logit model and cumulative
     logit/probit/... models: the derivative of the fitted
     probabilities with respect to each explanatory variable.

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

     margeff(object, subset=NULL)

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

  object: A 'vglm' 'multinomial' or 'cumulative' object.

  subset: Numerical or logical vector, denoting the required
          observation(s). Recycling is used if possible. The default
          means all observations.

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

     Computes the derivative of the fitted probabilities of a
     multinomial logit model or cumulative logit/probit/... model with
     respect to each explanatory variable.

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

     A p by M+1 by n array, where p is the number of explanatory
     variables and the (hopefully) nominal response has M+1 levels, and
     there are n observations.

     If 'is.numeric(subset)' and 'length(subset) == 1' then a p by M+1
     matrix is returned.

_W_a_r_n_i_n_g:

     Care is needed in interpretation, e.g., the change is not
     universally accurate for a unit change in each explanatory
     variable because eventually the `new' probabilities may become
     negative or greater than unity. Also, the `new' probabilities will
     not sum to one.

     This function is not applicable for models with data-dependent
     terms such as 'bs' and 'poly'. Also the function should not be
     applied to models with any terms that have generated more than one
     column of the LM model matrix, such as 'bs' and 'poly'. For such
     try using numerical methods such as finite-differences. The
     'formula' in 'object' should comprise of simple terms of the form
     ' ~ x2 + x3 + x4', etc.

_N_o_t_e:

     For 'multinomial' this function should handle any value of
     'refLevel' and also any constraint matrices. However, it does not
     currently handle the 'xij' or 'form2' arguments, nor 'vgam'
     objects.

     For 'multinomial' if 'subset' is numeric then the function uses a
     'for' loop over the observations (slow). The default computations
     use vectorization; this uses more memory than a 'for' loop but is
     faster.

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

     T. W. Yee

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

     'multinomial', 'cumulative', 'vglm'.

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

     # Not a good example for multinomial() because the response is ordinal!!
     ii = 3; hh = 1/100
     pneumo = transform(pneumo, let = log(exposure.time))
     fit = vglm(cbind(normal, mild, severe) ~ let, multinomial, pneumo)
     fit = vglm(cbind(normal, mild, severe) ~ let,
                cumulative(reverse=TRUE,  parallel=TRUE),
                data = pneumo)
     fitted(fit)[ii,]

     mynewdata = with(pneumo, data.frame(let = let[ii]+hh))
     (newp <- predict(fit, newdata=mynewdata, type="response"))

     # Compare the difference. Should be the same as hh --> 0.
     round(dig=3, (newp-fitted(fit)[ii,])/hh) # Finite-difference approximation
     round(dig=3, margeff(fit, subset=ii)["let",])

     # Other examples
     round(dig=3, margeff(fit))
     round(dig=3, margeff(fit, subset=2)["let",])
     round(dig=3, margeff(fit, subset=c(FALSE,TRUE))["let",,]) # recycling
     round(dig=3, margeff(fit, subset=c(2,4,6,8))["let",,])

