Last chance! 50% off unlimited learning
Sale ends in
margeff(object, subset = NULL, ...)
vglm
object,
with one of the following family functions:
multinomial
,
cumulative
,
In general, if
is.numeric(subset)
and
length(subset) == 1
then a
$p$ by $M+1$ matrix is returned.
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.
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
multinomial
,
cumulative
,
propodds
,
acat
,
cratio
,
sratio
,
vglm
.# 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",,])
Run the code above in your browser using DataLab