library(timeSeries)
## Loading required package: timeDate
library(forecast)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following object is masked from 'package:timeSeries':
##
## time<-
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## This is forecast 7.0
library(zoo)
library(foreign)
library(TTR)
library(urca)
#read the file
bhar<-read.csv("E:/2 presentation for class/R/importfile/bhar.csv")
#check the structure of the file
str(bhar)
## 'data.frame': 53 obs. of 6 variables:
## $ year : int 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 ...
## $ Cereal.production : int 87376496 87257552 90373008 93706000 79699504 80137608 95453504 102443708 106291244 113909504 ...
## $ Crop.production.index : num 35 34.7 35.7 36.7 34.5 ...
## $ Food.production.index : num 32.2 31.7 32.5 33.3 31.7 ...
## $ Livestock.production.index: num 24.6 24.7 24.7 24.7 24.8 ...
## $ Cereal.yield : num 947 930 966 994 854 ...
#convert teh file into time series
bharts<-ts(bhar, start = c(1961, 1), end=c(2011,1), frequency = 1)
bharts
## Time Series:
## Start = 1961
## End = 2011
## Frequency = 1
## year Cereal.production Crop.production.index Food.production.index
## 1961 1961 87376496 35.03 32.17
## 1962 1962 87257552 34.71 31.74
## 1963 1963 90373008 35.74 32.46
## 1964 1964 93706000 36.69 33.29
## 1965 1965 79699504 34.54 31.73
## 1966 1966 80137608 34.22 31.69
## 1967 1967 95453504 36.86 33.61
## 1968 1968 102443708 38.67 35.47
## 1969 1969 106291244 40.03 36.69
## 1970 1970 113909504 42.53 38.59
## 1971 1971 113238296 43.11 39.03
## 1972 1972 108615456 40.69 37.41
## 1973 1973 119648216 44.25 40.39
## 1974 1974 106793000 42.33 39.11
## 1975 1975 127807800 47.15 43.46
## 1976 1976 121625108 46.10 43.07
## 1977 1977 138062904 50.35 46.62
## 1978 1978 142964696 52.52 48.08
## 1979 1979 126470304 48.93 45.86
## 1980 1980 140490600 50.54 47.74
## 1981 1981 147583816 54.13 51.11
## 1982 1982 136101404 52.85 50.80
## 1983 1983 166781704 59.56 56.89
## 1984 1984 164477600 60.44 57.96
## 1985 1985 165682196 61.34 59.21
## 1986 1986 164955216 61.29 60.19
## 1987 1987 156114500 59.97 59.65
## 1988 1988 183867008 67.14 65.36
## 1989 1989 199413216 71.73 69.06
## 1990 1990 193919312 72.74 70.28
## 1991 1991 193101196 73.84 71.24
## 1992 1992 201468404 77.24 74.23
## 1993 1993 208626900 79.91 77.01
## 1994 1994 211941400 82.27 79.15
## 1995 1995 210012500 83.85 81.18
## 1996 1996 218750900 87.74 84.61
## 1997 1997 223232400 87.87 85.73
## 1998 1998 226877000 90.31 88.12
## 1999 1999 236205608 94.42 92.22
## 2000 2000 234931192 92.28 91.67
## 2001 2001 242963796 94.99 94.79
## 2002 2002 206636704 84.73 87.36
## 2003 2003 236592700 97.13 96.51
## 2004 2004 229845500 94.05 94.68
## 2005 2005 239997500 99.89 100.02
## 2006 2006 242785600 106.06 105.30
## 2007 2007 260485900 116.42 114.65
## 2008 2008 266835300 117.50 117.19
## 2009 2009 250783400 112.94 114.38
## 2010 2010 267838300 125.15 123.40
## 2011 2011 287860000 134.36 131.13
## Livestock.production.index Cereal.yield
## 1961 24.56 947.28
## 1962 24.67 929.74
## 1963 24.72 965.82
## 1964 24.68 993.64
## 1965 24.78 854.44
## 1966 25.10 864.20
## 1967 25.55 993.67
## 1968 26.78 1036.64
## 1969 27.25 1053.72
## 1970 27.01 1134.82
## 1971 28.55 1136.10
## 1972 28.94 1107.83
## 1973 29.58 1152.80
## 1974 30.86 1074.50
## 1975 32.04 1260.84
## 1976 33.70 1198.69
## 1977 34.97 1331.07
## 1978 35.69 1370.18
## 1979 37.22 1222.25
## 1980 38.74 1350.00
## 1981 41.21 1398.79
## 1982 43.69 1346.42
## 1983 46.38 1564.36
## 1984 48.74 1563.84
## 1985 51.32 1592.23
## 1986 53.22 1585.36
## 1987 54.45 1583.74
## 1988 56.04 1775.76
## 1989 58.77 1916.41
## 1990 60.86 1891.22
## 1991 61.74 1926.32
## 1992 63.85 2024.82
## 1993 66.10 2084.88
## 1994 68.37 2115.52
## 1995 71.84 2111.72
## 1996 74.25 2180.97
## 1997 76.37 2228.60
## 1998 79.14 2248.44
## 1999 82.54 2313.66
## 2000 84.52 2294.20
## 2001 87.78 2423.07
## 2002 89.47 2187.31
## 2003 91.56 2399.45
## 2004 95.79 2350.02
## 2005 99.81 2411.57
## 2006 104.39 2446.53
## 2007 111.06 2583.33
## 2008 114.60 2637.87
## 2009 118.66 2580.83
## 2010 123.80 2676.35
## 2011 128.50 2861.84
#str(bharts)
#ploting the time series
plot.ts(bharts[,-1], type="l")
#fitting a linear equation
reg1<-lm(bhar$Cereal.production~bhar$year)
reg2<-lm(bhar$Crop.production.index~bhar$year)
reg3<-lm(bhar$Food.production.index~bhar$year)
reg4<-lm(bhar$Livestock.production.index~bhar$year)
reg5<-lm(bhar$Cereal.yield~bhar$year)
#summary of the equation
summary(reg1)
##
## Call:
## lm(formula = bhar$Cereal.production ~ bhar$year)
##
## Residuals:
## Min 1Q Median 3Q Max
## -30503160 -7336344 2248515 6466248 16410411
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -7.877e+09 1.880e+08 -41.90 <2e-16 ***
## bhar$year 4.053e+06 9.460e+04 42.84 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 10540000 on 51 degrees of freedom
## Multiple R-squared: 0.973, Adjusted R-squared: 0.9724
## F-statistic: 1835 on 1 and 51 DF, p-value: < 2.2e-16
summary(reg2)
##
## Call:
## lm(formula = bhar$Crop.production.index ~ bhar$year)
##
## Residuals:
## Min 1Q Median 3Q Max
## -14.840 -4.339 -1.910 3.667 21.411
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -3.702e+03 1.343e+02 -27.56 <2e-16 ***
## bhar$year 1.899e+00 6.761e-02 28.09 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 7.53 on 51 degrees of freedom
## Multiple R-squared: 0.9393, Adjusted R-squared: 0.9381
## F-statistic: 788.9 on 1 and 51 DF, p-value: < 2.2e-16
summary(reg3)
##
## Call:
## lm(formula = bhar$Food.production.index ~ bhar$year)
##
## Residuals:
## Min 1Q Median 3Q Max
## -10.745 -4.335 -2.527 3.801 19.161
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -3.814e+03 1.263e+02 -30.20 <2e-16 ***
## bhar$year 1.954e+00 6.356e-02 30.74 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 7.078 on 51 degrees of freedom
## Multiple R-squared: 0.9488, Adjusted R-squared: 0.9478
## F-statistic: 945.1 on 1 and 51 DF, p-value: < 2.2e-16
summary(reg4)
##
## Call:
## lm(formula = bhar$Livestock.production.index ~ bhar$year)
##
## Residuals:
## Min 1Q Median 3Q Max
## -8.214 -6.747 -3.635 6.078 19.000
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -4117.983 153.008 -26.91 <2e-16 ***
## bhar$year 2.103 0.077 27.32 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.575 on 51 degrees of freedom
## Multiple R-squared: 0.936, Adjusted R-squared: 0.9348
## F-statistic: 746.2 on 1 and 51 DF, p-value: < 2.2e-16
summary(reg5)
##
## Call:
## lm(formula = bhar$Cereal.yield ~ bhar$year)
##
## Residuals:
## Min 1Q Median 3Q Max
## -213.980 -74.578 4.838 62.901 249.818
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -7.859e+04 1.929e+03 -40.75 <2e-16 ***
## bhar$year 4.044e+01 9.707e-01 41.66 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 108.1 on 51 degrees of freedom
## Multiple R-squared: 0.9715, Adjusted R-squared: 0.9709
## F-statistic: 1736 on 1 and 51 DF, p-value: < 2.2e-16
#plot the regression equation, where year is independent variable and FDI is depependent varaible
plot(bhar$Cereal.production~bhar$year, type="l")
plot(bhar$Crop.production.index~bhar$year, type="l")
plot(bhar$Food.production.index~bhar$year, type="l")
plot(bhar$Livestock.production.index~bhar$year, type="l")
plot(bhar$Cereal.yield~bhar$year, type="l")
#cyclic fluctuation
#cycle(bhar$Foreign.direct.investment)
#no cyclic fluctuation
#To plot the cyclic fluctuation, use box plot with cycles
#boxplot(bhar$Foreign.direct.investment~cycle(bhar$Foreign.direct.investment))
#no seasonal fluctuation
#moving average
ma2<-ma(bharts[,-1],2,centre = TRUE)
ma2
## Time Series:
## Start = 1961
## End = 2011
## Frequency = 1
## [,1] [,2] [,3] [,4] [,5]
## 1961 NA NA NA NA NA
## 1962 88066152 35.0475 32.0275 24.6550 943.1450
## 1963 90427392 35.7200 32.4875 24.6975 963.7550
## 1964 89371128 35.9150 32.6925 24.7150 951.8850
## 1965 83310654 34.9975 32.1100 24.8350 891.6800
## 1966 83857056 34.9600 32.1800 25.1325 894.1275
## 1967 93372081 36.6525 33.5950 25.7450 972.0450
## 1968 101658041 38.5575 35.3100 26.5900 1030.1675
## 1969 107233925 40.3150 36.8600 27.0725 1069.7250
## 1970 111837137 42.0500 38.2250 27.4550 1114.8650
## 1971 112250388 42.3600 38.5150 28.2625 1128.7125
## 1972 112529356 42.1850 38.5600 29.0025 1126.1400
## 1973 113676222 42.8800 39.3250 29.7400 1121.9825
## 1974 115260504 44.0150 40.5175 30.8350 1140.6600
## 1975 121008427 45.6825 42.2750 32.1600 1198.7175
## 1976 127280230 47.4250 44.0550 33.6025 1247.3225
## 1977 135178903 49.8300 46.0975 34.8325 1307.7525
## 1978 137615650 51.0800 47.1600 35.8925 1323.4200
## 1979 134098976 50.2300 46.8850 37.2175 1291.1700
## 1980 138758830 51.0350 48.1125 38.9775 1330.2600
## 1981 142939909 52.9125 50.1900 41.2125 1373.5000
## 1982 146642082 54.8475 52.4000 43.7425 1413.9975
## 1983 158535603 58.1025 55.6350 46.2975 1509.7450
## 1984 165354775 60.4450 58.0050 48.7950 1571.0675
## 1985 165199302 61.1025 59.1425 51.1500 1583.4150
## 1986 162926782 60.9725 59.8100 53.0525 1586.6725
## 1987 165262806 62.0925 61.2125 54.5400 1632.1500
## 1988 180815433 66.4950 64.8575 56.3250 1762.9175
## 1989 194153188 70.8350 68.4400 58.6100 1874.9500
## 1990 195088259 72.7625 70.2150 60.5575 1906.2925
## 1991 195397527 74.4150 71.7475 62.0475 1942.1700
## 1992 201166226 77.0575 74.1775 63.8850 2015.2100
## 1993 207665901 79.8325 76.8500 66.1050 2077.5250
## 1994 210630550 82.0750 79.1225 68.6700 2106.9100
## 1995 212679325 84.4275 81.5300 71.5750 2129.9825
## 1996 217686675 86.8000 84.0325 74.1775 2175.5650
## 1997 223023175 88.4475 86.0475 76.5325 2221.6525
## 1998 228298002 90.7275 88.5475 79.2975 2259.7850
## 1999 233554852 92.8575 91.0575 82.1850 2292.4900
## 2000 237257947 93.4925 92.5875 84.8400 2331.2825
## 2001 231873872 91.7475 92.1525 87.3875 2331.9125
## 2002 223207476 90.3950 91.5050 89.5700 2299.2850
## 2003 227416901 93.2600 93.7650 92.0950 2334.0575
## 2004 234070300 96.2800 96.4725 95.7375 2377.7650
## 2005 238156525 99.9725 100.0050 99.9500 2404.9225
## 2006 246513650 107.1075 106.3175 104.9125 2471.9900
## 2007 257648175 114.1000 112.9475 110.2775 2562.7650
## 2008 261234975 116.0900 115.8525 114.7300 2609.9750
## 2009 259060100 117.1325 117.3375 118.9300 2618.9700
## 2010 268580000 124.4000 123.0775 123.6900 2698.8425
## 2011 NA NA NA NA NA
ma2<-plot(ma2)
ma3<-ma(bharts[,-1],3, centre = TRUE)
plot(ma3)
ma4<-ma(bharts[,-1],4, centre = TRUE)
plot(ma4)
ma5<-ma(bharts[,-1],5, centre = TRUE)
plot(ma5)
#exponential smoothing
es1<-ses(bhar$Cereal.production, initial=c("simple"), alpha=.2)
summary(es1)
##
## Forecast method: Simple exponential smoothing
##
## Model Information:
## Simple exponential smoothing
##
## Call:
## ses(x = bhar$Cereal.production, initial = c("simple"), alpha = 0.2)
##
## Smoothing parameters:
## alpha = 0.2
##
## Initial states:
## l = 87376496
##
## sigma: 21078418
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 17235557 21078418 18500058 9.282279 10.37512 1.922243
## ACF1
## Training set 0.3783154
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 54 270073401 243060321 297086480 228760461 311386340
## 55 270073401 242525357 297621444 227942304 312204498
## 56 270073401 242000585 298146216 227139734 313007067
## 57 270073401 241485445 298661357 226351895 313794906
## 58 270073401 240979424 299167378 225578003 314568799
## 59 270073401 240482055 299664746 224817343 315329459
## 60 270073401 239992909 300153893 224069258 316077543
## 61 270073401 239511590 300635211 223333145 316813656
## 62 270073401 239037735 301109066 222608447 317538355
## 63 270073401 238571008 301575794 221894648 318252154
plot(es1)
es2<-ses(bhar$Crop.production.index, initial=c("simple"), alpha=.2)
summary(es2)
##
## Forecast method: Simple exponential smoothing
##
## Model Information:
## Simple exponential smoothing
##
## Call:
## ses(x = bhar$Crop.production.index, initial = c("simple"), alpha = 0.2)
##
## Smoothing parameters:
## alpha = 0.2
##
## Initial states:
## l = 35.03
##
## sigma: 10.5011
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 8.315653 10.50109 8.513045 10.41176 10.79125 2.518652
## ACF1
## Training set 0.7197402
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 54 123.1759 109.7182 136.6336 102.59416 143.7577
## 55 123.1759 109.4517 136.9001 102.18656 144.1653
## 56 123.1759 109.1903 137.1616 101.78672 144.5651
## 57 123.1759 108.9336 137.4182 101.39423 144.9576
## 58 123.1759 108.6815 137.6703 101.00868 145.3432
## 59 123.1759 108.4338 137.9181 100.62973 145.7221
## 60 123.1759 108.1901 138.1618 100.25704 146.0948
## 61 123.1759 107.9503 138.4016 99.89031 146.4615
## 62 123.1759 107.7142 138.6376 99.52927 146.8226
## 63 123.1759 107.4817 138.8701 99.17367 147.1782
plot(es2)
es3<-ses(bhar$Food.production.index, initial=c("simple"), alpha=.2)
summary(es3)
##
## Forecast method: Simple exponential smoothing
##
## Model Information:
## Simple exponential smoothing
##
## Call:
## ses(x = bhar$Food.production.index, initial = c("simple"), alpha = 0.2)
##
## Smoothing parameters:
## alpha = 0.2
##
## Initial states:
## l = 32.17
##
## sigma: 10.2877
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 8.425694 10.28774 8.487945 10.99613 11.19239 2.97001
## ACF1
## Training set 0.7926818
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 54 121.4824 108.2981 134.6666 101.31875 141.6460
## 55 121.4824 108.0370 134.9277 100.91943 142.0453
## 56 121.4824 107.7809 135.1839 100.52772 142.4370
## 57 121.4824 107.5294 135.4353 100.14320 142.8215
## 58 121.4824 107.2825 135.6823 99.76549 143.1992
## 59 121.4824 107.0397 135.9250 99.39423 143.5705
## 60 121.4824 106.8010 136.1637 99.02911 143.9356
## 61 121.4824 106.5661 136.3987 98.66984 144.2949
## 62 121.4824 106.3348 136.6299 98.31614 144.6486
## 63 121.4824 106.1070 136.8577 97.96775 144.9970
plot(es3)
es4<-ses(bhar$Livestock.production.index, initial=c("simple"), alpha=.2)
summary(es4)
##
## Forecast method: Simple exponential smoothing
##
## Model Information:
## Simple exponential smoothing
##
## Call:
## ses(x = bhar$Livestock.production.index, initial = c("simple"),
##
## Call:
## alpha = 0.2)
##
## Smoothing parameters:
## alpha = 0.2
##
## Initial states:
## l = 24.56
##
## sigma: 10.909
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 8.95589 10.90905 8.95589 12.85576 12.85576 4.186877 0.9424504
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 54 119.4924 105.5119 133.4729 98.11110 140.8738
## 55 119.4924 105.2351 133.7498 97.68766 141.2972
## 56 119.4924 104.9635 134.0214 97.27230 141.7126
## 57 119.4924 104.6969 134.2880 96.86455 142.1203
## 58 119.4924 104.4350 134.5499 96.46403 142.5208
## 59 119.4924 104.1776 134.8073 96.07035 142.9145
## 60 119.4924 103.9244 135.0605 95.68319 143.3017
## 61 119.4924 103.6753 135.3096 95.30221 143.6827
## 62 119.4924 103.4301 135.5548 94.92715 144.0577
## 63 119.4924 103.1885 135.7964 94.55772 144.4272
plot(es4)
es5<-ses(bhar$Cereal.yield, initial=c("simple"), alpha=.2)
summary(es5)
##
## Forecast method: Simple exponential smoothing
##
## Model Information:
## Simple exponential smoothing
##
## Call:
## ses(x = bhar$Cereal.yield, initial = c("simple"), alpha = 0.2)
##
## Smoothing parameters:
## alpha = 0.2
##
## Initial states:
## l = 947.28
##
## sigma: 202.9193
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 167.5644 202.9193 175.7864 8.804443 9.689529 2.294983
## ACF1
## Training set 0.5977717
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 54 2723.463 2463.412 2983.515 2325.749 3121.178
## 55 2723.463 2458.262 2988.665 2317.872 3129.054
## 56 2723.463 2453.210 2993.717 2310.146 3136.780
## 57 2723.463 2448.250 2998.676 2302.562 3144.365
## 58 2723.463 2443.379 3003.547 2295.112 3151.815
## 59 2723.463 2438.591 3008.335 2287.789 3159.138
## 60 2723.463 2433.882 3013.044 2280.587 3166.339
## 61 2723.463 2429.248 3017.678 2273.501 3173.426
## 62 2723.463 2424.687 3022.240 2266.524 3180.402
## 63 2723.463 2420.194 3026.733 2259.652 3187.274
plot(es5)
#exponential smoothing is also done by holwinter method, this is also used for exponential forcasting
#cereal production__________________________________________________________
es_holt1<-HoltWinters(bhar$Cereal.production, beta = FALSE, gamma = FALSE)
summary(es_holt1)
## Length Class Mode
## fitted 104 mts numeric
## x 53 ts numeric
## alpha 1 -none- numeric
## beta 1 -none- logical
## gamma 1 -none- logical
## coefficients 1 -none- numeric
## seasonal 1 -none- character
## SSE 1 -none- numeric
## call 4 -none- call
#forecast the values using exponential smoothing
es_holt_fore1<-forecast.HoltWinters(es_holt1, h=5)
es_holt_fore1
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 54 293169435 278691187 307647683 271026866 315312004
## 55 293169435 274959590 311379280 265319880 321018990
## 56 293169435 271872082 314466788 260597944 325740926
## 57 293169435 269178686 317160185 256478750 329860120
## 58 293169435 266758550 319580320 252777472 333561399
#gives the value of alfa, less is the value of alfa, means the prediction depends on the recent values, higher the value of alfa, prediction depends on the further values
plot(es_holt_fore1)
#_____________________________________________________________________
#Crop.production.index__________________________________________________________
es_holt2<-HoltWinters(bhar$Crop.production.index, beta = FALSE, gamma = FALSE)
summary(es_holt2)
## Length Class Mode
## fitted 104 mts numeric
## x 53 ts numeric
## alpha 1 -none- numeric
## beta 1 -none- logical
## gamma 1 -none- logical
## coefficients 1 -none- numeric
## seasonal 1 -none- character
## SSE 1 -none- numeric
## call 4 -none- call
#forecast the values using exponential smoothing
es_holt_fore2<-forecast.HoltWinters(es_holt2, h=5)
es_holt_fore2
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 54 141.8696 136.6613 147.0780 133.9042 149.8351
## 55 141.8696 134.5042 149.2351 130.6051 153.1341
## 56 141.8696 132.8489 150.8904 128.0736 155.6656
## 57 141.8696 131.4535 152.2858 125.9395 157.7998
## 58 141.8696 130.2240 153.5152 124.0592 159.6800
#gives the value of alfa, less is the value of alfa, means the prediction depends on the recent values, higher the value of alfa, prediction depends on the further values
plot(es_holt_fore2)
#_____________________________________________________________________
#Food.production.index__________________________________________________________
es_holt3<-HoltWinters(bhar$Food.production.index, beta = FALSE, gamma = FALSE)
summary(es_holt3)
## Length Class Mode
## fitted 104 mts numeric
## x 53 ts numeric
## alpha 1 -none- numeric
## beta 1 -none- logical
## gamma 1 -none- logical
## coefficients 1 -none- numeric
## seasonal 1 -none- character
## SSE 1 -none- numeric
## call 4 -none- call
#forecast the values using exponential smoothing
es_holt_fore3<-forecast.HoltWinters(es_holt3, h=5)
es_holt_fore3
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 54 138.7598 134.7570 142.7625 132.6381 144.8815
## 55 138.7598 133.0991 144.4204 130.1026 147.4169
## 56 138.7598 131.8270 145.6925 128.1570 149.3625
## 57 138.7598 130.7545 146.7650 126.5168 151.0027
## 58 138.7598 129.8097 147.7098 125.0718 152.4477
#gives the value of alfa, less is the value of alfa, means the prediction depends on the recent values, higher the value of alfa, prediction depends on the further values
plot(es_holt_fore3)
#_____________________________________________________________________
#Livestock.production.index __________________________________________________________
es_holt4<-HoltWinters(bhar$Livestock.production.index, beta = FALSE, gamma = FALSE)
summary(es_holt4)
## Length Class Mode
## fitted 104 mts numeric
## x 53 ts numeric
## alpha 1 -none- numeric
## beta 1 -none- logical
## gamma 1 -none- logical
## coefficients 1 -none- numeric
## seasonal 1 -none- character
## SSE 1 -none- numeric
## call 4 -none- call
#forecast the values using exponential smoothing
es_holt_fore4<-forecast.HoltWinters(es_holt4, h=5)
es_holt_fore4
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 54 135.2299 133.3307 137.1290 132.3253 138.1344
## 55 135.2299 132.5441 137.9156 131.1223 139.3374
## 56 135.2299 131.9405 138.5192 130.1992 140.2605
## 57 135.2299 131.4317 139.0281 129.4210 141.0387
## 58 135.2299 130.9834 139.4764 128.7354 141.7243
#gives the value of alfa, less is the value of alfa, means the prediction depends on the recent values, higher the value of alfa, prediction depends on the further values
plot(es_holt_fore4)
#_____________________________________________________________________
#Cereal.yield__________________________________________________________
es_holt5<-HoltWinters(bhar$Cereal.yield, beta = FALSE, gamma = FALSE)
summary(es_holt5)
## Length Class Mode
## fitted 104 mts numeric
## x 53 ts numeric
## alpha 1 -none- numeric
## beta 1 -none- logical
## gamma 1 -none- logical
## coefficients 1 -none- numeric
## seasonal 1 -none- character
## SSE 1 -none- numeric
## call 4 -none- call
#forecast the values using exponential smoothing
es_holt_fore5<-forecast.HoltWinters(es_holt4, h=5)
es_holt_fore5
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 54 135.2299 133.3307 137.1290 132.3253 138.1344
## 55 135.2299 132.5441 137.9156 131.1223 139.3374
## 56 135.2299 131.9405 138.5192 130.1992 140.2605
## 57 135.2299 131.4317 139.0281 129.4210 141.0387
## 58 135.2299 130.9834 139.4764 128.7354 141.7243
#gives the value of alfa, less is the value of alfa, means the prediction depends on the recent values, higher the value of alfa, prediction depends on the further values
plot(es_holt_fore5)
#_____________________________________________________________________
#ploting the ACF and pacf
#bhar_acf<-acf(bharts, lag.max = 20)
#bhar_pacf<-pacf(bharts[,-1],lag.max = 20)
#auto arima model
#auto_arima<-auto.arima(bharts)
#auto_arima
#summary(auto_arima)
#tsdiag(auto_arima)
#bhar_for<-forecast.Arima(auto_arima, h=10)
#bhar_for
#plot.forecast(bhar_for)
#plot.ts(bhar_for$residuals)
```