+ All documents
Home > Documents > ’nottem {dataset} ’ Analysis

’nottem {dataset} ’ Analysis

Date post: 10-Nov-2023
Category:
Upload: aims
View: 4 times
Download: 0 times
Share this document with a friend
27
AIMS-TANZANIA Susanna African Institute For Mathematical Science Environmental Statistics ’nottem {dataset} Analysis Jason Susanna Anquandah February 13, 2015 1
Transcript

AIMS-TANZANIA Susanna

African InstituteFor

Mathematical Science

Environmental Statistics

’nottem {dataset} ’ Analysis

Jason Susanna Anquandah

February 13, 2015

1

AIMS-TANZANIA Susanna

Abstract

’nottem {dataset} ’ is a dataset made up of the average Monthly Temperatures at Nottingham, 1920–1939 .It is a time series object containing average air temperatures at Nottingham Castle in degrees Fahrenheit for20 years. The Seasonal Trend Decomposition is an algorithm that was developed to help to divide up a timeseries into three components namely: the trend, seasonality and remainder. The methodology is the basis formy analysis.

2

AIMS-TANZANIA Susanna

Contents

Abstract 2

Introduction 4

Methodology 4

Conclusion 8

References 8

Tables and Figures 9

Apendices 18

3

AIMS-TANZANIA Susanna

Introduction

The Seasonal Trend Decomposition is an algorithm that was developed to help to divide up a time series intothree components namely: the trend, seasonality and remainder. The methodology was presented by RobertCleveland, William Cleveland, Jean McRae and Irma Terpenning in the Journal of Official Statistics in 1990.The application of this method can be demonstrated using one of the data sets available within the base Rinstallation. The well used ’nottem {dataset} ’ (Average Monthly Temperatures at Nottingham, 1920-1939)is a good starting point. The data itself is presented in Table (1).

Data Provided

Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec1920 40.60 40.80 44.40 46.70 54.10 58.50 57.70 56.40 54.30 50.50 42.90 39.801921 44.20 39.80 45.10 47.00 54.10 58.70 66.30 59.90 57.00 54.20 39.70 42.801922 37.50 38.70 39.50 42.10 55.70 57.80 56.80 54.30 54.30 47.10 41.80 41.701923 41.80 40.10 42.90 45.80 49.20 52.70 64.20 59.60 54.40 49.20 36.30 37.601924 39.30 37.50 38.30 45.50 53.20 57.70 60.80 58.20 56.40 49.80 44.40 43.601925 40.00 40.50 40.80 45.10 53.80 59.40 63.50 61.00 53.00 50.00 38.10 36.301926 39.20 43.40 43.40 48.90 50.60 56.80 62.50 62.00 57.50 46.70 41.60 39.801927 39.40 38.50 45.30 47.10 51.70 55.00 60.40 60.50 54.70 50.30 42.30 35.201928 40.80 41.10 42.80 47.30 50.90 56.40 62.20 60.50 55.40 50.20 43.00 37.301929 34.80 31.30 41.00 43.90 53.10 56.90 62.50 60.30 59.80 49.20 42.90 41.901930 41.60 37.10 41.20 46.90 51.20 60.40 60.10 61.60 57.00 50.90 43.00 38.801931 37.10 38.40 38.40 46.50 53.50 58.40 60.60 58.20 53.80 46.60 45.50 40.601932 42.40 38.40 40.30 44.60 50.90 57.00 62.10 63.50 56.30 47.30 43.60 41.801933 36.20 39.30 44.50 48.70 54.20 60.80 65.50 64.90 60.10 50.20 42.10 35.801934 39.40 38.20 40.40 46.90 53.40 59.60 66.50 60.40 59.20 51.20 42.80 45.801935 40.00 42.60 43.50 47.10 50.00 60.50 64.60 64.00 56.80 48.60 44.20 36.401936 37.30 35.00 44.00 43.90 52.70 58.60 60.00 61.10 58.10 49.60 41.60 41.301937 40.80 41.00 38.40 47.40 54.10 58.60 61.40 61.80 56.30 50.90 41.40 37.101938 42.10 41.20 47.30 46.60 52.40 59.00 59.60 60.40 57.00 50.70 47.80 39.201939 39.40 40.90 42.40 47.80 52.40 58.00 60.70 61.80 58.20 46.70 46.60 37.80

Table 1: Nottem Data

Methodology

Implementation

In my implementation, the steps I followed for my analysis were:

♠ Identification and explanation

? Descriptive Statistics

? Figures- Box plot, Histogram, Q-Q plot

? Plotting the data set

? Time series Data analysis

? Produce a time series plot

? Decomposition

? Making nottem matrix

? ACF & PACF

? Prediction of models

4

AIMS-TANZANIA Susanna

? Preferred Model

? Verification

♠ Prediction of models

♠ Selection of Model

♠ Verification and Forecast

♠ Arima Plus Regression model

Identification and explanation

Descriptive Statistics

In the table below is the descriptive statistics for each month.

Jan Feb Mar Apr May Jun1 Min. :34.80 Min. :31.30 Min. :38.30 Min. :42.10 Min. :49.20 Min. :52.702 1st Qu.:38.77 1st Qu.:38.35 1st Qu.:40.38 1st Qu.:45.40 1st Qu.:51.12 1st Qu.:56.983 Median :39.70 Median :39.55 Median :42.60 Median :46.80 Median :52.90 Median :58.454 Mean :39.70 Mean :39.19 Mean :42.20 Mean :46.29 Mean :52.56 Mean :58.045 3rd Qu.:41.00 3rd Qu.:40.92 3rd Qu.:44.10 3rd Qu.:47.15 3rd Qu.:53.88 3rd Qu.:59.106 Max. :44.20 Max. :43.40 Max. :47.30 Max. :48.90 Max. :55.70 Max. :60.80

Jul Aug Sep Oct Nov Dec1 Min. :56.80 Min. :54.30 Min. :53.00 Min. :46.60 Min. :36.30 Min. :35.202 1st Qu.:60.33 1st Qu.:59.83 1st Qu.:54.62 1st Qu.:48.27 1st Qu.:41.60 1st Qu.:37.253 Median :61.75 Median :60.50 Median :56.60 Median :49.90 Median :42.85 Median :39.504 Mean :61.90 Mean :60.52 Mean :56.48 Mean :49.49 Mean :42.58 Mean :39.535 3rd Qu.:63.67 3rd Qu.:61.80 3rd Qu.:57.65 3rd Qu.:50.55 3rd Qu.:43.75 3rd Qu.:41.736 Max. :66.50 Max. :64.90 Max. :60.10 Max. :54.20 Max. :47.80 Max. :45.80

Figures

For further display of results,

Box plot

In descriptive statistics, a box plot or box plot is a convenient way of graphically depicting groups of numericaldata through their quartiles. Box plots may also have lines extending vertically from the boxes (whiskers)indicating variability outside the upper and lower quartiles. Also, the outliers in the box plots indicate thatthere are some observations who don’t fall within the distribution. From my box plot in Figure (1), we see thatthere is no outlier hence our observation is normally distributed.

Histogram

