There is no problem with this adjustment or code. See what happens when I change the initial kick to 0.9
:
y=c(1.1178329,1.0871448,1.0897010,1.0759255,1.0535190,0.8725332)
x=c(6,5,4,3,2,1)
library(minpack.lm)
mod1 <- nlsLM( y ~ x^(-p),
start = list(p = 0.9) ,
trace = TRUE, lower=0.1, upper=1)
It. 0, RSS = 2.99354, Par. = 0.9
It. 1, RSS = 0.246237, Par. = 0.1
It. 2, RSS = 0.246237, Par. = 0.1
More iterations occur as expected. If I keep the initial fixed value and reduce the lower bound of the search grid to 0.00001
, see what happens:
mod2 <- nlsLM( y ~ x^(-p),
start = list(p = 0.1) ,
trace = TRUE, lower=0.00001, upper=1)
It. 0, RSS = 0.246237, Par. = 0.1
It. 1, RSS = 0.0544138, Par. = 1e-05
It. 2, RSS = 0.0544138, Par. = 1e-05
Apparently, the ideal value of p
for this data set is quite close to 0. Note that including the RSS value (Residual Sum of Squares) reduces of mod1
for mod2
, indicating that the second adjustment was better than the first.
In short, there’s nothing wrong with the code. It’s just converging too fast.
It may also be that the value of p
is not positive. It may be that the value of p
which best fits the data does not belong to the range determined by your initial fit, which is between 0.1 and 1. If this is true, the value of p
will converge to something at the boundary of the interval defined in the function call. You came to think of this hypothesis?
See the code below, for example:
mod3 <- nlsLM( y ~ x^(-p),
start = list(p = 0.1) ,
trace = TRUE, lower=-1, upper=1)
It. 0, RSS = 0.246237, Par. = 0.1
It. 1, RSS = 0.0218977, Par. = -0.0816128
It. 2, RSS = 0.0166599, Par. = -0.0607616
It. 3, RSS = 0.0166587, Par. = -0.0604426
It. 4, RSS = 0.0166587, Par. = -0.0604428
mod3
resulted in the lowest RSS of all. Even, it has more expensive of adjustment, because it took longer to arrive in a response, with more interactions and a smoother convergence in the value of the parameter.
You have to pull the regression intercept:
fit <- lm(log(y) ~ 0 + log(x))
, then I think it is equivalent. I think you have to be careful with the hypothesis tests as well. That p-value is not valid when you do it this way.– Daniel Falbel
@Danielfalbel Certo regarding the interception of regression, sorry for the rush. I will edit the answer with this modification. As for p-value, I do not agree. The only thing that matters is whether or not the coefficient is significant, the p-value can and should vary.
– Rui Barradas
Yes, but it assumes that log(y) has normal distribution that may not be the goal!
– Daniel Falbel
@Danielfalbel In the linear model, what is assumed to have normal distribution are the residues, not the answer. Of course it will be necessary to see the waste, with, for example, a histogram.
– Rui Barradas
is equivalent to the response or the residuals... if y = a + bx + e, with and normal(0, sigma) then y ~normal(a + bx, sigma)...
– Daniel Falbel
@Danielfalbel Graphically I see no problem with the linear model. There is an outlier and nothing else. I will edit the answer again, with the graphical instructions.
– Rui Barradas