Name: Reg. No.: Lab Exercise:: Shivam Batra 19BPS1131
Name: Reg. No.: Lab Exercise:: Shivam Batra 19BPS1131
Methods:
Store Airpassengers dataset (inbuilt dataset available in ‘R’) in a dataframe named “data”,
install packages such as ‘forecast’, ‘tseries’. Perform the following
(ii) Display the statistical info of the dataset such as min, max, 1st quartile, 3rd quartile,
mean and median.
library(forecast)
data<-AirPassengers
data
## Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
## 1949 112 118 132 129 121 135 148 148 136 119 104 118
## 1950 115 126 141 135 125 149 170 170 158 133 114 140
## 1951 145 150 178 163 172 178 199 199 184 162 146 166
## 1952 171 180 193 181 183 218 230 242 209 191 172 194
## 1953 196 196 236 235 229 243 264 272 237 211 180 201
## 1954 204 188 235 227 234 264 302 293 259 229 203 229
## 1955 242 233 267 269 270 315 364 347 312 274 237 278
## 1956 284 277 317 313 318 374 413 405 355 306 271 306
## 1957 315 301 356 348 355 422 465 467 404 347 305 336
## 1958 340 318 362 348 363 435 491 505 404 359 310 337
## 1959 360 342 406 396 420 472 548 559 463 407 362 405
## 1960 417 391 419 461 472 535 622 606 508 461 390 432
sum(is.na(data))
## [1] 0
dMax<-max(data)
print(paste("Max = ",dMax))
dMed<-median(data)
print(paste("Median = ",dMed))
quan<-quantile(data)
print("Quartiles are = ")
quan
3. Plot data
plot(data,xlab="Date", ylab = "Passenger numbers (1000's)",main="Air
Passenger numbers from 1949 to 1961")
4. Plot as timeseries ‘data’ (monthwise)
boxplot(data~cycle(data),xlab="Date", ylab = "Passenger Numbers
(1000's)" ,main ="Monthly Air Passengers Boxplot from 1949 to 1961")
6. & 7. Plot ddata and also plot the following: trend, seasonal
and random.
autoplot(ddata)
8. Perform ADF test for stationarity.
adf.test(data)
##
## Augmented Dickey-Fuller Test
##
## data: data
## Dickey-Fuller = -7.3186, Lag order = 5, p-value = 0.01
## alternative hypothesis: stationary
autoplot(acf(data,plot=FALSE))
Review random time series for any missing values
ddata$random
Autoplot the random time series from 7:138 which exclude the NA values
autoplot(acf(ddata$random[7:138],plot=FALSE))
## Series: data
## ARIMA(2,1,1)(0,1,0)[12]
##
## Coefficients:
## ar1 ar2 ma1
## 0.5960 0.2143 -0.9819
## s.e. 0.0888 0.0880 0.0292
##
## sigma^2 = 132.3: log likelihood = -504.92
## AIC=1017.85 AICc=1018.17 BIC=1029.35
library(ggfortify)
ggtsdiag(fitData)