A histogram is a graphical representation of the distribution of data. A rectangle is drawn with height propor-tional to the count and width equal to the bin size, so that rectangles abut each other. A histogram may also benormalized displaying relative frequencies. From our histogram in Figure (1), we observe that the observationis normally distributed.

Q-Q plot

The Q-Q plot is also normally distributed as seen in Figure (4).

5

AIMS-TANZANIA Susanna

Plotting the Dataset

The general plot of the data is seen in Figure (2).

Time series of nottem

The timeseries for nottem is seen in Table (2)

Plotting Time-Series Objects

For time series, we generally look at is the “time series plot,” which is a plot of the observed series nottem bytime t seen in Figure (2). Do you notice that some of these series exhibit a marked “periodicity,” or seasonality?Basically, within a given year the maximum of the series occurs in the summer and the minimum in the winter.This is perhaps not so clear for the plots of the whole series as the “cycles” are rather “squeezed.” We also see a“blow up” of a small number of years within each series. We know the maximum temperature is in the summer,so the “seasonality” of a temperature series is not unexpected.

Decomposition

The seasonal effect is demonstrated as well by computing averages across years within months. Considering thetemperature series nottem, there are 20 years of data, so there are 20 January temperatures. We take these 20January temperatures and average them to get an estimate of the over-all temperature in January. Removingseasonal component by subtracting seasonal mean. The approach we demonstrated is to decompose the seriesinto a trend, a seasonal component and a residual (stationary process). When you decomposed nottem versionis observed in the Appendix section.

Plotting the Decomposed nottem

The plots of the decomposed graph are seen in Figure (5), Figure (6) and Figure (7). Where Figure (5) is thedecomposition of the given observation(nottem), Figure (6) is the plot of the decomposition of the log of nottemand Figure (7) is the plot of the decomposition of the square root of the nottem data. The original data, log andsquare root were taken to make the variability in seasonality constant and this is well observed the differencein variability is not so different after manipulation.

Making nottem matrix

For our analysis, a matrix is made out of nottem which is seen in Figure (3) with its transpose shown in Figure(4).

Boxplots of nottem matrix

Under the nottem matrix, three box plots were made

� One of the nottem matrixThis boxplot is shown in Figure (8). it is observed that the 2nd, 4th, 6th, 8th and 11th box plots are notnormally distributed.

� Another of the transpose nottem matrixThis is seen in Figure (9). It is observed that all the box plots are normally distributed.

� The last of the log of the transpose nottem matrixThis is seen in Figure (10). It is observed that all boxplots in this figure are also normally distributed.

6

AIMS-TANZANIA Susanna

ACF & PACF

? acf: It computes (and by default plots) estimates of the autocovariance or autocorrelation function. Thisis seen in Figure (3)

? pacf: It is the function used for the partial autocorrelations.This is seen in Figure (3)

The two plots indicate that there is high variation even after data manipulation.

Prediction of models

Generic function calculating Akaike’s ‘An Information Criterion’ for one or several fitted model objects for whicha log-likelihood value can be obtained, according to the formula −2 ∗ log − likelihood + k ∗ npar, where nparrepresents the number of parameters in the fitted model, and k = 2 for the usual AIC, or k = log(n) (n beingthe number of observations) for the so-called BIC or SBC (Schwarz’s Bayesian criterion). Suppose that we havea statistical model of some data. Let L be the maximized value of the likelihood function for the model; let kbe the number of parameters in the model (i.e. k is the number of degrees of freedom). Then the AIC value isas follows.

AIC = 2k − 2 ln(L)

Given a set of candidate models for the data, the preferred model is the one with the minimum AIC value.Hence AIC rewards goodness of fit (as assessed by the likelihood function), but it also includes a penalty that isan increasing function of the number of estimated parameters. The penalty discourages over fitting (increasingthe number of parameters in the model almost always improves the goodness of the fit). The table below showsa set of fitted models and their AIC and BIC. I used the arima function to predict a model by changing theARIMA an Seasonal values. In the table below are some of the results.

ARIMA - MODEL SEASONAL -MODEL ar1 ar2 sar1 sar2 intercept AIC BIC(1, 0, 0) (2, 0, 0) 0.3355 - 0.3012 0.6455 49.5242 1155.17 1172.57(1, 1, 0) (2, 0, 0) -0.3451 - 0.2943 0.6292 - 1211.83 1225.73(2, 1, 0) (2, 0, 0) -0.4298 -0.2124 0.2951 0.6495 - 1203.91 1221.29(1, 0, 0) (1, 0, 0) 0.2970 - 0.8654 - 49.0251 1273.37 1287.24

Preferred Model

I used the forecast package to get an autoarima model. Which is given by:

Series: nottemtimeseries

ARIMA(1,0,0)(2,0,0)[12] with non-zero mean

Coefficients:

ar1 sar1 sar2 intercept

0.3355 0.3012 0.6455 49.5242

s.e. 0.0646 0.0481 0.0485 2.2613

sigma^2 estimated as 6.143: log likelihood=-572.58

AIC=1155.17 AICc=1155.43 BIC=1172.57

Also, if you observe the above table in the prediction of a model section, you will realise that ARIMA(1, 0, 0)(2, 0, 0)[12]has the minimum AIC and BIC value snd as such is the preferred model. Thus my model is given by:

Xt = 0.3355Xt−1 + 0.3021Xt−4 + 0.6455Xt−8 + εt + 49.5242

7

AIMS-TANZANIA Susanna

Verification and Forecasting

’tsdiag’

The test of this model using the tsdiag package to test for the significance level in my model. The Figurefor tsdiag is seen in Figure (11). We see that the p value is highly significant . We can investigate whetherthe predictive model can be improved upon by checking whether the in-sample forecast errors show non-zeroautocorrelations at lags 1-12, by making a correlogram and carrying out the Ljung-Box test in Figure (11).The correlogram shows that the autocorrelations for the in-sample forecast errors do not exceed the significancebounds for lags 1-12. Furthermore, the p-value for Ljung-Box test is 0.6741, indicating that there is evidenceof non-zero autocorrelations at lags 1-12.

Future Forecast

We see from the plot that the Arima model is very successful in predicting the seasonal peaks, which occurroughly in November every year. To make forecasts for future times not included in the original time series,we use the “forecast.Arima()” function in the “forecast” package. For example, the original data for the beerconsumption is from January 1920 to December 1939. If we wanted to make forecasts for January 1940 toDecember 1944 (60 more months) in the appendix 1 and plot the forecasts in Figure (12). The forecastsare shown as a blue line, and the lightblue and gray shaded areas show 80% and 95% prediction intervals,respectively.

Forecast Error

We can check whether the forecast errors have constant variance over time, and are normally distributed withmean zero, by making a time plot of the forecast errors and a histogram (with overlaid normal curve). The timeplot in Figure (13) and histogram in Figure (14). From the time plot, it appears plausible that the forecast errorshave constant variance over time. From the histogram of forecast errors, it seems plausible that the forecasterrors are normally distributed with mean zero. Thus, there is little evidence of autocorrelation at lags 1-12for the forecast errors, and the forecast errors appear to be normally distributed with mean zero and constantvariance over time. This suggests that Arima model provides an adequate predictive model. Furthermore, theassumptions upon which the prediction intervals were based are probably valid.

Results and Discussion

