[R] R exponential regression

PIKAL Petr petr.pikal at precheza.cz
Thu Nov 15 13:26:14 CET 2012


Hi

your model
f <- function(x,a,b) {a * I(x^b)}

can be expressed as

log(a)+b*log(x)

and for that it shall result in straight line and you can use lm for estimate of b and log(a)

It is also better to use 1:33 instead of 1980:2012

Based on values you get from linear realation you can set sensible starting values.

> fm <- nls(y~a*z^b, data=test, start=c(a=0.2,b=2))
> summary(fm)

Formula: y ~ a * z^b

Parameters:
  Estimate Std. Error t value Pr(>|t|)    
a  0.13391    0.01848   7.248 3.74e-08 ***
b  2.22563    0.04140  53.763  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Residual standard error: 6.239 on 31 degrees of freedom

Number of iterations to convergence: 6 
Achieved convergence tolerance: 7.673e-07 

Regards
Petr


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of muzammil786
> Sent: Wednesday, November 14, 2012 12:12 PM
> To: r-help at r-project.org
> Subject: Re: [R] R exponential regression
> 
> I am having a similar problem on this data (given below). I have tried
> several starting values for a and b, but it is consistently giving me:
> 
> fm <- nls(y~f(x,a,b), data.frame(x,y), start=c(a=1,b=1)) Error in
> numericDeriv(form[[3L]], names(ind), env) :
>   Missing value or an infinity produced when evaluating the model
> 
> The function f(x,a,b) is defined here:
> f <- function(x,a,b) {a * I(x^b)}
> 
> The data is given here:
> 
>       x   y
> 1  1980   1
> 2  1981   1
> 3  1982   1
> 4  1983   3
> 5  1984   3
> 6  1985   5
> 7  1986   8
> 8  1987   8
> 9  1988   9
> 10 1989  12
> 11 1990  15
> 12 1991  24
> 13 1992  33
> 14 1993  44
> 15 1994  62
> 16 1995  68
> 17 1996  81
> 18 1997  87
> 19 1998 102
> 20 1999 114
> 21 2000 123
> 22 2001 135
> 23 2002 144
> 24 2003 158
> 25 2004 172
> 26 2005 188
> 27 2006 197
> 28 2007 224
> 29 2008 234
> 30 2009 254
> 31 2010 278
> 32 2011 312
> 33 2012 317
> 
> I shall be grateful if you could guide me what's wrong here.
> 
> Cheers.
> Muzammil
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/R-
> exponential-regression-tp1009449p4649474.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list