Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre1.8.0_144')
library(tseries)
library(forecast)
library(urca) 

Question 1: Describe a situation or problem from your job, everyday life, current events, etc., for which exponential smoothing would be appropriate. What data would you need? Would you expect the value of ?? (the first smoothing parameter) to be closer to 0 or 1, and why

As a not so rich home owner, I would want to study the impact and benefits of subscribing to a HVAC maintenance program with respect to savings in electricity costs. For every home included in the analysis, I would record the electricity usage every month. Some homes will get the maintenance every 3 months, some every 6 months, some every 9 months and other never.

We could build an exponential soothing model, with monthly electricity usage as the value being analyzed. It would include cyclic effects (3,6,9,12 months etc) and the trend would demonstrate how electricity usage increases over time.

Question 6.1: Describe a situation or problem from your job, everyday life, current events, etc., for which a Change Detection model would be appropriate. Applying the CUSUM technique, how would you choose the critical value and the threshold?

temp_df = read.table("C:\\Users\\vabhagat\\Downloads\\temps.txt", header= TRUE, stringsAsFactors = F) 
head(temp_df)
summary( temp_df )
##      DAY                X1996           X1997           X1998      
##  Length:123         Min.   :60.00   Min.   :55.00   Min.   :63.00  
##  Class :character   1st Qu.:79.00   1st Qu.:78.50   1st Qu.:79.50  
##  Mode  :character   Median :84.00   Median :84.00   Median :86.00  
##                     Mean   :83.72   Mean   :81.67   Mean   :84.26  
##                     3rd Qu.:90.00   3rd Qu.:88.50   3rd Qu.:89.00  
##                     Max.   :99.00   Max.   :95.00   Max.   :95.00  
##      X1999           X2000            X2001           X2002      
##  Min.   :57.00   Min.   : 55.00   Min.   :51.00   Min.   :57.00  
##  1st Qu.:75.00   1st Qu.: 77.00   1st Qu.:78.00   1st Qu.:78.00  
##  Median :86.00   Median : 86.00   Median :84.00   Median :87.00  
##  Mean   :83.36   Mean   : 84.03   Mean   :81.55   Mean   :83.59  
##  3rd Qu.:91.00   3rd Qu.: 91.00   3rd Qu.:87.00   3rd Qu.:91.00  
##  Max.   :99.00   Max.   :101.00   Max.   :93.00   Max.   :97.00  
##      X2003           X2004           X2005           X2006      
##  Min.   :57.00   Min.   :62.00   Min.   :54.00   Min.   :53.00  
##  1st Qu.:78.00   1st Qu.:78.00   1st Qu.:81.50   1st Qu.:79.00  
##  Median :84.00   Median :82.00   Median :85.00   Median :85.00  
##  Mean   :81.48   Mean   :81.76   Mean   :83.36   Mean   :83.05  
##  3rd Qu.:87.00   3rd Qu.:87.00   3rd Qu.:88.00   3rd Qu.:91.00  
##  Max.   :91.00   Max.   :95.00   Max.   :94.00   Max.   :98.00  
##      X2007           X2008           X2009           X2010      
##  Min.   : 59.0   Min.   :50.00   Min.   :51.00   Min.   :67.00  
##  1st Qu.: 81.0   1st Qu.:79.50   1st Qu.:75.00   1st Qu.:82.00  
##  Median : 86.0   Median :85.00   Median :83.00   Median :90.00  
##  Mean   : 85.4   Mean   :82.51   Mean   :80.99   Mean   :87.21  
##  3rd Qu.: 89.5   3rd Qu.:88.50   3rd Qu.:88.00   3rd Qu.:93.00  
##  Max.   :104.0   Max.   :95.00   Max.   :95.00   Max.   :97.00  
##      X2011           X2012            X2013           X2014      
##  Min.   :59.00   Min.   : 56.00   Min.   :56.00   Min.   :63.00  
##  1st Qu.:79.00   1st Qu.: 79.50   1st Qu.:77.00   1st Qu.:81.50  
##  Median :89.00   Median : 85.00   Median :84.00   Median :86.00  
##  Mean   :85.28   Mean   : 84.65   Mean   :81.67   Mean   :83.94  
##  3rd Qu.:94.00   3rd Qu.: 90.50   3rd Qu.:88.00   3rd Qu.:89.00  
##  Max.   :99.00   Max.   :105.00   Max.   :92.00   Max.   :95.00  
##      X2015     
##  Min.   :56.0  
##  1st Qu.:77.0  
##  Median :85.0  
##  Mean   :83.3  
##  3rd Qu.:90.0  
##  Max.   :97.0
#Plotting timeseries

temp_series = as.vector( unlist( temp_df[ , 2:21 ] ) )
temp_series = ts( temp_series, start = 1996, frequency = 123 )
plot.ts( temp_series )

#Running Holt-Winters. Not specifying alpha/gamma, but specifying beta to generate a trend value that will allow to forecast a future trend.

temp_HW_model= HoltWinters( temp_series, beta = 0.05 )
#Plotting moder
plot(temp_HW_model)

# Checking SSE:
temp_HW_model$SSE
## [1] 71099.09
#Fitting model

seasonal_temp = temp_HW_model$fitted
plot( seasonal_temp )

#Forecast

temp_forecast=predict( temp_HW_model, n.ahead = 100, prediction.interval = TRUE )
plot(forecast( temp_HW_model, h = 180 ))

The above plot reflects the actual forecast in dark blue, along with the 80% and 90% condidence intervals where 90% is illustrated in the lightest shade of blue. We extrapolate our prediction out to 180 days in order to see a clearer illustration of our forecast’s cyclicality.

#Dump data for CUSUM 
seasonal_temp = data.frame( temp_df$DAY, seasonal_temp )
write.csv( seasonal_temp, file = "seasonal_data.csv" )

Used St = max( 0, St-1 + ( ?? - T - C)) as a running equation across each daily temprature observation. Ploting the control chart indicated there wasn’t much of a chnage.

A caption

A caption