It is obvious that the predicted model for Arima Model is adequate. The tsdiag shows a very high significancein the p value plot. But our model can be improved upon because there was high variability in our data whenI found the ACF and PACF plot of my data. The variation should be worked upon to be taken out to see if wewill get a better model than what I have for much better and accurate predictions.

Conclusions

From my analysis, the predicted model for predicting average Monthly Temperatures at Nottingham is adequatefor Arima Model. Even with is basis, I recommend that further work should to be done for an utter verificationand improvement of the model or the development of a new model for a more effictive, efficient and adequateprediction.

References

[1] Anderson, O. D. (1976) Time Series Analysis and Forecasting: The Box-Jenkins approach. Butterworths.Series R.

[2] ”+ magazine”, Testing Bernoulli: a simple experiment, http://plus.maths.org/content/

testing-bernoulli-simple-experiment?src=aop.

8

AIMS-TANZANIA Susanna

[3] Anderson, O. D. (1976) Time Series Analysis and Forecasting: The Box-Jenkins approach. Butterworths.Series R.

[4] R-bloggers -R news and tutorials contributed by (573) R bloggers http://www.r-bloggers.com/

seasonal-trend-decomposition-in-r/

[5] Vincentarelbundock http://vincentarelbundock.github.io/Rdatasets/datasets.html

[6] Wikipedia, https://www.wikipedia.org/

[7] Wikipedia, http://axiomic.net/primers/primer2-p-value.pdf

Tables and Figures

Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec1920 40.60 40.80 44.40 46.70 54.10 58.50 57.70 56.40 54.30 50.50 42.90 39.801921 44.20 39.80 45.10 47.00 54.10 58.70 66.30 59.90 57.00 54.20 39.70 42.801922 37.50 38.70 39.50 42.10 55.70 57.80 56.80 54.30 54.30 47.10 41.80 41.701923 41.80 40.10 42.90 45.80 49.20 52.70 64.20 59.60 54.40 49.20 36.30 37.601924 39.30 37.50 38.30 45.50 53.20 57.70 60.80 58.20 56.40 49.80 44.40 43.601925 40.00 40.50 40.80 45.10 53.80 59.40 63.50 61.00 53.00 50.00 38.10 36.301926 39.20 43.40 43.40 48.90 50.60 56.80 62.50 62.00 57.50 46.70 41.60 39.801927 39.40 38.50 45.30 47.10 51.70 55.00 60.40 60.50 54.70 50.30 42.30 35.201928 40.80 41.10 42.80 47.30 50.90 56.40 62.20 60.50 55.40 50.20 43.00 37.301929 34.80 31.30 41.00 43.90 53.10 56.90 62.50 60.30 59.80 49.20 42.90 41.901930 41.60 37.10 41.20 46.90 51.20 60.40 60.10 61.60 57.00 50.90 43.00 38.801931 37.10 38.40 38.40 46.50 53.50 58.40 60.60 58.20 53.80 46.60 45.50 40.601932 42.40 38.40 40.30 44.60 50.90 57.00 62.10 63.50 56.30 47.30 43.60 41.801933 36.20 39.30 44.50 48.70 54.20 60.80 65.50 64.90 60.10 50.20 42.10 35.801934 39.40 38.20 40.40 46.90 53.40 59.60 66.50 60.40 59.20 51.20 42.80 45.801935 40.00 42.60 43.50 47.10 50.00 60.50 64.60 64.00 56.80 48.60 44.20 36.401936 37.30 35.00 44.00 43.90 52.70 58.60 60.00 61.10 58.10 49.60 41.60 41.301937 40.80 41.00 38.40 47.40 54.10 58.60 61.40 61.80 56.30 50.90 41.40 37.101938 42.10 41.20 47.30 46.60 52.40 59.00 59.60 60.40 57.00 50.70 47.80 39.201939 39.40 40.90 42.40 47.80 52.40 58.00 60.70 61.80 58.20 46.70 46.60 37.80

Table 2: Nottem Timeseries Data

9

AIMS-TANZANIA Susanna

1 2 3 4 5 6 7 8 9 10 11 121 40.60 40.80 44.40 46.70 54.10 58.50 57.70 56.40 54.30 50.50 42.90 39.802 44.20 39.80 45.10 47.00 54.10 58.70 66.30 59.90 57.00 54.20 39.70 42.803 37.50 38.70 39.50 42.10 55.70 57.80 56.80 54.30 54.30 47.10 41.80 41.704 41.80 40.10 42.90 45.80 49.20 52.70 64.20 59.60 54.40 49.20 36.30 37.605 39.30 37.50 38.30 45.50 53.20 57.70 60.80 58.20 56.40 49.80 44.40 43.606 40.00 40.50 40.80 45.10 53.80 59.40 63.50 61.00 53.00 50.00 38.10 36.307 39.20 43.40 43.40 48.90 50.60 56.80 62.50 62.00 57.50 46.70 41.60 39.808 39.40 38.50 45.30 47.10 51.70 55.00 60.40 60.50 54.70 50.30 42.30 35.209 40.80 41.10 42.80 47.30 50.90 56.40 62.20 60.50 55.40 50.20 43.00 37.30

10 34.80 31.30 41.00 43.90 53.10 56.90 62.50 60.30 59.80 49.20 42.90 41.9011 41.60 37.10 41.20 46.90 51.20 60.40 60.10 61.60 57.00 50.90 43.00 38.8012 37.10 38.40 38.40 46.50 53.50 58.40 60.60 58.20 53.80 46.60 45.50 40.6013 42.40 38.40 40.30 44.60 50.90 57.00 62.10 63.50 56.30 47.30 43.60 41.8014 36.20 39.30 44.50 48.70 54.20 60.80 65.50 64.90 60.10 50.20 42.10 35.8015 39.40 38.20 40.40 46.90 53.40 59.60 66.50 60.40 59.20 51.20 42.80 45.8016 40.00 42.60 43.50 47.10 50.00 60.50 64.60 64.00 56.80 48.60 44.20 36.4017 37.30 35.00 44.00 43.90 52.70 58.60 60.00 61.10 58.10 49.60 41.60 41.3018 40.80 41.00 38.40 47.40 54.10 58.60 61.40 61.80 56.30 50.90 41.40 37.1019 42.10 41.20 47.30 46.60 52.40 59.00 59.60 60.40 57.00 50.70 47.80 39.2020 39.40 40.90 42.40 47.80 52.40 58.00 60.70 61.80 58.20 46.70 46.60 37.80

Table 3: Nottem as a matrix

1 2 3 4 5 6 7 8 9 101 40.60 44.20 37.50 41.80 39.30 40.00 39.20 39.40 40.80 34.802 40.80 39.80 38.70 40.10 37.50 40.50 43.40 38.50 41.10 31.303 44.40 45.10 39.50 42.90 38.30 40.80 43.40 45.30 42.80 41.004 46.70 47.00 42.10 45.80 45.50 45.10 48.90 47.10 47.30 43.905 54.10 54.10 55.70 49.20 53.20 53.80 50.60 51.70 50.90 53.106 58.50 58.70 57.80 52.70 57.70 59.40 56.80 55.00 56.40 56.907 57.70 66.30 56.80 64.20 60.80 63.50 62.50 60.40 62.20 62.508 56.40 59.90 54.30 59.60 58.20 61.00 62.00 60.50 60.50 60.309 54.30 57.00 54.30 54.40 56.40 53.00 57.50 54.70 55.40 59.80

