We talked about different ways of smoothing a time series data set. Smoothing is beneficial because it can help us see the overall trend a lot better without having to look at all the random noise over time.
Usually smoothing takes the average of a certain range of values around the data point to make the data point better and everything around it more smooth. This makes a drastic from one point to the next less drastic.
There were 5 different methods of smoothing that we talked about: moving averages, moving averages with different weights, Kernel smoothing, Lowess smoothing, and spline smoothing. Here I will do a couple to show what smoothing looks like and how it can help.
The first one is the moving average where the point is found using the average of a certain number of points around it making it less vulnerable to random changes and noise.
library(astsa)
plot(globtemp, type="o", ylab="Global Temperature Deviations")
out <- filter(globtemp, sides=2, filter=rep(1/3,3)) # moving average
par(mfrow=c(2,1))
plot.ts(globtemp, main="unsmoothed temp")
plot.ts(out, main="smoothed temp")
This final plot that is made compares the two plots: one smoothed and one untouched. As we can see the smoothed plot is just that smoother. There arent as many little jumps and randomness, we get a better picture at the trends with out all the distractions that you can see in the other graph.
The other smoothing technique that I really thought was cool was Kernel smoothing. This one basically takes a weighted average where the points closer to our point have a higher weight than those farther away.
k <- ksmooth(time(globtemp), globtemp, kernel = "normal", bandwidth = 2)
plot(globtemp)
lines(k, lwd=2, col=6)
As we can see this one looks a little different but still smooths this time series to looking much better to get overall trend indications as you see in the color compared to the original in black.