I have an array with dates as indices which I’m plotting. I’d like to plot a LOESS curve along with it. However, the input for loess is a formula. Is there a good way to define a formula from array index to value which I can then give to the loess function?
Share
Check out the help page for
loess()– it has a couple of examples of specifying the formula. Basically, you need to put your data into adata.frameobject with variables given appropriate names, then the formula will bey ~ x, wherexandyare the names of the variables you want on the x- and y-axis, respectively.I prefer the function
lowess(), which is a faster, simpler alternative. It has fewer adjustable parameters thanloess()but it just as good in many applications.Here are some links describing the differences between the two functions.
Below is a simple example for both
loess()andlowess()