1
N   x1  x2  x3      x4  x5      y
1   8   7.0 -148    26  0.54    3768
2   12  4.4 -148    28  0.99    2957
3   12  6.6 -130    26  0.58    3772
4   5   3.0 -73     33  0.49    1134
5   7   6.0 -115    42  0.32    2691
6   13  5.8 -53     26  0.52    2613
7   9   6.2 -64     32  0.86    2425
8   7   5.7 -76     43  0.72    2108
9   15  4.0 -84     33  0.63    2639
10  8   5.1 -68     40  0.34    1846
11  10  5.5 -90     30  0.79    2465
12  13  6.0 -51     26  0.24    2696
13  14  4.0 -95     41  0.63    2592
14  14  4.9 -85     39  0.79    2748
15  15  3.2 -100    28  0.61    2656
16  10  6.7 -51     40  0.29    2715
17  15  5.7 -113    26  0.72    3559
18  5   5.1 -135    29  0.51    2341
19  8   6.8 -106    35  0.22    3169
20  13  3.9 -68     37  0.76    2106
21  10  4.9 -129    26  0.93    2646
22  7   4.1 -55     40  0.58    1294
23  7   6.9 -86     38  0.31    2932
24  11  6.7 -85     38  0.44    3214
25  14  4.7 -133    31  0.30    3203
26  9   5.7 -128    25  0.74    2859
27  7   3.1 -111    33  0.61    1709
28  6   4.1 -51     34  0.52    1168
29  9   3.4 -124    27  0.38    2088
30  9   4.0 -118    28  0.29    2146

So I have the above dataset and what I am trying to do is perform exponential multivariable regression in the form of a*x^b. I've tried using the nls function on r with no luck. Does anyone have any tips on how to do this. Basically the final form of the equation should be y = a1*x1^b1 + a2*x2^b2 + a3*x3^b3 + a4*x4^b4 + a5*x5^b5. I need to solve for the a1,b1,a2,b2,a3,b3,a4,b4,a5,b5 variables.

Mateusz1981
  • 1,817
  • 17
  • 33
  • so you need a `nls` with the starting values for all the parameters ex `start = c(a1 = ..., a2 = ...)`. It could be hard to fine starting values to solve the equation and I do not know if this function is a proper one as I have never seen equation with so many parameters – Mateusz1981 Jan 18 '17 at 07:03
  • x3 has negative values and you can't raise a negative noninteger value to a power. – G. Grothendieck Jan 19 '17 at 19:54

1 Answers1

0

The example with parameters just for x1 and x2 is as follow

det <- read.table(header = T, stringsAsFactors = F,  text = "N   x1  x2  x3      x4  x5      y
1   8   7.0 -148    26  0.54    3768
2   12  4.4 -148    28  0.99    2957
3   12  6.6 -130    26  0.58    3772
4   5   3.0 -73     33  0.49    1134
5   7   6.0 -115    42  0.32    2691
6   13  5.8 -53     26  0.52    2613
7   9   6.2 -64     32  0.86    2425
8   7   5.7 -76     43  0.72    2108
9   15  4.0 -84     33  0.63    2639
10  8   5.1 -68     40  0.34    1846
11  10  5.5 -90     30  0.79    2465
12  13  6.0 -51     26  0.24    2696
13  14  4.0 -95     41  0.63    2592
14  14  4.9 -85     39  0.79    2748
15  15  3.2 -100    28  0.61    2656
16  10  6.7 -51     40  0.29    2715
17  15  5.7 -113    26  0.72    3559
18  5   5.1 -135    29  0.51    2341
19  8   6.8 -106    35  0.22    3169
20  13  3.9 -68     37  0.76    2106
21  10  4.9 -129    26  0.93    2646
22  7   4.1 -55     40  0.58    1294
23  7   6.9 -86     38  0.31    2932
24  11  6.7 -85     38  0.44    3214
25  14  4.7 -133    31  0.30    3203
26  9   5.7 -128    25  0.74    2859
27  7   3.1 -111    33  0.61    1709
28  6   4.1 -51     34  0.52    1168
29  9   3.4 -124    27  0.38    2088
30  9   4.0 -118    28  0.29    2146")

You can use `optim` function `?optim` I give an example for `x1` and `x2`

Firstly you create an optimization function that reduce SS of your model i.e. par[1]*x1^par[2] + par[3]*x2^par[4] - y ( you can add parameters for x3, x4 ect.

min.RSS_2 <- function(data, par){
  with(data, sum((par[1]*x1^par[2] + par[3]*x2^par[4] - y)^2))

}

and than you run optim function with starting values

result <- optim(par = c(0, 1, 0.1, 0.2), min.RSS_2, data = det)

new values are calculated

result$par
$par
[1]  973.4197484    0.4210558  250.6697196 -645.7000012

You can visualise this on the figure

plot(y ~ x1, data = det, main="Least square regression")
curve(result$par[1]*x^result$par[2] + result$par[3] * 7^result$par[4], 6 , 14, col = "red", add = T)
Mateusz1981
  • 1,817
  • 17
  • 33
  • How would I figure out the starting values with 5, so a1*x1^b1+a2*x2^b2 etc. – brownmamba71 Jan 18 '17 at 07:19
  • I do it by tries and errors and recognision of how the function behave – Mateusz1981 Jan 18 '17 at 07:22
  • I tried using logs for finding the start values but still have no luck, am consistently getting "Missing value or an infinity produced when evaluating model" – brownmamba71 Jan 18 '17 at 20:53
  • It means that the starting values are wrong. As I wrote I doubt that you will find the starting values for such complicated model. The best solution is to find out the response of your dependent variable and try different functions that have been proposed in the literature and then fit the model. See here http://stats.stackexchange.com/questions/63226/non-linear-modelling-with-several-variables-including-a-categorical-variable – Mateusz1981 Jan 19 '17 at 06:46
  • If the answer was of any help for you, acknowledge please – Mateusz1981 Jan 24 '17 at 09:53