非线性最小二乘回归问题

时间:2014-10-20 21:04:01

标签: r nls

我在尝试使用' nls'来估算模型时遇到了问题。功能。我试图在以下等式中估计参数(即j=0,1,...,9的a j ')

log(y) = log(a0 + a1*x1 + a2*x2 + a3*x3 + a4*(x1)^2 + a5*(x2)^2 + 
             a6*(x3)^2 + a7*(x1*x2) + a8*(x1*x3) + a9*(x2*x3)) + error

为了避免log函数内的负值,我根据以下代码在非线性最小二乘模型中设置参数的起始值:

ols.model <- lm(y ~ x1 + x2 + x3 + (x1)^2 + (x2)^2 + (x3)^2 + x1*x2 + 
                x1*x3 + x2*x3)
ols.coefficients <- ols.model$coefficients
fitted <- fitted(ols.model)
fitted <- fitted-ols.coefficients[1]
min.fitted <- min(fitted)
b0.start <- -min.fitted + 0.1

以上确保log函数内的起始拟合值均不为负。我对nls回归的调用看起来像这样:

nls.model <- nls(log(y) ~ log(b0 + b1*x1 + b2*x2 + b3*x3 + b4*(x1)^2 + 
                 b5*(x2)^2 + b6*(x3)^2 + b7*(x1*x2) + b8*(x1*x3) + 
                 b9*(x2*x3)),
             start=list(b0=b0.start, b1=ols.coefficients[2], 
                        b2=ols.coefficients[3], b3=ols.coefficients[4],
                        b4=ols.coefficients[5],b5=ols.coefficients[6],
                        b6=ols.coefficients[7], b7=ols.coefficients[8], 
                        b8=ols.coefficients[9], b9=ols.coefficients[10]),
             trace=TRUE)

尽管有这些精心挑选的起始参数值,但我仍然会收到一条错误消息:

Error in numericDeriv(form[[3L]], names(ind), env) : 
Missing value or an infinity produced when evaluating the model
In addition: Warning message:
In log(b0 + b1 * x1 + b2 * x2 + b3 * x3 + b4 * x4 +  :
NaNs produced

有没有人知道如何解决此问题并估算非线性模型而不会收到错误消息?我的数据集不包含任何缺失值或零值,因此绝对不是问题。

0 个答案:

没有答案
相关问题