获得非线性多元回归参数估计

时间:2015-04-26 00:12:04

标签: r statistics regression non-linear-regression

我正在考虑获取具有3个维度的数据的参数估计值。我使用mathematica中的manipulate函数将其绘制出来。但是,当我使用mathematica中我认为合适的常量时,我​​最终得到了单个渐变错误。那么,是否有一种图形方法可以在R中使用我的估计来绘制我的数据的3d图,或者是否有人对如何纠正错误有任何建议?

Distance<-c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,15 ,15 ,15 ,15 ,15 ,15 ,15 ,15 ,15 ,15 ,15 ,15, 15 ,15, 15 ,15 ,15 ,15,15 ,15 ,20, 20 ,20, 20 ,20, 20 ,20, 20 ,20 ,20 ,20 ,20 ,20 ,20, 20 ,20, 20 ,20, 20 ,20, 20)
Height<-c(400   ,300 ,  200,     0  ,-200 , -400  ,-600 , -800 ,-1000 ,-1000 ,-1200, -1220 ,-1300 ,-1400,-1400 ,-1500, -1600, -1700 ,-1700 ,-1800 ,-1900 ,  400 ,  200 ,    0  ,-200,  -400  ,-600 , -800,-1000 ,-1200, -1200 ,-1400 ,-1600 ,-1600 ,-1800 ,-2000 ,-2000 ,-2200 ,-2200 ,-2400 ,-2600 ,-2800,-3000  , 400 ,  200  ,   0  ,-200  ,-300 , -400 , -500  ,-600  ,-700  ,-800  ,-900 ,-1000 ,-1100,-1200 ,-1200 ,-1400, -1600 ,-1800 ,-1800 ,-2000 ,-2200 ,-2400 ,-2400 ,-2600 ,-2800 ,-3000  , 400,200  ,   0,  -200,  -400  ,-600  ,-800, -1000 ,-1200 ,-1400 ,-1600 ,-1600 ,-1800 ,-2000, -2200,-2400 ,-2400, -2600, -2800 ,-3000  ,1000 ,  800  , 600 ,  400  , 200  ,   0  ,-200 , -400 , -600, -800 ,-1000, -1200 ,-1400, -1600 ,-1800, -2000 ,-2200, -2400 ,-2600 ,-2800 ,-3000)
Value<-c(163301.080, 269704.110 ,334570.550, 409536.530, 433021.260 ,418962.060, 349554.460, 253987.570,124461.710, 140750.480  ,52612.790 , 54286.427  ,26150.025  ,14631.210  ,15780.244 ,  8053.618, 4402.581,   2251.137  , 2743.511 ,  1707.508 ,  1246.894 ,176232.060 ,270797.240 ,323096.710,333401.080, 311949.900 ,272821.770 ,189571.850 ,114263.560  ,51939.070  ,62578.665  ,36905.438,  22625.515,  22940.591  ,14576.295  , 9686.653 , 10344.214  , 6912.779  , 7092.919   ,5366.797, 4058.492,   3270.734  , 2528.644  ,89311.555 ,116698.175 ,143588.620 ,139203.190, 145399.445, 145635.715, 134671.110 ,128931.160 ,119734.835 ,108708.815 , 90221.955  ,81692.585 , 64882.275,58215.735,  60443.190  ,44690.690 , 33224.152 , 24140.272 , 24913.280  ,19082.689  ,13920.669, 11074.718,  10015.653   ,8743.850  , 7516.880 ,  6377.743 , 36888.842  ,43088.720  ,47904.490, 51298.710,  51120.887  ,47687.488  ,42238.912 , 38563.007 , 33902.918  ,28565.303  ,23700.862,24818.393,  21620.129 , 17816.061  ,15377.097 , 12992.321  ,12985.911  ,11177.941   ,9536.621,8357.279,  13052.178 , 14325.789  ,15120.314 , 16227.575  ,17226.307  ,18557.270  ,18680.326, 18844.544,  18205.607,  17770.311  ,16605.438 , 16062.309  ,14785.654  ,14324.493  ,13373.627,12135.392,  10632.699,   9155.762  , 8240.951,   6934.240  , 6475.927)


fit<-nls(Value~a*(exp(-(Height+b)^2/(2*c^2))+(Distance-d)^2/(2*e^2))+g*exp(-abs((-h*Height)^2+(-i*Distance)^2))+f, start = list(a=300000,b=200,c=0.003,d=0,e=0.1,f=1100,g=50000,h=0.001,i=0.085))
summary(fit)

感谢您的任何建议

1 个答案:

答案 0 :(得分:0)

虽然我无法完全回答,但你发现nls2套餐很有用。以下是快速测试。

# fit with nls fails
fit<-nls(Value~a*(exp(-(Height+b)^2/(2*c^2))+(Distance-d)^2/(2*e^2))+g*exp(-abs((-h*Height)^2+(-i*Distance)^2))+f,
         start = list(a=300000,b=200,c=0.003,d=0,e=0.1,f=1100,g=50000,h=0.001,i=0.085),
         algorithm = "plinear")

Error in qr.solve(QR.B, cc) : singular matrix 'a' in solve

# fit with nls2 looks successful
library(nls2)
fit2 <- nls2(Value~a*(exp(-(Height+b)^2/(2*c^2))+(Distance-d)^2/(2*e^2))+g*exp(-abs((-h*Height)^2+(-i*Distance)^2))+f,
          start = list(a=300000,b=200,c=0.003,d=0,e=0.1,f=1100,g=50000,h=0.001,i=0.085),
          algorithm = "brute-force")

fit2
Nonlinear regression model
model: Value ~ a * (exp(-(Height + b)^2/(2 * c^2)) + (Distance - d)^2/(2 *     e^2)) + g * exp(-abs((-h * Height)^2 + (-i * Distance)^2)) +     f
data: NULL
a       b       c       d       e       f       g       h       i 
3.0e+05 2.0e+02 3.0e-03 0.0e+00 1.0e-01 1.1e+03 5.0e+04 1.0e-03 8.5e-02 
residual sum-of-squares: 1.045e+21

Number of iterations to convergence: 9 
Achieved convergence tolerance: NA

# but still there is an issue
summary(fit2)
Error in chol2inv(object$m$Rmat()) : 
  element (8, 8) is zero, so the inverse cannot be computed