[R] Fitting exponential curve to data points
andrew.clegg at gmail.com
Tue Jul 24 03:09:06 CEST 2007
I've looked through the list archives and online resources, but I
haven't really found an answer to this -- it's pretty basic, but I'm
(very much) not a statistician, and I just want to check that my
solution is statistically sound.
Basically, I have a data file containing two columns of data, call it data.tsv:
These look exponential to me, so what I want to do is plot these
points on a graph with linear axes, and add an exponential curve over
the top. I also want to give an R-squared for the fit.
The way I did it was like so:
# Read in the data, make a copy of it, and take logs
data = read.table("data.tsv", header=TRUE)
log.data = data
log.data$count = log(log.data$count)
# Fit a model to the logs of the data
model = lm(log.data$count ~ year, data = log.data)
# Plot the original data points on a graph
# Draw in the exponents of the model's output
Is this the right way to do it? log-ing the data and then exp-ing the
results seems like a bit of a long-winded way to achieve the desired
effect. Is the R-squared given by summary(model) a valid measurement
of the fit of the points to an exponential curve, and should I use
multiple R-squared or adjusted R-squared?
The R-squared I get from this method (0.98 multiple) seems a little
high going by the deviation of the last data point from the curve --
you'll see what I mean if you try it.
Thanks in advance for any help!
More information about the R-help