10 50.50 54.20 47.10 49.20 49.80 50.00 46.70 50.30 50.20 49.2011 42.90 39.70 41.80 36.30 44.40 38.10 41.60 42.30 43.00 42.9012 39.80 42.80 41.70 37.60 43.60 36.30 39.80 35.20 37.30 41.90

11 12 13 14 15 16 17 18 19 201 41.60 37.10 42.40 36.20 39.40 40.00 37.30 40.80 42.10 39.402 37.10 38.40 38.40 39.30 38.20 42.60 35.00 41.00 41.20 40.903 41.20 38.40 40.30 44.50 40.40 43.50 44.00 38.40 47.30 42.404 46.90 46.50 44.60 48.70 46.90 47.10 43.90 47.40 46.60 47.805 51.20 53.50 50.90 54.20 53.40 50.00 52.70 54.10 52.40 52.406 60.40 58.40 57.00 60.80 59.60 60.50 58.60 58.60 59.00 58.007 60.10 60.60 62.10 65.50 66.50 64.60 60.00 61.40 59.60 60.708 61.60 58.20 63.50 64.90 60.40 64.00 61.10 61.80 60.40 61.809 57.00 53.80 56.30 60.10 59.20 56.80 58.10 56.30 57.00 58.20

10 50.90 46.60 47.30 50.20 51.20 48.60 49.60 50.90 50.70 46.7011 43.00 45.50 43.60 42.10 42.80 44.20 41.60 41.40 47.80 46.6012 38.80 40.60 41.80 35.80 45.80 36.40 41.30 37.10 39.20 37.80

Table 4: Transpose of Nottem as a matrix

10

AIMS-TANZANIA Susanna

(a) Boxplot of nottem (b) Histogram with normal curve of nottem

Figure 1: Boxplot and Histogram of nottem

(a) Plot of nottem (b) Time Series Plot of nottem

Figure 2: Plot and Time series Plot of nottem

(a) ACF of nottemtimeserires (b) PACF of nottemtimeserires

Figure 3: ACF and PACF of nottemtimeserires

11

AIMS-TANZANIA Susanna

Figure 4: Q-Q Plot

Figure 5: Plot of decompose nottem

12

AIMS-TANZANIA Susanna

Figure 6: Plot of decompose log(nottem)

Figure 7: Plot of decompose sqrt(nottem)

13

AIMS-TANZANIA Susanna

Figure 8: Box Plot of Nottem Matrix

Figure 9: Box Plot of the Transpose of the Nottem Matrix

14

AIMS-TANZANIA Susanna

Figure 10: Box Plot of the log of the transpose of the Nottem Matrix

Figure 11: tsdiag for ARIMA(1, 0, 0)(2, 0, 0)[12]

15

AIMS-TANZANIA Susanna

Figure 12: Plot of Forecast with Arima Model

Figure 13: Plot of Residuals of Timeseries Forecast

16

AIMS-TANZANIA Susanna

Figure 14: Histogram of Forecast Error

Figure 15: tsdiag for ARIMA PLUS REGRESSION MODEL

17

AIMS-TANZANIA Susanna

Apendices

Appendix 1

This is the decomposed results.

$x

Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

1920 40.6 40.8 44.4 46.7 54.1 58.5 57.7 56.4 54.3 50.5 42.9 39.8

1921 44.2 39.8 45.1 47.0 54.1 58.7 66.3 59.9 57.0 54.2 39.7 42.8

1922 37.5 38.7 39.5 42.1 55.7 57.8 56.8 54.3 54.3 47.1 41.8 41.7

1923 41.8 40.1 42.9 45.8 49.2 52.7 64.2 59.6 54.4 49.2 36.3 37.6

1924 39.3 37.5 38.3 45.5 53.2 57.7 60.8 58.2 56.4 49.8 44.4 43.6

1925 40.0 40.5 40.8 45.1 53.8 59.4 63.5 61.0 53.0 50.0 38.1 36.3

1926 39.2 43.4 43.4 48.9 50.6 56.8 62.5 62.0 57.5 46.7 41.6 39.8

1927 39.4 38.5 45.3 47.1 51.7 55.0 60.4 60.5 54.7 50.3 42.3 35.2

1928 40.8 41.1 42.8 47.3 50.9 56.4 62.2 60.5 55.4 50.2 43.0 37.3

1929 34.8 31.3 41.0 43.9 53.1 56.9 62.5 60.3 59.8 49.2 42.9 41.9

1930 41.6 37.1 41.2 46.9 51.2 60.4 60.1 61.6 57.0 50.9 43.0 38.8

1931 37.1 38.4 38.4 46.5 53.5 58.4 60.6 58.2 53.8 46.6 45.5 40.6

1932 42.4 38.4 40.3 44.6 50.9 57.0 62.1 63.5 56.3 47.3 43.6 41.8

1933 36.2 39.3 44.5 48.7 54.2 60.8 65.5 64.9 60.1 50.2 42.1 35.8

1934 39.4 38.2 40.4 46.9 53.4 59.6 66.5 60.4 59.2 51.2 42.8 45.8

1935 40.0 42.6 43.5 47.1 50.0 60.5 64.6 64.0 56.8 48.6 44.2 36.4

1936 37.3 35.0 44.0 43.9 52.7 58.6 60.0 61.1 58.1 49.6 41.6 41.3

1937 40.8 41.0 38.4 47.4 54.1 58.6 61.4 61.8 56.3 50.9 41.4 37.1

1938 42.1 41.2 47.3 46.6 52.4 59.0 59.6 60.4 57.0 50.7 47.8 39.2

1939 39.4 40.9 42.4 47.8 52.4 58.0 60.7 61.8 58.2 46.7 46.6 37.8

$seasonal

Jan Feb Mar Apr May Jun

1920 -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132

1921 -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132

1922 -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132

1923 -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132

1924 -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132

1925 -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132

1926 -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132

1927 -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132

1928 -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132

1929 -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132

1930 -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132

1931 -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132

1932 -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132

1933 -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132

1934 -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132

1935 -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132

1936 -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132

1937 -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132

1938 -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132

1939 -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132

Jul Aug Sep Oct Nov Dec

1920 12.9672149 11.4591009 7.4001096 0.6547149 -6.6176535 -9.3601974

1921 12.9672149 11.4591009 7.4001096 0.6547149 -6.6176535 -9.3601974

1922 12.9672149 11.4591009 7.4001096 0.6547149 -6.6176535 -9.3601974

18

AIMS-TANZANIA Susanna

1923 12.9672149 11.4591009 7.4001096 0.6547149 -6.6176535 -9.3601974

1924 12.9672149 11.4591009 7.4001096 0.6547149 -6.6176535 -9.3601974

1925 12.9672149 11.4591009 7.4001096 0.6547149 -6.6176535 -9.3601974

1926 12.9672149 11.4591009 7.4001096 0.6547149 -6.6176535 -9.3601974

1927 12.9672149 11.4591009 7.4001096 0.6547149 -6.6176535 -9.3601974

