[R] smoothing or curve-fit a time series using lowess, polynomial or whatever I can get working
Andrew
nodecorum at yahoo.com
Thu Dec 3 02:03:01 CET 2009
I was looking for suggestions as to how to smooth a timeseries and, having accomplished that, how to find the fitted curve values for intermediate points.
I've tried numerous examples of possible approaches in R that I've found on the web, but when applied to my simple data, R returns an error message in numerous cases.
The main problem seems to be that I have monthly data, starting on the 4th month of the first year. So if I create a timeseries with null for the first 3 months, or starting on the 3rd month, R libraries function fail.
I don't care about the quality of the data,I just want to get R working with time series, so I added obviously false values for jan-march of 2008 and I get the same error messages "only univariate series are allowed"
1.0
1.0
1.0
29925.0
60663.0
221873.5
480491.0
231454.5
193697.5
289078.1
446774.9
471155.7
211032.2
214740.9
865103.5
1358822.0
1484117.0
2152747.0
1825709.0
1403461.0
2502712.0
2392353.1
3368193.8
2496529.3
3089231.2
4334911.7
3577551.2
4450100.7
4581147.2
4501380.8
4406765.3
4326864.4
4253378.1
4142437.6
3931249.9
3658728.2
3364516.9
3103204.5
2878541.5
2684296.9
2513390.0
2360164.3
2211494.8
2074479.4
1947117.0
1828018.3
1716195.3
1610921.2
dec=".",)
> myTS<- ts(df, start=c(2008,1), frequency=12)
>
> myTS
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2008 0.0 0.0 0.0 29925.0 60663.0 221873.5 480491.0 231454.5 193697.5 289078.1 446774.9 471155.7
2009 211032.2 214740.9 865103.5 1358822.0 1484117.0 2152747.0 1825709.0 1403461.0 2502712.0 2392353.1 3368193.8 2496529.3
2010 3089231.2 4334911.7 3577551.2 4450100.7 4581147.2 4501380.8 4406765.3 4326864.4 4253378.1 4142437.6 3931249.9 3658728.2
2011 3364516.9 3103204.5 2878541.5 2684296.9 2513390.0 2360164.3 2211494.8 2074479.4 1947117.0 1828018.3 1716195.3 1610921.2
>
>
> library(stats)
>
> stl(log(myTS),s.window="periodic")
Error in stl(log(myTS), s.window = "periodic") :
only univariate series are allowed
>
I don't understand what is wrong with my time series and I certain I'm missing something very basic here --
I'd be very grateful for any suggestions as to how to fit a curve to this data, and then how to find the fitted value of the curve at any arbitrary month within the series (i.e. no extraplolation is needed)
I would not mind using some other method, lm, polynomial fit etc, and am not set on using stl.
I'd be very grateful for any suggestions as to how to fit a curve to this data, and then how to find the fitted value of the curve at any arbitrary month within the series (i.e. no extraplolation is needed)
Warm regards,
Andrew
More information about the R-help
mailing list