Hi all, I have a dataset which consists of 2 columns. I'd like to plot them on a x-y scatter plot and fit an exponential trendline. I'd like R to determine the equation for the trendline and display it on the graph. Since I am new to R (and statistics), any advice on how to achieve this will be greatly appreciated. Many thanks, Chris -- View this message in context: http://n4.nabble.com/R-exponential-regression-tp1009449p1009449.html Sent from the R help mailing list archive at Nabble.com.
Chris, I haven't seen anyone post a reply yet so thought I'd throw in my thoughts. I'm no R expert! When you talk about an exponential trend line are you refering to: 1) y=ax^b or 2) y=ae^(bx) If 1) then take base10 logs of y and x and then fit them with simple linear regression. Then calculate the antilog of the residulas and plot these as your trendline. If 2) then take natural logs of y and x and follow the rest of the procedure described in 1). Hope this helps. Murray M Cooper, Ph.D. Richland Statistics 9800 N 24th St Richland, MI, USA 49083 Mail: richstat at earthlink.net ----- Original Message ----- From: "chrisli1223" <chrisli at austwaterenv.com.au> To: <r-help at r-project.org> Sent: Thursday, January 07, 2010 10:33 PM Subject: [R] R exponential regression> > Hi all, > > I have a dataset which consists of 2 columns. I'd like to plot them on a > x-y > scatter plot and fit an exponential trendline. I'd like R to determine the > equation for the trendline and display it on the graph. > > Since I am new to R (and statistics), any advice on how to achieve this > will > be greatly appreciated. > > Many thanks, > Chris > -- > View this message in context: > http://n4.nabble.com/R-exponential-regression-tp1009449p1009449.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. >
chrisli1223 wrote:> Hi all, > > I have a dataset which consists of 2 columns. I'd like to plot them on a x-y > scatter plot and fit an exponential trendline. I'd like R to determine the > equation for the trendline and display it on the graph.Here's one way: f <- function(x,a,b) {a * exp(b * x)} # generate some data x <- 1:10 set.seed(44) y <- 2*exp(x/4) + rnorm(10)*2 dat <- data.frame(x, y) # plot the data plot(y ~ x) # fit a nonlinear model fm <- nls(y ~ f(x,a,b), data = dat, start = c(a=1, b=1)) # get estimates of a, b co <- coef(fm) # plot the curve curve(f(x, a=co[1], b=co[2]), add = TRUE) -Peter Ehlers> > Since I am new to R (and statistics), any advice on how to achieve this will > be greatly appreciated. > > Many thanks, > Chris-- Peter Ehlers University of Calgary 403.202.3921