1928 12.9672149 11.4591009 7.4001096 0.6547149 -6.6176535 -9.3601974

1929 12.9672149 11.4591009 7.4001096 0.6547149 -6.6176535 -9.3601974

1930 12.9672149 11.4591009 7.4001096 0.6547149 -6.6176535 -9.3601974

1931 12.9672149 11.4591009 7.4001096 0.6547149 -6.6176535 -9.3601974

1932 12.9672149 11.4591009 7.4001096 0.6547149 -6.6176535 -9.3601974

1933 12.9672149 11.4591009 7.4001096 0.6547149 -6.6176535 -9.3601974

1934 12.9672149 11.4591009 7.4001096 0.6547149 -6.6176535 -9.3601974

1935 12.9672149 11.4591009 7.4001096 0.6547149 -6.6176535 -9.3601974

1936 12.9672149 11.4591009 7.4001096 0.6547149 -6.6176535 -9.3601974

1937 12.9672149 11.4591009 7.4001096 0.6547149 -6.6176535 -9.3601974

1938 12.9672149 11.4591009 7.4001096 0.6547149 -6.6176535 -9.3601974

1939 12.9672149 11.4591009 7.4001096 0.6547149 -6.6176535 -9.3601974

$trend

Jan Feb Mar Apr May Jun

1920 NA NA NA NA NA NA

1921 49.56667 50.07083 50.32917 50.59583 50.61667 50.60833

1922 48.87083 48.24167 47.89583 47.48750 47.27917 47.32083

1923 47.68333 48.21250 48.43750 48.52917 48.38750 47.98750

1924 47.59167 47.39167 47.41667 47.52500 47.88750 48.47500

1925 49.51250 49.74167 49.71667 49.58333 49.32917 48.76250

1926 48.64167 48.64167 48.87083 48.92083 48.92917 49.22083

1927 48.83750 48.68750 48.50833 48.54167 48.72083 48.55833

1928 48.63333 48.70833 48.73750 48.76250 48.78750 48.90417

1929 47.47917 47.48333 47.65833 47.80000 47.75417 47.94167

1930 49.48333 49.43750 49.37500 49.32917 49.40417 49.27917

1931 48.66250 48.54167 48.26667 47.95417 47.87917 48.05833

1932 48.30417 48.58750 48.91250 49.04583 48.99583 48.96667

1933 50.00000 50.20000 50.41667 50.69583 50.75417 50.44167

1934 49.75000 49.60417 49.37917 49.38333 49.45417 49.90000

1935 50.72083 50.79167 50.84167 50.63333 50.58333 50.25000

1936 48.65000 48.33750 48.27083 48.36667 48.30000 48.39583

1937 49.39167 49.47917 49.43333 49.41250 49.45833 49.27500

1938 49.71667 49.58333 49.55417 49.57500 49.83333 50.18750

1939 49.67917 49.78333 49.89167 49.77500 49.55833 49.45000

Jul Aug Sep Oct Nov Dec

1920 49.04167 49.15000 49.13750 49.17917 49.19167 49.20000

1921 50.45417 50.12917 49.85000 49.41250 49.27500 49.30417

1922 47.45417 47.69167 47.89167 48.18750 48.07083 47.58750

1923 47.71250 47.50000 47.20000 46.99583 47.15000 47.52500

1924 48.75417 48.90833 49.13750 49.22500 49.23333 49.32917

1925 48.42500 48.51250 48.74167 49.00833 49.03333 48.79167

1926 49.37500 49.17917 49.05417 49.05833 49.02917 49.00000

1927 48.42500 48.59167 48.59583 48.50000 48.47500 48.50000

1928 48.74167 48.08333 47.60000 47.38333 47.33333 47.44583

1929 48.41667 48.94167 49.19167 49.32500 49.37083 49.43750

1930 48.96250 48.82917 48.76667 48.63333 48.71250 48.72500

1931 48.35417 48.57500 48.65417 48.65417 48.46667 48.30000

1932 48.75833 48.53750 48.75000 49.09583 49.40417 49.70000

1933 50.32500 50.41250 50.19583 49.95000 49.84167 49.75833

19

AIMS-TANZANIA Susanna

1934 50.34167 50.55000 50.86250 51.00000 50.86667 50.76250

1935 49.74583 49.31667 49.02083 48.90833 48.88750 48.92083

1936 48.74583 49.14167 49.15833 49.07083 49.27500 49.33333

1937 49.15417 49.21667 49.59583 49.93333 49.82917 49.77500

1938 50.16250 50.03750 49.82083 49.66667 49.71667 49.67500

1939 NA NA NA NA NA NA

$random

Jan Feb Mar Apr May Jun Jul

1920 NA NA NA NA NA NA -4.308881579

1921 3.972697368 -0.370942982 1.717434211 -0.838486842 0.029934211 -0.894846491 2.878618421

1922 -2.031469298 0.358223684 -1.449232456 -2.630153509 4.967434211 1.492653509 -3.621381579

1923 3.456030702 1.787390351 1.409100877 0.028179825 -2.640899123 -4.274013158 3.520285088

1924 1.047697368 0.008223684 -2.170065789 0.732346491 1.859100877 0.238486842 -0.921381579

1925 -0.173135965 0.658223684 -1.970065789 -1.725986842 1.017434211 1.650986842 2.107785088

1926 -0.102302632 4.658223684 1.475767544 2.736513158 -1.782565789 -1.407346491 0.157785088

1927 -0.098135965 -0.287609649 3.738267544 1.315679825 -0.474232456 -2.544846491 -0.992214912

1928 1.506030702 2.291557018 1.009100877 1.294846491 -1.340899123 -1.490679825 0.491118421

1929 -3.339802632 -6.283442982 0.288267544 -1.142653509 1.892434211 -0.028179825 1.116118421

1930 1.456030702 -2.437609649 -1.228399123 0.328179825 -1.657565789 2.134320175 -1.829714912

1931 -2.223135965 -0.241776316 -2.920065789 1.303179825 2.167434211 1.355153509 -0.721381579

1932 3.435197368 -0.287609649 -1.665899123 -1.688486842 -1.549232456 -0.953179825 0.374451754

1933 -4.460635965 -1.000109649 1.029934211 0.761513158 -0.007565789 1.371820175 2.207785088

1934 -1.010635965 -1.504276316 -2.032565789 0.274013158 0.492434211 0.713486842 3.191118421

1935 -1.381469298 1.708223684 -0.395065789 -0.775986842 -4.036732456 1.263486842 1.886951754

1936 -2.010635965 -3.437609649 2.675767544 -1.709320175 0.946600877 1.217653509 -1.713048246

1937 0.747697368 1.420723684 -4.086732456 0.744846491 1.188267544 0.338486842 -0.721381579

1938 1.722697368 1.516557018 4.692434211 -0.217653509 -0.886732456 -0.174013158 -3.529714912

1939 -0.939802632 1.016557018 -0.545065789 0.782346491 -0.611732456 -0.436513158 NA

Aug Sep Oct Nov Dec

1920 -4.209100877 -2.237609649 0.666118421 0.325986842 -0.039802632

1921 -1.688267544 -0.250109649 4.132785088 -2.957346491 2.856030702

