我的R公式對象:更新公式對象與偏移功能
R> formula.obj <- Y ~ 1 + X + offset(Z)
我想擺脫偏移(Z),並獲得:
R> formula.obj.want <- Y ~ 1 + X
似乎更新功能在這種情況下不起作用:
R> update(formula.obj,.~.-offset(Z))
Y ~ X + offset(Z)
有沒有辦法從formula.obj獲取formula.obj.want?
我的R公式對象:更新公式對象與偏移功能
R> formula.obj <- Y ~ 1 + X + offset(Z)
我想擺脫偏移(Z),並獲得:
R> formula.obj.want <- Y ~ 1 + X
似乎更新功能在這種情況下不起作用:
R> update(formula.obj,.~.-offset(Z))
Y ~ X + offset(Z)
有沒有辦法從formula.obj獲取formula.obj.want?
你不能在更新中做到這一點。 「 - 」不支持偏移公式http://stat.ethz.ch/R-manual/R-patched/library/stats/html/offset.html 定義爲u做
您可以使用列表結構和語言
> formula.obj[[3]] <- quote(1 + X)
> formula.obj
Y ~ 1 + X
> class(formula.obj)
[1] "formula"
請注意,我也嘗試update
另一個函數,它不想包括1
> update(formula.obj, .~ 1 + X)
Y ~ X
是如何那b etter比'更新(formula.obj ,.〜1 + X)'...? – 2014-11-05 01:55:51
因爲當我使用'update'' – 2014-11-05 02:00:41
時,我的機器上沒有顯示1(雖然實際的公式是等價的)。 – 2014-11-05 02:12:09
另一種可能性(雖然不如優雅)。將包含/排除'offset'作爲單獨的參數(不一定普遍的,但是被允許在'lm'和'glm') – 2014-11-05 02:13:09