Stackuser
Stackuser

Reputation: 59

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

Upvotes: 0

Views: 240

Answers (2)

G. Grothendieck
G. Grothendieck

Reputation: 269664

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. (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.

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:

> 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:

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)

screenshot

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))

Upvotes: 1

Maurits Evers
Maurits Evers

Reputation: 50678

Here is a rough guide based on what I would do.

  1. Choosing starting values for parameters m and b.

    You can narrow down starting parameters by plugging in values X, Y, Z from a few observations into your model; for example, take the measurement with Y=0, X=1 and Z=37, leading to 0 = b + m + 37, or b = -37 - m.

  2. Choosing starting value for parameter 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. In this case, a linear dependence D = 1 seems to be a good initial guess.

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

    enter image description here

If we now modify the starting parameters accordingly, nlm reaches convergence

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

Upvotes: 2

Related Questions