使用R的非线性回归

时间:2017-04-27 04:10:56

标签: r

我是R的新手,我正在尝试以下面的格式构建非线性相关。我在R中尝试了一个脚本,但它无法工作并返回错误消息“初始参数估计时的奇异梯度矩阵”。有人可以帮助我使用正确的脚本输入R,以便根据新的数据集估计更新的相关系数吗?数据集由3个变量Z,X和Y组成。我想估计Z = f(x,y)。 谢谢

等式

z=a+bx+cy+dx^2+ey^2+fxy+gx^3+hy^3+ixy^2+jx^2y  

a   0.065119008
b   -0.002506607
c   0.004586821
d   3.73635E-05
e   8.41116E-07
f   -1.7902E-05
g   -1.28967E-07
h   -1.04123E-10
i   -2.40641E-09
j   4.42138E-08

X   |       Y   |       Z
_______ |       _______ |       _______
60  |       100 |       0.41994
60  |       200 |       0.79807
60  |       300 |       1.18778
60  |       400 |       1.58945
60  |       500 |       2.00336
60  |       600 |       2.42971
60  |       700 |       2.86858
60  |       800 |       3.31989
60  |       900 |       3.78335
60  |       1000    |       4.25842
60  |       1100    |       4.74429
60  |       1200    |       5.23983
60  |       1300    |       5.74359
60  |       1400    |       6.25381
60  |       1500    |       6.76844
60  |       1600    |       7.28523
60  |       1700    |       7.80179
60  |       1800    |       8.31574
60  |       1900    |       8.82475
60  |       2000    |       9.32668
80  |       100 |       0.40357
80  |       200 |       0.76552
80  |       300 |       1.13711
80  |       400 |       1.5185
80  |       500 |       1.90979
80  |       600 |       2.311
80  |       700 |       2.72205
80  |       800 |       3.14274
80  |       900 |       3.57269
80  |       1000    |       4.01141
80  |       1100    |       4.45817
80  |       1200    |       4.91207
80  |       1300    |       5.37202
80  |       1400    |       5.83674
80  |       1500    |       6.30477
80  |       1600    |       6.77453
80  |       1700    |       7.24438
80  |       1800    |       7.71262
80  |       1900    |       8.17761
80  |       2000    |       8.63777
100 |       100 |       0.38847
100 |       200 |       0.73573
100 |       300 |       1.09104
100 |       400 |       1.45447
100 |       500 |       1.82598
100 |       600 |       2.20551
100 |       700 |       2.59287
100 |       800 |       2.9878
100 |       900 |       3.38993
100 |       1000    |       3.79877
100 |       1100    |       4.21372
100 |       1200    |       4.63401
100 |       1300    |       5.0588
100 |       1400    |       5.48709
100 |       1500    |       5.91781
100 |       1600    |       6.3498
100 |       1700    |       6.78184
100 |       1800    |       7.21271
100 |       1900    |       7.64119
100 |       2000    |       8.06612
120 |       100 |       0.37451
120 |       200 |       0.70832
120 |       300 |       1.04892
120 |       400 |       1.39627
120 |       500 |       1.7503
120 |       600 |       2.11085
120 |       700 |       2.47771
120 |       800 |       2.85059
120 |       900 |       3.22913
120 |       1000    |       3.61287
120 |       1100    |       4.00129
120 |       1200    |       4.39376
120 |       1300    |       4.78958
120 |       1400    |       5.18797
120 |       1500    |       5.58809
120 |       1600    |       5.98905
120 |       1700    |       6.38994
120 |       1800    |       6.78981
120 |       1900    |       7.18777
120 |       2000    |       7.58291
140 |       100 |       0.36155
140 |       200 |       0.683
140 |       300 |       1.01021
140 |       400 |       1.34307
140 |       500 |       1.68148
140 |       600 |       2.02523
140 |       700 |       2.37411
140 |       800 |       2.72783
140 |       900 |       3.08602
140 |       1000    |       3.4483
140 |       1100    |       3.81418
140 |       1200    |       4.18314
140 |       1300    |       4.55459
140 |       1400    |       4.9279
140 |       1500    |       5.3024
140 |       1600    |       5.67739
140 |       1700    |       6.05216
140 |       1800    |       6.42596
140 |       1900    |       6.7981
140 |       2000    |       7.16787
160 |       100 |       0.34948
160 |       200 |       0.65953
160 |       300 |       0.97447
160 |       400 |       1.29419
160 |       500 |       1.61852
160 |       600 |       1.94728
160 |       700 |       2.28022
160 |       800 |       2.61706
160 |       900 |       2.95748
160 |       1000    |       3.3011
160 |       1100    |       3.64752
160 |       1200    |       3.99628
160 |       1300    |       4.34688
160 |       1400    |       4.6988
160 |       1500    |       5.05149
160 |       1600    |       5.40438
160 |       1700    |       5.7569
160 |       1800    |       6.10847
160 |       1900    |       6.4585
160 |       2000    |       6.80647
180 |       100 |       0.33822
180 |       200 |       0.6377
180 |       300 |       0.94137
180 |       400 |       1.24907
180 |       500 |       1.56064
180 |       600 |       1.87588
180 |       700 |       2.19455
180 |       800 |       2.51639
180 |       900 |       2.84109
180 |       1000    |       3.16833
180 |       1100    |       3.49772
180 |       1200    |       3.82888
180 |       1300    |       4.16138
180 |       1400    |       4.49478
180 |       1500    |       4.82863
180 |       1600    |       5.16245
180 |       1700    |       5.49577
180 |       1800    |       5.82812
180 |       1900    |       6.15903
180 |       2000    |       6.48806
200 |       100 |       0.32767
200 |       200 |       0.61734
200 |       300 |       0.91058
200 |       400 |       1.20725
200 |       500 |       1.50717
200 |       600 |       1.81015
200 |       700 |       2.11596
200 |       800 |       2.42434
200 |       900 |       2.73502
200 |       1000    |       3.04768
200 |       1100    |       3.36202
200 |       1200    |       3.67767
200 |       1300    |       3.99427
200 |       1400    |       4.31145
200 |       1500    |       4.62882
200 |       1600    |       4.94597
200 |       1700    |       5.26253
200 |       1800    |       5.57809
200 |       1900    |       5.89227
200 |       2000    |       6.2047

1 个答案:

答案 0 :(得分:0)

我不完全确定你想做什么,或者为什么谷歌不能令人满意,但也许这些方面的东西会给你一个想法:

x <- rep(c(60,80,100,160,200), each = 10)
y <- c(seq(from = 100, to = 2000, length.out = 25),seq(1800, 200, length.out = 25))
z <- rnorm(50, 6)
df <- data.frame(x,y,z)
mod <- lm(z ~ 1 + x + y + I(x^2) + I(y^2) + I(x*y) + I(x^3) + I(y^3) + I(x*y^2) + I(x*y^3), data =df)
summary(mod)
summary(mod)$adj