When I execute the following code for testing proportional odds assumption in the ordered logit model it works fine:
data = transform(VGAM::pneumo, let=log(exposure.time))
formula = cbind(normal, mild, severe) ~ let
fit_po = VGAM::vglm(formula, family=VGAM::cumulative(parallel=TRUE, link='logitlink'), data=data)
fit_h0 = VGAM::vglm(formula, family=VGAM::cumulative(parallel=FALSE, link='logitlink'), data=data)
VGAM::lrtest(fit_po, fit_h0)
However, when I try to wrap it into a helper function log_lr_po_assumption
:
log_lr_po_assumption = function(formula, data, method='logitlink') {
fit_po = VGAM::vglm(formula, family=VGAM::cumulative(parallel=TRUE, link=method), data=data)
fit_h0 = VGAM::vglm(formula, family=VGAM::cumulative(parallel=FALSE, link=method), data=data)
VGAM::lrtest(fit_po, fit_h0)
}
log_lr_po_assumption(formula, data)
it fails with:
Error in get(fun.name) : object 'method' not found
Why is it so? How can I create a convenience wrapper which will work?
One way to solve it is to force eager evaluation using
do.call
(with the defaultquote=FALSE
):Though I believe that an easier solution should exist...