Jie
Jie

Reputation: 131

nls function in R how to deal with the selection of parameters

I'm dealing with the adstock model and try to find the best alpha in the formula of adstock_t=ad_t+alpha*adstock_t-1. I found the following relevant code in R to solve this question: enter image description here

Here, for the modeling, the guy used nls function, I have several questions about it: first, it seems that the function sales~b0+bi*adstock is a linear function why we use the nonlinear fitting model nls here. secondly, I'm wondering how the model choose the best b0,b1 and alpha(rate here). We only specify the start point of each parameter, how does the model go through all possible value and choose the best ones? Is there upper bound for the range of parameters? Does it choose the best parameters based on R square(minimize SSR)? But in our course, the instructor mentioned that we estimate the best rate using maximize likelihood, which makes me confused because the nls uses least square rule. Is that inconsistent?

Thanks for any help!

Jie

Upvotes: 0

Views: 476

Answers (1)

G. Grothendieck
G. Grothendieck

Reputation: 270055

If rate were fixed then sales would be a linear function of b0 and b1 and we could solve it using lm but rate is not fixed. It is true that algorithm="plinear" could be used in this case in which case only a starting value for the nonlinear parameter rate would have to be specified, starting values for linear parameters can be omitted with that algorithm. Note that the formula required for "plinear" is not the same as for the other algorithms. Here is an example of using plinear -- searching SO for plinear will find other examples.

nls does not try all possible values. The method it uses is specified by the algorithm= argument and if nothing is specified it uses Gauss-Newton by default. It starts at some specified starting value and then moves a small amount downhill and repeats. Exactly how that is done depends on the specific algorithm chosen. See ?nls for details on the arguments and references.

Note

When posting to SO do not use images but rather include a complete reproducible example including all inputs that others can copy and paste into their session to run.

Upvotes: 0

Related Questions