1922 -4.850767544 -0.991776316 -1.742214912 0.346820175 3.472697368

1923 0.640899123 -0.200109649 1.549451754 -4.232346491 -0.564802632

1924 -2.167434211 -0.137609649 -0.079714912 1.784320175 3.631030702

1925 1.028399123 -3.141776316 0.336951754 -4.315679825 -3.131469298

1926 1.361732456 1.045723684 -3.013048246 -0.811513158 0.160197368

1927 0.449232456 -1.295942982 1.145285088 0.442653509 -3.939802632

1928 0.957565789 0.399890351 2.161951754 2.284320175 -0.785635965

1929 -0.100767544 3.208223684 -0.779714912 0.146820175 1.822697368

1930 1.311732456 0.833223684 1.611951754 0.905153509 -0.564802632

1931 -1.834100877 -2.254276316 -2.708881579 3.650986842 1.660197368

1932 3.503399123 0.149890351 -2.450548246 0.813486842 1.460197368

1933 3.028399123 2.504057018 -0.404714912 -1.124013158 -4.598135965

1934 -1.609100877 0.937390351 -0.454714912 -1.449013158 4.397697368

1935 3.224232456 0.379057018 -0.963048246 1.930153509 -3.160635965

1936 0.499232456 1.541557018 -0.125548246 -1.057346491 1.326864035

1937 1.124232456 -0.695942982 0.311951754 -1.811513158 -3.314802632

1938 -1.096600877 -0.220942982 0.378618421 4.700986842 -1.114802632

1939 NA NA NA NA NA

$figure

[1] -9.3393640 -9.8998904 -6.9466009 -2.7573465 3.4533991 8.9865132 12.9672149 11.4591009

[9] 7.4001096 0.6547149 -6.6176535 -9.3601974

20

AIMS-TANZANIA Susanna

$type

[1] "additive"

attr(,"class")

[1] "decomposed.ts"

This is the predicted values of Arima Model for 1940 to 1944.

Point Forecast Lo 80 Hi 80 Lo 95 Hi 95

Jan 1940 41.49586 38.69379 44.50085 37.28788 46.17871

Feb 1940 41.48327 38.53720 44.65455 37.06331 46.43032

Mar 1940 45.91116 42.63350 49.44080 40.99423 51.41784

Apr 1940 47.06976 43.70747 50.69072 42.02591 52.71897

May 1940 52.17338 48.44628 56.18722 46.58230 58.43554

Jun 1940 58.03614 53.89020 62.50104 51.81674 65.00204

Jul 1940 59.18699 54.95883 63.74043 52.84425 66.29102

Aug 1940 60.01202 55.72492 64.62894 53.58087 67.21508

Sep 1940 56.80190 52.74413 61.17186 50.71476 63.61966

Oct 1940 49.40999 45.88027 53.21126 44.11500 55.34052

Nov 1940 47.51815 44.12358 51.17388 42.42590 53.22161

Dec 1940 39.32293 36.51380 42.34817 35.10891 44.04274

Jan 1941 40.52121 37.52678 43.75459 36.03226 45.56940

Feb 1941 41.51753 38.43844 44.84326 36.90202 46.71032

Mar 1941 43.75649 40.51008 47.26307 38.89020 49.23170

Apr 1941 47.65476 44.11897 51.47391 42.35470 53.61804

May 1941 52.11164 48.24515 56.28800 46.31587 58.63267

Jun 1941 57.40378 53.14463 62.00427 51.01943 64.58705

Jul 1941 59.46663 55.05442 64.23244 52.85284 66.90803

Aug 1941 60.40635 55.92442 65.24747 53.68805 67.96535

Sep 1941 57.17999 52.93744 61.76254 50.82052 64.33525

Oct 1941 47.59273 44.06152 51.40693 42.29954 53.54828

Nov 1941 46.99815 43.51106 50.76470 41.77109 52.87930

Dec 1941 38.83746 35.95587 41.95000 34.51802 43.69742

Jan 1942 41.63065 37.94785 45.67085 36.13207 47.96599

Feb 1942 41.91276 38.14565 46.05189 36.29053 48.40600

Mar 1942 45.45801 41.36524 49.95574 39.35000 52.51413

Apr 1942 47.34559 43.08206 52.03105 40.98278 54.69626

May 1942 51.94689 47.26892 57.08782 44.96557 60.01213

Jun 1942 57.24734 52.09203 62.91285 49.55365 66.13555

Jul 1942 58.57430 53.29949 64.37113 50.70227 67.66853

Aug 1942 59.37152 54.02492 65.24725 51.39235 68.58954

Sep 1942 56.38701 51.30918 61.96738 48.80894 65.14165

Oct 1942 48.85014 44.45102 53.68461 42.28498 56.43460

Nov 1942 47.45056 43.17748 52.14653 41.07350 54.81773

Dec 1942 39.70987 36.13386 43.63977 34.37310 45.87521

Jan 1943 41.30817 37.43838 45.57796 35.53882 48.01412

Feb 1943 42.04920 38.09359 46.41556 36.15255 48.90763

Mar 1943 44.53818 40.34652 49.16532 38.28972 51.80632

Apr 1943 47.63983 43.15604 52.58948 40.95591 55.41457

May 1943 51.85976 46.97877 57.24788 44.58373 60.32323

Jun 1943 56.79524 51.44972 62.69615 48.82675 66.06418

Jul 1943 58.50101 52.99495 64.57915 50.29320 68.04834

Aug 1943 59.33162 53.74737 65.49605 51.00726 69.01449

Sep 1943 56.40570 51.09685 62.26614 48.49187 65.61108

Oct 1943 48.02745 43.50714 53.01740 41.28910 55.86549

Nov 1943 47.24049 42.79425 52.14868 40.61255 54.95010

21

AIMS-TANZANIA Susanna

Dec 1943 39.64055 35.90962 43.75913 34.07890 46.10986

Jan 1944 41.94911 37.68552 46.69506 35.60684 49.42105

Feb 1944 42.34930 38.01162 47.18198 35.89824 49.95965

Mar 1944 45.39425 40.74075 50.57928 38.47367 53.55968

Apr 1944 47.52215 42.65007 52.95080 40.27652 56.07126

May 1944 51.72788 46.42455 57.63702 43.84092 61.03369

Jun 1944 56.56570 50.76638 63.02751 47.94111 66.74185

Jul 1944 57.90604 51.96931 64.52097 49.07709 68.32332

Aug 1944 58.65521 52.64167 65.35572 49.71203 69.20726

Sep 1944 55.89942 50.16841 62.28512 47.37642 65.95571

Oct 1944 48.61465 43.63050 54.16817 41.20236 57.36041

Nov 1944 47.47635 42.60890 52.89983 40.23762 56.01733

Dec 1944 40.19914 36.07778 44.79131 34.06997 47.43095

This is the predicted values of Arima and Regression Model for 1940 to 1944

Point Forecast Lo 80 Hi 80 Lo 95 Hi 95

Jan 1940 41.49586 38.69379 44.50085 37.28788 46.17871

Feb 1940 41.48327 38.53720 44.65455 37.06331 46.43032

Mar 1940 45.91116 42.63350 49.44080 40.99423 51.41784

