当我执行以下代码来测试有序logit模型中的比例优势假设时,它工作得很好:
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)
然而,当我试图将其包装成一个helper函数时
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)
出现以下故障:
Error in get(fun.name) : object 'method' not found
为什么会这样?我如何创建一个方便的包装,这将工作?