Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nonlinear multiple regression in R

I'm trying to run a nonlinear multiple regression in R with a dataset, it has thousands of rows so I'll 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 please explain to me in very simple terms how to run a nonliner multiple regression using Header.1 and Header.2 as independent variables and Header.7 as the dependent variable? I successfully ran a linear multiple regression using lm(), but when I tried to use nls(), I got the following error message:

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

If you need more information in order to be able to run the regression let me know. Thanks.

like image 487
japem Avatar asked Dec 21 '13 15:12

japem


1 Answers

In order to use nls, you need to specify both a formula and start values for the variables. So the first thing to do is decide what kind of nonlinear formula you want to try and fit.

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 an ordinary linear regression, because the model you are fitting is linear. There is no "default" non-linear regression, so you need to figure out what kind of non-linear model you want to fit. See ?nls for details.

like image 179
mrip Avatar answered Sep 29 '22 01:09

mrip