How to define initial kicks for nls function for potential regression model?

Asked

Viewed 375 times

3

I would like to know how to define the initial "kicks" to use the power nonlinear regression model. I am working with estimation of data, testing various regression models, even if there is no adjustment, I would like to quote this model, but I have difficulty defining the values initial, below follows only a fragment of data for testing, I would like to know a method that allows me to apply in any data set, for obtaining the initial values of A and B for the function nls(y~B*x^A,start=list(A=1, B=1.7))

dados<-structure(list(y = c(44.42, 77.9, 95.72, 40.24, 63.7, 46.62, 
84.6, 52.49, 88.53, 56.52, 71.21, 65.16, 72.24, 53.81, 67.02), 
    x = c(11.26, 14.78, 17.56, 10.37, 13.27, 10.3, 14.07, 12.26, 
    13.3, 12.84, 13.72, 12.8, 14.86, 11.47, 15.06)), .Names = c("y", 
"x"), row.names = c(NA, -15L), class = "data.frame")

attach(dados)

nls(y~B*x^A,start=list(A=1, B=1.7))

1 answer

3


That answer Cross-Validated seems a good solution.

The suggestion here is to take the log on both sides and adjust a linear model. That would look something like this:

y = b*(x^a)
log(y) = log(b) + a*log(x)

Therefore, by making the linear model you will have an initial estimate for log(b) and to a.

Adjust the linear model:

linear <- lm(log(y) ~ log(x), data = dados)
linear
# Call:
#   lm(formula = log(y) ~ log(x), data = dados)
# 
# Coefficients:
#   (Intercept)       log(x)  
#        0.1371       1.5611  

Thus you will have 0.1371 the estimate of log(b) and 1.5611 estimation of a. A direct estimate of b can be exp(0.1371) = 1.146943. These values can be used as starting kicks.

modelo <- nls(y~B*x^A,start=list(A=coef(linear)[2], B = exp(coef(linear)[1])), data = dados)
modelo

# Nonlinear regression model
# model: y ~ B * x^A
# data: dados
# A     B 
# 1.436 1.598 
# residual sum-of-squares: 1040
# 
# Number of iterations to convergence: 5 
# Achieved convergence tolerance: 3.365e-07

In the link has several other answers that may help!

  • 1

    Excellent answer. Logging on both sides was my idea to linearize the problem and answer it. However, is this question not beyond the scope of the site? I looked for questions on meta and it seems to me that there is no consensus among users as to what to do in cases like this. Personally, I think you were right to answer, but there’s no risk of anyone coming here and closing the question?

  • 1

    @Marcusnunes Thanks! For me this question is on the frontier of "inside" and "outside" the scope... There is a risk of someone closing, but as it is at the border, you will find it difficult to get the 5 votes needed. The answer from Carlos reflects well my opinion. I mean, I just don’t answer if the question has nothing to do with programming. Here the problem of AP is more: I want to run nls and I can not pq the convergence problem, how to correct?. The way I see it, he didn’t come to me for help in statistics.

  • I will take this into account in my next responses. I need to learn to answer what is asked and not go too far in statistical theory on this site.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.