Apr 1940 47.06976 43.70747 50.69072 42.02591 52.71897

May 1940 52.17338 48.44628 56.18722 46.58230 58.43554

Jun 1940 58.03614 53.89020 62.50104 51.81674 65.00204

Jul 1940 59.18699 54.95883 63.74043 52.84425 66.29102

Aug 1940 60.01202 55.72492 64.62894 53.58087 67.21508

Sep 1940 56.80190 52.74413 61.17186 50.71476 63.61966

Oct 1940 49.40999 45.88027 53.21126 44.11500 55.34052

Nov 1940 47.51815 44.12358 51.17388 42.42590 53.22161

Dec 1940 39.32293 36.51380 42.34817 35.10891 44.04274

Jan 1941 40.52121 37.52678 43.75459 36.03226 45.56940

Feb 1941 41.51753 38.43844 44.84326 36.90202 46.71032

Mar 1941 43.75649 40.51008 47.26307 38.89020 49.23170

Apr 1941 47.65476 44.11897 51.47391 42.35470 53.61804

May 1941 52.11164 48.24515 56.28800 46.31587 58.63267

Jun 1941 57.40378 53.14463 62.00427 51.01943 64.58705

Jul 1941 59.46663 55.05442 64.23244 52.85284 66.90803

Aug 1941 60.40635 55.92442 65.24747 53.68805 67.96535

Sep 1941 57.17999 52.93744 61.76254 50.82052 64.33525

Oct 1941 47.59273 44.06152 51.40693 42.29954 53.54828

Nov 1941 46.99815 43.51106 50.76470 41.77109 52.87930

Dec 1941 38.83746 35.95587 41.95000 34.51802 43.69742

Jan 1942 41.63065 37.94785 45.67085 36.13207 47.96599

Feb 1942 41.91276 38.14565 46.05189 36.29053 48.40600

Mar 1942 45.45801 41.36524 49.95574 39.35000 52.51413

Apr 1942 47.34559 43.08206 52.03105 40.98278 54.69626

May 1942 51.94689 47.26892 57.08782 44.96557 60.01213

Jun 1942 57.24734 52.09203 62.91285 49.55365 66.13555

Jul 1942 58.57430 53.29949 64.37113 50.70227 67.66853

Aug 1942 59.37152 54.02492 65.24725 51.39235 68.58954

Sep 1942 56.38701 51.30918 61.96738 48.80894 65.14165

Oct 1942 48.85014 44.45102 53.68461 42.28498 56.43460

Nov 1942 47.45056 43.17748 52.14653 41.07350 54.81773

Dec 1942 39.70987 36.13386 43.63977 34.37310 45.87521

Jan 1943 41.30817 37.43838 45.57796 35.53882 48.01412

Feb 1943 42.04920 38.09359 46.41556 36.15255 48.90763

Mar 1943 44.53818 40.34652 49.16532 38.28972 51.80632

22

AIMS-TANZANIA Susanna

Apr 1943 47.63983 43.15604 52.58948 40.95591 55.41457

May 1943 51.85976 46.97877 57.24788 44.58373 60.32323

Jun 1943 56.79524 51.44972 62.69615 48.82675 66.06418

Jul 1943 58.50101 52.99495 64.57915 50.29320 68.04834

Aug 1943 59.33162 53.74737 65.49605 51.00726 69.01449

Sep 1943 56.40570 51.09685 62.26614 48.49187 65.61108

Oct 1943 48.02745 43.50714 53.01740 41.28910 55.86549

Nov 1943 47.24049 42.79425 52.14868 40.61255 54.95010

Dec 1943 39.64055 35.90962 43.75913 34.07890 46.10986

Jan 1944 41.94911 37.68552 46.69506 35.60684 49.42105

Feb 1944 42.34930 38.01162 47.18198 35.89824 49.95965

Mar 1944 45.39425 40.74075 50.57928 38.47367 53.55968

Apr 1944 47.52215 42.65007 52.95080 40.27652 56.07126

May 1944 51.72788 46.42455 57.63702 43.84092 61.03369

Jun 1944 56.56570 50.76638 63.02751 47.94111 66.74185

Jul 1944 57.90604 51.96931 64.52097 49.07709 68.32332

Aug 1944 58.65521 52.64167 65.35572 49.71203 69.20726

Sep 1944 55.89942 50.16841 62.28512 47.37642 65.95571

Oct 1944 48.61465 43.63050 54.16817 41.20236 57.36041

Nov 1944 47.47635 42.60890 52.89983 40.23762 56.01733

Dec 1944 40.19914 36.07778 44.79131 34.06997 47.43095

Appendix 2

#####################################################################################

########################### NOTTEM DATA ANALYSIS ####################################

############ READING FROM ’nottem.csv’

#***************************#Reading the file#***************************************

nottem1 = read.csv("nottem.csv", header=TRUE)

#***************************#Display of Data#****************************************

#fix(nottem)

nottem1

############ USING NOTTEM DATASET IN R

rm(nottem)

nottem

#fix(nottem)

nottem2 =xtable(nottem)

nottem2

dim(nottem2)

#*************************#Length, Dim, Names#***************************************

length(nottem)

dim(nottem)

names(nottem)

########################## #DESCRIPTIVE STATISTICS

#***************************#Descriptive Statistics#*************************************

#Computations

n = summary(nottem2)

n = xtable(n)

23

AIMS-TANZANIA Susanna

n

########################## #Figures- Boxplot, Histogram, QQplot

#***************************#Boxplot#*************************************

par(mfrow=c(1, 1))

#boxplot(nottem, main="Box Plot of Nottem",ylab="Frequency", col=2)

boxplot(nottem , data=nottem , main=toupper("Box Plot of Nottem"),

font.main=3, cex.main=1, xlab="",

ylab="Nottem Frequancy", font.lab=3, col="red")

#***********************#Histograms with Normal Curves#******************************

#hist(nottem)

nottem <- nottem

m<-mean(nottem)

std<-sqrt(var(nottem))

hist(nottem, density=20, breaks=50, col="red", prob=TRUE,

xlab="nottem", ylim=c(0, 0.07),

main="HISTOGRAM OF NOTTEM",cex.main=1)

curve(dnorm(x, mean=m, sd=std),

col="blue", lwd=2, add=TRUE, yaxt="n")

#***********************#QQ-Plots#*****************************

#qq plot(nottem)

qqnorm(nottem, col="darkgreen" , main="NORMAL Q-Q PLOT OF NOTTEM",cex.main=1)

#qqline(nottem ,col="blue")

qqline(nottem, col = ’darkred’,lwd=2,lty=2)

#**********************#General Plot#******************************

plot(nottem, col = ’darkgreen’,lwd=2,lty=1, main="PLOT OF NOTTEM",cex.main=1)

###################### Beginning Time Series Analysis

nottemtimeseries = ts(nottem, frequency=12, start=c(1920,1))

nt = xtable(nottemtimeseries)

nt

#**********************#Plot of Timeserires#****************************

plot(nottemtimeseries, col = ’darkviolet’,lwd=2,lty=1, main="TIME SERIES PLOT OF NOTTEM",cex.main=1)

