這會給你新的formul對象。它們是否正常工作可能仍然存在問題,因爲它們具有關聯的環境,並且您沒有提供用於測試的數據集。與興田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
嘗試使用'update'? – liuminzhao 2013-02-25 18:05:19
看起來很有用,乍一看。 – tomka 2013-02-25 18:15:28
在這種情況下,聽起來好像你還沒有完全描述你的問題,這很難回答。嘗試更具體。運行一個特定的例子,用每一步中使用的實際代碼。 – joran 2013-02-25 18:54:01