我試圖存儲下面代碼的結果,但是我只能想出一個解決方案來保存模型殘差平方和最小的結果。這是有用的,直到結果在c和gamma的範圍內,因此我需要評估其他點的特徵。爲此,我需要存儲每次迭代的結果。有沒有人知道如何在這種情況下做到這一點?在R中存儲循環迭代的結果
在此先感謝!
dlpib1 <- info$dlpib1
scale <- sqrt(var(dlpib1))
RSS.m <- 10
for (c in seq(-0.03,0.05,0.001)){
for (gamma in seq(1,100,0.2))
{
trans <- (1+exp(-(gamma/scale)*(dlpib1-c)))^-1
grid.regre <-lm(dlpib ~ dlpib1 + dlpib8 + trans + trans*dlpib1 +
+ I(trans*dlpib4) ,data=info)
coef <- grid.regre$coefficients
RSS <- sum(grid.regre$residuals^2)
if (RSS < RSS.m){
RSS.m <- RSS
gamma.m <- gamma
c.m <- c
coef.m <- coef
}
}
}
grid <- c(RSS=RSS.m,gamma=gamma.m,c=c.m,coef.m)
grid`
作爲一般尖端,避免使用'C'如在'R'變量名,因爲它也是最高度使用的功能之一的名稱,'C()' –