Nonlinear Multiple Regression in R

I'm trying to run non-linear multiple regression in R with a dataset, it has thousands of rows, so I just put the first few here:

Header.1 Header.2 Header.3 Header.4 Header.5 Header.6 Header.7 1 -60 -45 615 720 1.8318 0.428 -11.614 2 -59 -45 616 720 1.8322 0.429 -11.498 3 -58 -45 617 720 1.8326 0.430 -11.383 4 -57 -45 618 720 1.8330 0.430 -11.267 5 -56 -45 619 720 1.8334 0.431 -11.152 6 -55 -45 620 720 1.8338 0.432 -11.036 7 -54 -45 621 720 1.8342 0.433 -10.921 8 -53 -45 622 720 1.8346 0.433 -10.806 9 -52 -45 623 720 1.8350 0.434 -10.691 10 -51 -45 624 720 1.8354 0.435 -10.576 11 -50 -45 625 720 1.8357 0.435 -10.461 12 -49 -45 626 720 1.8361 0.436 -10.347 13 -48 -45 627 720 1.8365 0.437 -10.232 14 -47 -45 628 720 1.8369 0.438 -10.118 15 -46 -45 629 720 1.8373 0.438 -10.003 16 -45 -45 630 720 1.8377 0.439 -9.889 17 -44 -45 631 720 1.8381 0.440 -9.775 18 -43 -45 632 720 1.8385 0.440 -9.660 19 -42 -45 633 720 1.8389 0.441 -9.546 20 -41 -45 634 720 1.8393 0.442 -9.432 21 -40 -45 635 720 1.8397 0.442 -9.318 22 -39 -45 636 720 1.8400 0.443 -9.205 23 -38 -45 637 720 1.8404 0.444 -9.091 24 -37 -45 638 720 1.8408 0.445 -8.977 25 -36 -45 639 720 1.8412 0.445 -8.864 26 -35 -45 640 720 1.8416 0.446 -8.751 27 -34 -45 641 720 1.8420 0.447 -8.637 28 -33 -45 642 720 1.8424 0.447 -8.524 

Can someone explain to me very simply how to run multiple nonliner regression using Header.1 and Header.2 as independent variables, and Header.7 as a dependent variable? I successfully performed linear multiple regression using lm (), but when I tried using nls (), I got the folloiwng error message:

Error in getInitial.default (func, data, mCall = as.list (match.call (func ,: the getInitial method was not found for the "function" objects

If you need more information to be able to trigger a regression, let me know. Thanks.

+6
source share
2 answers

To use nls , you need to specify both the formula and the initial values ​​for the variables. So, the first thing to do is decide which non-linear formula you want to try.

For example, if you do this:

 m2<-nls(Header.7 ~ Header.1*a + Header.2*b + c,data=data,start=c(a=0,b=0,c=0)) 

then you will get (approximately) the same result as regular linear regression, because the model you are installing is linear. There is no default nonlinear regression, so you need to figure out which nonlinear model you want to fit. See ?nls more details.

+6
source

So, in a linear model, parameters are set implicitly:

 fit <- lm(Header.7 ~ Header.1 + Header.2, data=...) 

corresponds to the model:

 Header.7 = a * Header.1 + b * Header.2 + c 

In a non-linear model, you must explicitly specify the parameters, as @mrip shows. Of course, in a nonlinear model, the model formula can be arbitrarily complex:

 fit <- nls(Header.7 ~ exp(a*Header.1 + b/Header.2), data=..., start=c(...)) 

Finally, a run is optional: nls (...) will make an assumption. But there is no guarantee that the model converges to significant parameter values ​​or even converges at all.

+3
source

All Articles