library(smooth)
## Warning: package 'smooth' was built under R version 4.0.2
## Loading required package: greybox
## Warning: package 'greybox' was built under R version 4.0.2
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## Package "greybox", v0.6.0 loaded.
## This is package "smooth", v2.6.0
Importing dataset “Global Temperatures”, attaching it and reading the names of columns present in it.
globaltemp=read.csv(file = "C://temp//GlobalTemperatures.csv", header = TRUE)
attach(globaltemp)
names(globaltemp)
## [1] "dt"
## [2] "LandAverageTemperature"
## [3] "LandAverageTemperatureUncertainty"
## [4] "LandMaxTemperature"
## [5] "LandMaxTemperatureUncertainty"
## [6] "LandMinTemperature"
## [7] "LandMinTemperatureUncertainty"
## [8] "LandAndOceanAverageTemperature"
## [9] "LandAndOceanAverageTemperatureUncertainty"
Removing all columns showing “uncertainty” as well as “landmintemperature” as we do not intend to use them in our analysis.
globaltemp=subset(globaltemp, select = -c(LandAndOceanAverageTemperatureUncertainty, LandAverageTemperatureUncertainty, LandMaxTemperatureUncertainty, LandMinTemperatureUncertainty, LandMinTemperature))
Reading names of remaining columns.
names(globaltemp)
## [1] "dt" "LandAverageTemperature"
## [3] "LandMaxTemperature" "LandAndOceanAverageTemperature"
Creating time-series objects for the 3 types of temperature readings.
tslandavg=ts(data = LandAverageTemperature, start = c(1850, 1), end = c(2015,12), frequency = 12)
tslandmax=ts(data = LandMaxTemperature, start = c(1850, 1), end = c(2015,12), frequency = 12)
tslandoceanavg=ts(data = LandAndOceanAverageTemperature, start = c(1850, 1), end = c(2015,12), frequency = 12)
Plotting timeseries objects.
plot(tslandavg)
plot(tslandmax)
plot(tslandoceanavg)
We see an overall positive trend for all 3 quantities. However, to be able to comment any further, we need to break down each time-series into 3 components - trend, seasonality, and residual.
plot(decompose(tslandavg))
plot(decompose(tslandmax))
plot(decompose(tslandoceanavg))
Above graphs shows a positive trend for all 3 quantities. We also see the presence of a seasonal variation where each block repeats itself every ~20 years. Random variation is seen for all as well.
10-year moving average on Land and Ocean Average Temperature
sma(tslandoceanavg, order = 10)
## Time elapsed: 0.03 seconds
## Model estimated: SMA(10)
## Initial values were produced using backcasting.
##
## Loss function type: MSE; Loss function value: 2.1596
## Error standard deviation: 1.4703
## Sample size: 1992
## Number of estimated parameters: 2
## Number of degrees of freedom: 1990
## Information criteria:
## AIC AICc BIC BICc
## 7190.693 7190.699 7201.887 7201.910