我嘗試用optim()
函數估計三個參數a,b0和b1。但我總是得到錯誤: 優化錯誤(par = c(1,1,1),fn = logweibull,method =「L-BFGS-B」,: L-BFGS-B需要有限值'fn 「R optim()L-BFGS-B需要有限的'fn'值 - Weibull
t<-c(6,6,6,6,7,9,10,10,11,13,16,17,19,20,22,23,25,32,32,34,35,1,1,2,2,3,4,4,5,5,8,8,8,8,11,11,12,12,15,17,22,23)
d<-c(0,1,1,1,1,0,0,1,0,1,1,0,0,0,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
X<-c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
logweibull <- function (a,b0,b1) {a <- v[1];b0 <- v[2]; b1 <- v[3];
sum (d*log(t^a*exp(b0+X*b1)-t^a*exp(b0+X*b1))) + sum (d + log((a*t^(a-1))/t^a)) }
v<-c(1,1,1)
optim(par=c(1,1,1) ,fn = logweibull, method = "L-BFGS-B",lower = c(0.1, 0.1,0.1), upper = c(100, 100,100),control = list(fnscale = -1))
你能幫我嗎?你知道我做錯了什麼?
'logweibull < - 功能(A,B0,B1){一個< - V [1]; B0 < - V [2]; b1 <-v [3]; sum(d * log(t^a * exp(b0 + X * b1)) - t^a * exp(b0 + X * b1))+ sum * t ^(a-1))/ t^a))}'謝謝有一個錯誤,缺少一些括號。但是現在這個功能仍然不能正常工作。我將只將起始值作爲估計參數返回。你有什麼想法嗎? – Hans