#Name: Sweta Kumari #Time series analysis #Read the global temperture file and check the columns name. #1. Read the global temperture file and check the columns name.
GlobalTemperature<-read.csv("C:\\Users\\Sweta\\Documents\\Data\\GlobalTemperatures.csv",header=T)
attach(GlobalTemperature)
names(GlobalTemperature)
## [1] "dt"
## [2] "LandAverageTemperature"
## [3] "LandAverageTemperatureUncertainty"
## [4] "LandMaxTemperature"
## [5] "LandMaxTemperatureUncertainty"
## [6] "LandMinTemperature"
## [7] "LandMinTemperatureUncertainty"
## [8] "LandAndOceanAverageTemperature"
## [9] "LandAndOceanAverageTemperatureUncertainty"
#2. Importing librarries
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.0.2
## -- Attaching packages --------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.1 v purrr 0.3.4
## v tibble 3.0.1 v dplyr 1.0.0
## v tidyr 1.1.1 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.5.0
## Warning: package 'tidyr' was built under R version 4.0.2
## Warning: package 'readr' was built under R version 4.0.2
## Warning: package 'forcats' was built under R version 4.0.2
## -- Conflicts ------------------------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(dplyr)
library(ggplot2)
library(lubridate)
## Warning: package 'lubridate' was built under R version 4.0.2
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(fpp2)
## Warning: package 'fpp2' was built under R version 4.0.2
## Loading required package: forecast
## Warning: package 'forecast' was built under R version 4.0.2
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## Loading required package: fma
## Warning: package 'fma' was built under R version 4.0.2
## Loading required package: expsmooth
## Warning: package 'expsmooth' was built under R version 4.0.2
library(zoo)
## Warning: package 'zoo' was built under R version 4.0.2
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
#3.#To review the changes in the ‘LandAverageTemperature’, we plot the graph of LandAverageTemperature vs time. #Analysis: From the graph, there is no outlier observed in the graph. #The Land Average Temperature is between 0 and 16 for the period of 1850 to 2015. #As the years passed, the average tempertaure of land has increased. #So, Average temperature is not stationary and showing upward trend.
Temperature <- GlobalTemperature %>% mutate(Time_year= year(dt)) %>% filter(Time_year>1849)
Temperature %>% group_by(Time_year) %>% ggplot(aes( x=Time_year,y=LandAverageTemperature,Colour=LandAverageTemperature)) + geom_line()
#4. To review the changes in the ‘LandAndOceanAverageTemperature’, we plot the graph of LandAndOceanAverageTemperature vs time. #Analysis: From the graph, there is no outlier observed in the graph. #The Land and Ocean Average Temperature is between 12 and 18 for the period of 1850 to 2015. #As the years passed, the average tempertaure has increased. #So, Average temperature is not stationary and showing upward trend. #We will check the seasonality with help of moving average method in last section
Temperature %>% group_by(Time_year) %>% ggplot(aes( x=Time_year,y=LandAndOceanAverageTemperature,Colour=LandAndOceanAverageTemperature)) + geom_line()
#5. To review the changes in the ‘LandMaxTemperature’, we plot the graph of LandMaxTemperature vs time. #Analysis: From the graph, there is no outlier observed in the graph. #The Land Maximum Temperature is between 6 and 21 for the period of 1850 to 2015. #As the years passed, the maximum tempertaure of land has increased. #So, Land Max temperature is not stationary and showing upward trend.
Temperature %>% group_by(Time_year) %>% ggplot(aes( x=Time_year,y=LandMaxTemperature,Colour=LandMaxTemperature)) + geom_line()
#6.Running a 10-year moving average on LandAndOceanAverageTemperature. #Analysis: Moving average helped to smooth the graph. Graph is showing strong seasonality with upward trend. #In 1880 and 1950, there is increment in temperature. From 1980, there is continuous increment in the temperature and it has crossed 16 degree in 2015.
LandTemperature <- GlobalTemperature %>% mutate(LandAndOceanAverageTemperature = rollmean(LandAndOceanAverageTemperature, k = 120, fill = NA, align = "right"), Time_year=year(dt))
LandTemperature %>% group_by(Time_year) %>% filter(Time_year>1849) %>% ggplot(aes( x=Time_year,y=LandAndOceanAverageTemperature,Colour=LandAndOceanAverageTemperature)) + geom_line()
## Warning: Removed 119 row(s) containing missing values (geom_path).