plot.ts(nottem, col = ’darkviolet’,lwd=2,lty=1, main="TIME SERIES PLOT OF NOTTEM",cex.main=1)

################## DECOMPOSITION

#normal

nottemdecompose = decompose(nottem)

nottemdecompose

plot(nottemdecompose, col=10)

#log

nottemdecomposelog = decompose(log(nottem))

nottemdecomposelog

plot(nottemdecomposelog, col=3)

#sqrt

nottemdecomposesqrt = decompose(sqrt(nottem))

nottemdecomposesqrt

plot(nottemdecomposesqrt, col=4)

24

AIMS-TANZANIA Susanna

################## ACF Squareroot

#nottem

nottem

nottemtimeseries

acf(nottemtimeseries, lag.max=12) # plot a correlogram

acf(nottemtimeseries,lag.max=12, plot=FALSE)

################## PACF

#nottem

pacf(nottemtimeseries, lag.max=20) # plot a correlogram

pacf(nottemtimeseries, lag.max=20, plot=FALSE)

################## AUTO ARIMA

library("forecast")

a = auto.arima(nottemtimeseries)

a

a = auto.arima(nottem)

a

################## ARIMA

Model1 = arima(nottemtimeseries,order=c(1,0,0),seasonal=list(order=c(2,0,0), period = 12))

Model1

################## VERIFICATION

#**********************#tsdiag(Model1)#****************************

tsdiag(Model1)

arima(nottemtimeseries,order=c(1,0,0),seasonal=list(order=c(2,0,0),period=12))

fit <- Arima(nottemtimeseries, order=c(1,0,0), seasonal=c(2,0,0), lambda=0)

plot(forecast(fit,h=60), ylab="nottem", xlab="Year",col=’Darkred’)

############## Forecasts using Exponential Smoothing

#Exponential smoothing can be used to make short-term forecasts for time series data.

##########################################################################################

############## nottem Exponential Smoothing

ts.iesforecasts2$residuals, lag=20, type="Ljung-Box")

#nottem

#Gives alpha beta gamma.

nottemtimeseriesforecasts <- Arima(nottemtimeseries, order=c(1,0,0), seasonal=c(2,0,0), lambda=0)

nottemtimeseriesforecasts

#SSE

nottemtimeseriesforecasts$SSE

#PLOT

plot(nottemtimeseriesforecasts)

#FUTURE FORECAST

nottemtimeseriesforecasts2 <- forecast.Arima(nottemtimeseriesforecasts, h=60)

nottemtimeseriesforecasts2

25

AIMS-TANZANIA Susanna

#PLOT

plot.forecast(nottemtimeseriesforecasts2)

#THE TIME PLOT

plot.ts(nottemtimeseriesforecasts2$residuals, ylab="nottemtimeseriesforecasts$residuals"

, xlab="Year",col=’darkviolet’,lwd=2,lty=1, main="Plot of Residuals of Timeseries Forecast",cex.main=1)

#THE HISTOGRAM

plotForecastErrors <- function(forecasterrors)

{

# make a histogram of the forecast errors:

mybinsize <- IQR(forecasterrors)/4

mysd <- sd(forecasterrors)

mymin <- min(forecasterrors) - mysd*5

mymax <- max(forecasterrors) + mysd*3

# generate normally distributed data with mean 0 and standard deviation mysd

mynorm <- rnorm(10000, mean=0, sd=mysd)

mymin2 <- min(mynorm)

mymax2 <- max(mynorm)

if (mymin2 < mymin) { mymin <- mymin2 }

if (mymax2 > mymax) { mymax <- mymax2 }

# make a red histogram of the forecast errors, with the normally distributed data overlaid:

mybins <- seq(mymin, mymax, mybinsize)

hist(forecasterrors, col="darkblue", freq=FALSE, breaks=mybins)

# freq=FALSE ensures the area under the histogram = 1

# generate normally distributed data with mean 0 and standard deviation mysd

myhist <- hist(mynorm, plot=FALSE, breaks=mybins)

# plot the normal curve as a blue line on top of the histogram of forecast errors:

points(myhist$mids, myhist$density, type="l", col="red", lwd=3)

}

plotForecastErrors(nottemtimeseriesforecasts2$residuals)

################## REGRESSION + ARIMA

#Adding Sequence

D=seq(1,240,1)/12

D1=D^2

A=arima(nottemtimeseries,order=c(2,0,0),seasonal=list(order=c(1,0,0),

period=12),xreg=cbind(D,D1))

A

tsdiag(A)

################## VERIFICATION

#**********************#tsdiag(Model1)#****************************

tsdiag(a)

arima(nottemtimeseries,order=c(2,0,0),seasonal=list(order=c(1,0,0)

,period=12),xreg=cbind(D,D1))

fit <- Arima(nottemtimeseries, order=c(1,0,0), seasonal=c(2,0,0), xreg=cbind(D,D1),lambda=0)

plot(forecast(fit,h=60), ylab="nottem", xlab="Year",col=’Darkred’)

############## Forecasts using Exponential Smoothing

#Exponential smoothing can be used to make short-term forecasts for time series data.

26

AIMS-TANZANIA Susanna

##########################################################################################

############## nottem Exponential Smoothing

#nottem

#Gives alpha beta gamma.

nottemtimeseriesforecasts <- Arima(nottemtimeseries, order=c(1,0,0), seasonal=c(2,0,0), xreg=cbind(D,D1),lambda=0)

nottemtimeseriesforecasts

#SSE

nottemtimeseriesforecasts$SSE

#PLOT

plot(nottemtimeseriesforecasts)

#FUTURE FORECAST

#PLOT

plot.forecast(nottemtimeseriesforecasts2, col=2)

#THE TIME PLOT

plot.ts(nottemtimeseriesforecasts2$residuals, ylab="nottemtimeseriesforecasts$residuals"

, xlab="Year",col=’darkviolet’,lwd=2,lty=1,

main="Plot of Residuals of Timeseries Forecast for Arima and Regressive Model",

cex.main=1)

#THE HISTOGRAM

plotForecastErrors <- function(forecasterrors)

{

# make a histogram of the forecast errors:

mybinsize <- IQR(forecasterrors)/4

mysd <- sd(forecasterrors)

mymin <- min(forecasterrors) - mysd*5

mymax <- max(forecasterrors) + mysd*3

# generate normally distributed data with mean 0 and standard deviation mysd

mynorm <- rnorm(10000, mean=0, sd=mysd)

mymin2 <- min(mynorm)

mymax2 <- max(mynorm)

if (mymin2 < mymin) { mymin <- mymin2 }

if (mymax2 > mymax) { mymax <- mymax2 }

# make a red histogram of the forecast errors, with the normally distributed data overlaid:

mybins <- seq(mymin, mymax, mybinsize)

hist(forecasterrors, col="red", freq=FALSE, breaks=mybins)

# freq=FALSE ensures the area under the histogram = 1

# generate normally distributed data with mean 0 and standard deviation mysd

myhist <- hist(mynorm, plot=FALSE, breaks=mybins)

# plot the normal curve as a blue line on top of the histogram of forecast errors:

points(myhist$mids, myhist$density, type="l", col="darkblue", lwd=3)

}

plotForecastErrors(nottemtimeseriesforecasts2$residuals)

27


Recommended