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

View source: R/family.categorical.R

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

1 |

`object` |
A |

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

`...` |
further arguments passed into the other methods functions. |

Computes the derivative of the fitted probabilities of the categorical response model with respect to each explanatory variable. Formerly one big function, this function now uses S4 dispatch to break up the computations.

The function `margeff()`

is *not* generic. However, it
calls the function `margeffS4VGAM()`

which *is*.
This is based on the class of the `VGAMff`

argument, and
it uses the S4 function `setMethod`

to
correctly dispatch to the required methods function.
The inheritance is given by the `vfamily`

slot of the
VGAM family function.

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.

In general, if
`is.numeric(subset)`

and
`length(subset) == 1`

then a
*p* by *M+1* matrix is returned.

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.

Some numerical problems may occur if the fitted values are
close to 0 or 1 for the
`cratio`

and
`sratio`

models.
Models with offsets may result in an incorrect answer.

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.

Some other limitations are imposed, e.g.,
for `acat`

models
only a `loglink`

link is allowed.

T. W. Yee, with some help and motivation from Stasha Rmandic.

`multinomial`

,
`cumulative`

,
`propodds`

,
`acat`

,
`cratio`

,
`sratio`

,
`vglm`

.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ```
# 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, data = 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(digits = 3, (newp-fitted(fit)[ii, ])/hh) # Finite-difference approxn
round(digits = 3, margeff(fit, subset = ii)["let",])
# Other examples
round(digits = 3, margeff(fit))
round(digits = 3, margeff(fit, subset = 2)["let",])
round(digits = 3, margeff(fit, subset = c(FALSE, TRUE))["let",,]) # recycling
round(digits = 3, margeff(fit, subset = c(2, 4, 6, 8))["let",,])
``` |

```
Loading required package: stats4
Loading required package: splines
normal mild severe
0.84670042 0.08509397 0.06820561
normal mild severe
1 0.8432994 0.08682604 0.06987459
normal mild severe
1 -0.34 0.173 0.167
normal mild severe
-0.337 0.172 0.165
, , 1
normal mild severe
(Intercept) 0.058 -0.032 -0.026
let -0.015 0.009 0.006
, , 2
normal mild severe
(Intercept) 0.600 -0.312 -0.287
let -0.161 0.090 0.071
, , 3
normal mild severe
(Intercept) 1.256 -0.583 -0.673
let -0.337 0.172 0.165
, , 4
normal mild severe
(Intercept) 1.840 -0.708 -1.132
let -0.494 0.216 0.278
, , 5
normal mild severe
(Intercept) 2.241 -0.625 -1.616
let -0.601 0.205 0.396
, , 6
normal mild severe
(Intercept) 2.409 -0.362 -2.047
let -0.646 0.144 0.502
, , 7
normal mild severe
(Intercept) 2.377 0.016 -2.392
let -0.638 0.051 0.587
, , 8
normal mild severe
(Intercept) 2.239 0.329 -2.568
let -0.601 -0.029 0.630
normal mild severe
-0.161 0.090 0.071
2 4 6 8
normal -0.161 -0.494 -0.646 -0.601
mild 0.090 0.216 0.144 -0.029
severe 0.071 0.278 0.502 0.630
2 4 6 8
normal -0.161 -0.494 -0.646 -0.601
mild 0.090 0.216 0.144 -0.029
severe 0.071 0.278 0.502 0.630
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.