我有一個類似的問題,我想計算R中的非線性迴歸,但是我得到一個錯誤。非線性迴歸R
這是我的代碼:
f <- function(x1,x2,x3,a,b1,b2,b3) {a * (x1^b1) * (x2^b2) * (x3^b3) }
# generate some data
x1 <- c(9,9,12,12,12,16,9,16)
x2 <- c(0.8,1,0.8,1,1.2,1.2,1.2,1)
x3 <- c(0.14,0.12,0.16,0.14,0.12,0.16,0.16,0.14)
y <- c(304,284,435,489,512,854,517,669)
dat <- data.frame(x1,x2,x3, y)
# fit a nonlinear model
fm <- nls(y ~ f(x1,x2,x3,a,b1,b2,b3), data = dat, start = c(a=0, b1=0,b2=0,b3=0))
# get estimates of a, b
co <- coef(fm)
而且我得到了這個錯誤:
Error in nlsModel(formula, mf, start, wts) : singular gradient matrix at initial parameter estimates
我該怎麼辦?
謝謝!