Nathan Gilmore
Nathan Gilmore

Reputation: 1

How to add a trendline (exponential) in R?

Okay, so I am working with the daily closings of the Dow Jones Industrial Average (DJIA) index from January 1979 to December 1989. I have successfully plotted the time-evolution of the index, but I am stumped as to how to add a trendline (specifically, exponential). You can get the data here:

http://research.stlouisfed.org/fred2/series/DJIA/downloaddata

I just downloaded it to Excel and then imported it to R as a csv file and plotted it.

In addition to that, how can I add a trendline at a specific place? Say, I wanted a trendline from the year 1985 to 1988?

Upvotes: 0

Views: 1940

Answers (1)

Thomas
Thomas

Reputation: 44525

If that's literally what you want to do (I suspect it isn't), then all you have to do is plot and add a curve with the specified function of x:

plot(y~x)
par(new=TRUE)
curve(0.0629*exp(0.0003*x))

If you actually want to fit a curve based on something you do in R, you'll have to generate some kind of model and then plot fitted values from that using basically the same thing but instead of curve you could use lines.

Upvotes: 1

Related Questions