简体   繁体   English

非线性建模起始值

[英]Nonlinear modelling starting values

I have a huge time series datasets involving many loops. 我有一个庞大的时间序列数据集,涉及多个循环。 But, the model couldn't be converged. 但是,该模型无法收敛。 My model is given as follows.. 我的模型如下。

Model <- nls(Y~b+m*X^D+Z, start = list(b=0.5,m=0.5, D=1),data=logar)

I just want a clear cut determination of starting value of nonlinear modelling! 我只想清楚地确定非线性建模的起始值!

Data(logar)

X         Y                  Z
135      -0.171292376      85  
91      0.273954718        54   
171     -0.288513438       107
88       -0.17363066       54
59     -1.770852012        50
1        0                 37
1       0                  32
1       0.301029996        36
2       -0.301029996       39
1       1.041392685        30
11      -0.087150176       42
9        0.577236408       20
34       -0.355387658      28
15        0.329058719      17
32        -0.182930683     24
21        0.196294645      21
33        0.114954516      91
43       -0.042403849      111
39       -0.290034611       88
20       -0.522878746       76
6        -0.301029995       108
3         0.477121254       78
9          0                63
9          0.492915522      51
28       -0.243038048       88
16        -0.028028724      17
15      -0.875061263        29
2       -0.301029996        44
1        0                  52
1        1.531478917        65

Here is a rough guide based on what I would do. 这是根据我的意愿编写的粗略指南。

  1. Choosing starting values for parameters m and b . 为参数mb选择起始值。

    You can narrow down starting parameters by plugging in values X, Y, Z from a few observations into your model; 您可以通过将一些观察中的值X, Y, Z插入模型来缩小起始参数的范围。 for example, take the measurement with Y=0 , X=1 and Z=37 , leading to 0 = b + m + 37 , or b = -37 - m . 例如,使用Y=0X=1Z=37进行测量,得出0 = b + m + 37b = -37 - m

  2. Choosing starting value for parameter D . 为参数D选择起始值。

    As suggested by @jogo, plotting (Y - Z) as a function of X will give you a good idea about a sensible starting parameter for D . 正如@jogo所建议的那样,将(Y - Z)绘制为X的函数将使您对D的合理起始参数有个好主意。 In this case, a linear dependence D = 1 seems to be a good initial guess. 在这种情况下,线性相关性D = 1似乎是一个很好的初始猜测。

     plot((Y - Z) ~ X, data = logar) 

    在此处输入图片说明

If we now modify the starting parameters accordingly, nlm reaches convergence 如果现在我们相应地修改起始参数,则nlm达到收敛

fit <- nls(Y ~ b + m * X ^ D + Z, start = list(b = -37 - 0.5, m = 0.5, D = 1), data = logar)
fit
#Nonlinear regression model
#  model: Y ~ b + m * X^D + Z
#   data: df
#       b        m        D
#-46.1134  -0.2118   1.0704
# residual sum-of-squares: 19846
#
#Number of iterations to convergence: 7
#Achieved convergence tolerance: 3.761e-06

We can write the model as: 我们可以将模型编写为:

Y - Z ~ b + m * X^D

With algorithm="plinear" only the nonlinear parameters, in this case only D , need starting values and the starting value may not be particularly critical. 使用algorithm="plinear"仅非线性参数(在这种情况下仅是D )需要起始值,并且起始值可能不是特别关键。 (For example, at least in this case if we use a starting value of -1 instead of 1 then a few more iterations are needed but we get the same answer.) Note that with the plinear algorithm the right hand side should be specified as a matrix whose columns are implicitly multiplied by the linear parameters. (例如,至少在这种情况下,如果我们使用-1而不是1作为起始值,则需要进行几次迭代,但得到的答案是相同的。)请注意,对于plinear算法,应将右侧指定为一个矩阵,其列隐式乘以线性参数。

o <- order(logar$X)
fit.nls <- nls(Y - Z ~ cbind(1, X^D), logar[o, ], start = list(D = 1),
  algorithm = "plinear")

which converges to the following in 6 iterations: 通过6次迭代收敛到以下内容:

> fit.nls
Nonlinear regression model
  model: Y - Z ~ cbind(1, X^D)
   data: logar[o, ]
       D    .lin1    .lin2 
  1.0703 -46.1135  -0.2118 
 residual sum-of-squares: 19846

Number of iterations to convergence: 6 
Achieved convergence tolerance: 8.814e-06

Given that D is so close to 1 you may wish to simplify the model to just: 鉴于D非常接近1,您可能希望将模型简化为:

fit.lm <- lm(Y - Z ~ X, logar)

Visually these model fits seem indistinguishable: 在视觉上,这些模型拟合似乎无法区分:

plot(Y-Z ~ X, logar)
lines(fitted(fit.nls) ~ X, logar[o, ], col = "red", lty = 2)
abline(fit.lm, col = "blue", lty = 3)

截图

Note 注意

The input in reproducible form is: 可复制形式的输入为:

logar <- structure(list(X = c(135L, 91L, 171L, 88L, 59L, 1L, 1L, 1L, 2L, 
1L, 11L, 9L, 34L, 15L, 32L, 21L, 33L, 43L, 39L, 20L, 6L, 3L, 
9L, 9L, 28L, 16L, 15L, 2L, 1L, 1L), Y = c(-0.171292376, 0.273954718, 
-0.288513438, -0.17363066, -1.770852012, 0, 0, 0.301029996, -0.301029996, 
1.041392685, -0.087150176, 0.577236408, -0.355387658, 0.329058719, 
-0.182930683, 0.196294645, 0.114954516, -0.042403849, -0.290034611, 
-0.522878746, -0.301029995, 0.477121254, 0, 0.492915522, -0.243038048, 
-0.028028724, -0.875061263, -0.301029996, 0, 1.531478917), Z = c(85L, 
54L, 107L, 54L, 50L, 37L, 32L, 36L, 39L, 30L, 42L, 20L, 28L, 
17L, 24L, 21L, 91L, 111L, 88L, 76L, 108L, 78L, 63L, 51L, 88L, 
17L, 29L, 44L, 52L, 65L)), class = "data.frame", row.names = c(NA, 
-30L))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何找到适合非线性数据的起始值? - How do I find starting values to fit nonlinear data? 如何找到非线性 model 的起始值? - How do I find the starting values for a nonlinear model? 具有自启动函数和 purrr 的非线性混合效应模型 - Nonlinear mixed effect models with self-starting function and purrr 绘制新值以最佳拟合非线性曲线 - plot new values for best fit nonlinear curve R中联立非线性方程的根值 - root values of simultaneous nonlinear equations in R ggplot2:为alpha设置(非线性)值 - ggplot2: set (nonlinear) values for alpha 非线性优化问题中的错误:“ x”中的值无穷或缺失 - Error in nonlinear optimization problem : infinite or missing values in 'x' 创建线性或非线性模型的(分组)摘要以连接到表并预测值 - Creating a (grouped) summary of linear or nonlinear models to join to a table and predict values 如何用一系列值的常数求解 R 中的非线性方程? - How to solve a nonlinear equation in R with a constant of a list of values? 如何在 geom_smooth()(来自 ggplot2 包)中为多重非线性回归分配不同的初始值? - How to assign different initial values inside geom_smooth() (from the ggplot2 package) for multiple nonlinear regressions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM