这将为您提供新的公式对象。它们是否正常工作可能仍然存在问题,因为它们具有关联的环境并且您没有提供用于测试的数据集。从 hte update.formula 页面上的示例开始:
> ## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
> ## Page 9: Plant Weight Data.
> ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
> trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
> group <- gl(2, 10, 20, labels = c("Ctl", "Trt"))
> weight <- c(ctl, trt)
> lm.D9 <- lm(weight ~ group)
> update.formula(lm.D9$call[[2]], .~.)
weight ~ group # Just to make sure that we got something sensible.
<environment: 0x1212230b0>
> update.formula(lm.D9$call[[2]], Z~.)
Z ~ group
<environment: 0x102799fc8>
似乎使用以下随机排列在我的测试用例上工作weight
:
> Z <- sample(weight)
> lm(update.formula(lm.D9$call[[2]], Z~.), data.frame(Z=Z, group=group) )
Call:
lm(formula = update.formula(lm.D9$call[[2]], Z ~ .), data = data.frame(Z = Z,
group = group))
Coefficients:
(Intercept) groupTrt
4.711 0.271