jlivsey / UB-sping24-time-series

2 stars 1 forks source link

Akshaya Peduru #34

Open Akshayapeduru opened 7 months ago

Akshayapeduru commented 7 months ago

HW_1_ICNSA.pdf So I forecast the new data release value will be 339658.3 with confidence interval (102326.4, 576990.2)

jlivsey commented 7 months ago

Please note this does not satisfy the criteria. Specifically that part that says "results visable without downloading"

Akshayapeduru commented 7 months ago

please let me know if i need to upload ipynb file along with the pdf in brightspace.

Akshayapeduru commented 7 months ago

Multiplicative Model - 279634.5811 HW2f- ICNSA_akshayap.pdf

Akshayapeduru commented 6 months ago

Forecast value:369548.6 HW3- akshayap - ICNSA Forecast.pdf

Akshayapeduru commented 5 months ago
library(forecast)
#> Warning: package 'forecast' was built under R version 4.2.3
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo
library(vars)
#> Warning: package 'vars' was built under R version 4.2.3
#> Loading required package: MASS
#> Loading required package: strucchange
#> Loading required package: zoo
#> 
#> Attaching package: 'zoo'
#> The following objects are masked from 'package:base':
#> 
#>     as.Date, as.Date.numeric
#> Loading required package: sandwich
#> Loading required package: urca
#> Loading required package: lmtest
library(tseries)
library(readxl)
library(ggplot2)

All_Houses <- read.csv("/Users/akshayapeduru/Downloads/All_Houses.csv", skip = 7)
print(head(All_Houses))
#>     Period Value
#> 1 Jan-1963   591
#> 2 Feb-1963   464
#> 3 Mar-1963   461
#> 4 Apr-1963   605
#> 5 May-1963   586
#> 6 Jun-1963   526

Houses_Not_Started <- read.csv("/Users/akshayapeduru/Downloads/Houses_Not_Started.csv", skip = 7)
print(head(Houses_Not_Started))
#>     Period Value
#> 1 Jan-1963    NA
#> 2 Feb-1963    NA
#> 3 Mar-1963    NA
#> 4 Apr-1963    NA
#> 5 May-1963    NA
#> 6 Jun-1963    NA

Houses_Under_Construction <- read.csv("/Users/akshayapeduru/Downloads/Houses_Under_Construction.csv", skip = 7)
print(head(Houses_Under_Construction))
#>     Period Value
#> 1 Jan-1963    NA
#> 2 Feb-1963    NA
#> 3 Mar-1963    NA
#> 4 Apr-1963    NA
#> 5 May-1963    NA
#> 6 Jun-1963    NA

library(reprex)
library(BigVAR)
#> Loading required package: lattice
#> Warning: package 'lattice' was built under R version 4.2.3

Houses_Completed <- read.csv("/Users/akshayapeduru/Downloads/Houses_Completed.csv", skip = 7)
print(head(Houses_Completed))
#>     Period Value
#> 1 Jan-1963    NA
#> 2 Feb-1963    NA
#> 3 Mar-1963    NA
#> 4 Apr-1963    NA
#> 5 May-1963    NA
#> 6 Jun-1963    NA

All_Houses$Value <- as.numeric(as.character(All_Houses$Value))
sum(is.na(All_Houses$Value))
#> [1] 10

Houses_Not_Started$Value <- as.numeric(as.character(Houses_Not_Started$Value))
sum(is.na(Houses_Not_Started$Value))
#> [1] 442

Houses_Under_Construction$Value <- as.numeric(as.character(Houses_Under_Construction$Value))
sum(is.na(Houses_Under_Construction$Value))
#> [1] 442

Houses_Completed$Value <- as.numeric(as.character(Houses_Completed$Value))
sum(is.na(Houses_Completed$Value))
#> [1] 442

All_Houses <- All_Houses[!is.na(All_Houses$Value), ]
TSe_All_Houses <- ts(All_Houses$Value, start=c(1963, 1), frequency=12)
Houses_Not_Started <- Houses_Not_Started[!is.na(Houses_Not_Started$Value), ]
TSe_Houses_Not_Started <- ts(Houses_Not_Started$Value, start=c(1963, 1), frequency=12)
Houses_Under_Construction <- Houses_Under_Construction[!is.na(Houses_Under_Construction$Value), ]
TSe_Houses_Under_Construction <- ts(Houses_Under_Construction$Value, start=c(1963, 1), frequency=12)
Houses_Completed <- Houses_Completed[!is.na(Houses_Completed$Value), ]
TSe_Houses_Completed <- ts(Houses_Completed$Value, start=c(1963, 1), frequency=12)

plot(TSe_All_Houses, main="All Houses", xlab="Year", ylab="Houses Sold")

plot(TSe_Houses_Not_Started, main="Houses Not Started", xlab="Year", ylab="Houses Sold")

plot(TSe_Houses_Under_Construction, main="Houses Under Construction", xlab="Year", ylab="Houses Sold")

plot(TSe_Houses_Completed, main="Houses Completed", xlab="Year", ylab="Houses Sold")


D_All_Houses <- stl(TSe_All_Houses, s.window="periodic")
plot(D_All_Houses)


D_Houses_Not_Started <- stl(TSe_Houses_Not_Started, s.window="periodic")
plot(D_Houses_Not_Started)


D_Houses_Under_Construction <- stl(TSe_Houses_Under_Construction, s.window="periodic")
plot(D_Houses_Under_Construction)


D_Houses_Completed <- stl(TSe_Houses_Completed, s.window="periodic")
plot(D_Houses_Completed)


adf.test(TSe_All_Houses)
#> 
#>  Augmented Dickey-Fuller Test
#> 
#> data:  TSe_All_Houses
#> Dickey-Fuller = -2.3546, Lag order = 9, p-value = 0.4282
#> alternative hypothesis: stationary
adf.test(TSe_Houses_Not_Started)
#> 
#>  Augmented Dickey-Fuller Test
#> 
#> data:  TSe_Houses_Not_Started
#> Dickey-Fuller = -1.4368, Lag order = 6, p-value = 0.8137
#> alternative hypothesis: stationary
adf.test(TSe_Houses_Under_Construction)
#> 
#>  Augmented Dickey-Fuller Test
#> 
#> data:  TSe_Houses_Under_Construction
#> Dickey-Fuller = -1.2637, Lag order = 6, p-value = 0.8867
#> alternative hypothesis: stationary
adf.test(TSe_Houses_Completed)
#> 
#>  Augmented Dickey-Fuller Test
#> 
#> data:  TSe_Houses_Completed
#> Dickey-Fuller = -1.4675, Lag order = 6, p-value = 0.8008
#> alternative hypothesis: stationary

F_All_Houses <- auto.arima(TSe_All_Houses)
summary(F_All_Houses)
#> Series: TSe_All_Houses 
#> ARIMA(1,1,2)(1,0,2)[12] 
#> 
#> Coefficients:
#>           ar1     ma1      ma2    sar1     sma1     sma2
#>       -0.8634  0.6358  -0.2359  0.2948  -0.4085  -0.1094
#> s.e.   0.1052  0.1083   0.0378  0.2197   0.2194   0.0549
#> 
#> sigma^2 = 2190:  log likelihood = -3856.63
#> AIC=7727.26   AICc=7727.42   BIC=7759.44
#> 
#> Training set error measures:
#>                     ME     RMSE     MAE       MPE   MAPE      MASE
#> Training set 0.2624641 46.57831 35.8077 -0.408953 5.6687 0.3646529
#>                       ACF1
#> Training set -0.0001323341

F_Houses_Not_Started <- auto.arima(TSe_Houses_Not_Started)
summary(F_Houses_Not_Started)
#> Series: TSe_Houses_Not_Started 
#> ARIMA(0,1,1) 
#> 
#> Coefficients:
#>           ma1
#>       -0.2415
#> s.e.   0.0542
#> 
#> sigma^2 = 644.2:  log likelihood = -1400.07
#> AIC=2804.15   AICc=2804.19   BIC=2811.56
#> 
#> Training set error measures:
#>                     ME     RMSE      MAE       MPE     MAPE      MASE
#> Training set -1.066121 25.29757 18.18945 -1.515353 9.201286 0.3416855
#>                     ACF1
#> Training set -0.01204622

F_Houses_Under_Construction <- auto.arima(TSe_Houses_Under_Construction)
summary(F_Houses_Under_Construction)
#> Series: TSe_Houses_Under_Construction 
#> ARIMA(0,1,1) 
#> 
#> Coefficients:
#>           ma1
#>       -0.3882
#> s.e.   0.0521
#> 
#> sigma^2 = 694.5:  log likelihood = -1411.44
#> AIC=2826.87   AICc=2826.91   BIC=2834.29
#> 
#> Training set error measures:
#>                     ME     RMSE      MAE        MPE     MAPE      MASE
#> Training set -0.381581 26.26632 19.26672 -0.9068271 8.024289 0.4114394
#>                      ACF1
#> Training set -0.007683403

F_Houses_Completed <- auto.arima(TSe_Houses_Completed)
summary(F_Houses_Completed)
#> Series: TSe_Houses_Completed 
#> ARIMA(2,1,0) 
#> 
#> Coefficients:
#>           ar1      ar2
#>       -0.3933  -0.2526
#> s.e.   0.0558   0.0557
#> 
#> sigma^2 = 471.2:  log likelihood = -1352.57
#> AIC=2711.15   AICc=2711.23   BIC=2722.27
#> 
#> Training set error measures:
#>                     ME     RMSE      MAE       MPE     MAPE      MASE
#> Training set 0.5397674 21.59822 16.79712 -0.393783 7.574252 0.4767238
#>                     ACF1
#> Training set 0.008029448

checkresiduals(F_All_Houses)

#> 
#>  Ljung-Box test
#> 
#> data:  Residuals from ARIMA(1,1,2)(1,0,2)[12]
#> Q* = 41.137, df = 18, p-value = 0.001457
#> 
#> Model df: 6.   Total lags used: 24
checkresiduals(F_Houses_Not_Started)

#> 
#>  Ljung-Box test
#> 
#> data:  Residuals from ARIMA(0,1,1)
#> Q* = 54.172, df = 23, p-value = 0.0002536
#> 
#> Model df: 1.   Total lags used: 24
checkresiduals(F_Houses_Under_Construction)

#> 
#>  Ljung-Box test
#> 
#> data:  Residuals from ARIMA(0,1,1)
#> Q* = 46.714, df = 23, p-value = 0.002436
#> 
#> Model df: 1.   Total lags used: 24
checkresiduals(F_Houses_Completed)

#> 
#>  Ljung-Box test
#> 
#> data:  Residuals from ARIMA(2,1,0)
#> Q* = 26.283, df = 22, p-value = 0.2397
#> 
#> Model df: 2.   Total lags used: 24

acf(TSe_All_Houses, main="ACF for All Houses")

acf(TSe_Houses_Not_Started, main="ACF for Houses not started")

acf(TSe_Houses_Under_Construction, main="ACF for Houses under construction")

acf(TSe_Houses_Completed, main="ACF for completed houses")


pacf(TSe_All_Houses, main="PACF for All Houses")

pacf(TSe_Houses_Not_Started, main="PACF for Houses not started")

pacf(TSe_Houses_Under_Construction, main="PACF for Houses under construction")

pacf(TSe_Houses_Completed, main="PACF for completed houses")


min_length <- min(length(TSe_All_Houses), length(TSe_Houses_Not_Started), length(TSe_Houses_Under_Construction), length(TSe_Houses_Completed))

TSe_All_Houses_t <- TSe_All_Houses[1:min_length]
TSe_Houses_Not_Started_t <- TSe_Houses_Not_Started[1:min_length]
TSe_Houses_Under_Construction_t <- TSe_Houses_Under_Construction[1:min_length]
TSe_Houses_Completed_t <- TSe_Houses_Completed[1:min_length]

data_combined <- data.frame(All_Houses = TSe_All_Houses_t,                            Houses_Not_Started = TSe_Houses_Not_Started_t,                            Houses_Under_Construction = TSe_Houses_Under_Construction_t,                            Houses_Completed = TSe_Houses_Completed_t)

data_TSe<- ts(data_combined,  frequency=12, start=c(1963, 1))

var1_m <- VAR(data_TSe,  type="both",p=1)

summary(var1_m)
#> 
#> VAR Estimation Results:
#> ========================= 
#> Endogenous variables: All_Houses, Houses_Not_Started, Houses_Under_Construction, Houses_Completed 
#> Deterministic variables: both 
#> Sample size: 301 
#> Log Likelihood: -5742.372 
#> Roots of the characteristic polynomial:
#> 0.9791 0.9123 0.8877 0.7336
#> Call:
#> VAR(y = data_TSe, p = 1, type = "both")
#> 
#> 
#> Estimation results for equation All_Houses: 
#> =========================================== 
#> All_Houses = All_Houses.l1 + Houses_Not_Started.l1 + Houses_Under_Construction.l1 + Houses_Completed.l1 + const + trend 
#> 
#>                                Estimate Std. Error t value Pr(>|t|)    
#> All_Houses.l1                 0.9115526  0.0241476  37.749  < 2e-16 ***
#> Houses_Not_Started.l1        -0.0837090  0.0567143  -1.476  0.14102    
#> Houses_Under_Construction.l1  0.0493632  0.0569198   0.867  0.38652    
#> Houses_Completed.l1           0.0155610  0.0542639   0.287  0.77449    
#> const                        55.3301671 21.0481597   2.629  0.00902 ** 
#> trend                        -0.0005751  0.0413458  -0.014  0.98891    
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> 
#> Residual standard error: 45.01 on 295 degrees of freedom
#> Multiple R-Squared: 0.874,   Adjusted R-squared: 0.8719 
#> F-statistic: 409.3 on 5 and 295 DF,  p-value: < 2.2e-16 
#> 
#> 
#> Estimation results for equation Houses_Not_Started: 
#> =================================================== 
#> Houses_Not_Started = All_Houses.l1 + Houses_Not_Started.l1 + Houses_Under_Construction.l1 + Houses_Completed.l1 + const + trend 
#> 
#>                              Estimate Std. Error t value Pr(>|t|)    
#> All_Houses.l1                -0.02414    0.01380  -1.750  0.08123 .  
#> Houses_Not_Started.l1         0.87719    0.03240  27.070  < 2e-16 ***
#> Houses_Under_Construction.l1  0.09313    0.03252   2.864  0.00449 ** 
#> Houses_Completed.l1          -0.01010    0.03100  -0.326  0.74488    
#> const                        27.59281   12.02633   2.294  0.02247 *  
#> trend                        -0.05753    0.02362  -2.435  0.01548 *  
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> 
#> Residual standard error: 25.72 on 295 degrees of freedom
#> Multiple R-Squared: 0.9608,  Adjusted R-squared: 0.9602 
#> F-statistic:  1448 on 5 and 295 DF,  p-value: < 2.2e-16 
#> 
#> 
#> Estimation results for equation Houses_Under_Construction: 
#> ========================================================== 
#> Houses_Under_Construction = All_Houses.l1 + Houses_Not_Started.l1 + Houses_Under_Construction.l1 + Houses_Completed.l1 + const + trend 
#> 
#>                               Estimate Std. Error t value Pr(>|t|)    
#> All_Houses.l1                -0.001029   0.014766  -0.070   0.9445    
#> Houses_Not_Started.l1         0.138674   0.034680   3.999 8.06e-05 ***
#> Houses_Under_Construction.l1  0.842588   0.034806  24.208  < 2e-16 ***
#> Houses_Completed.l1           0.008288   0.033182   0.250   0.8029    
#> const                        -0.911943  12.870754  -0.071   0.9436    
#> trend                         0.063410   0.025283   2.508   0.0127 *  
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> 
#> Residual standard error: 27.52 on 295 degrees of freedom
#> Multiple R-Squared: 0.942,   Adjusted R-squared: 0.941 
#> F-statistic: 958.4 on 5 and 295 DF,  p-value: < 2.2e-16 
#> 
#> 
#> Estimation results for equation Houses_Completed: 
#> ================================================= 
#> Houses_Completed = All_Houses.l1 + Houses_Not_Started.l1 + Houses_Under_Construction.l1 + Houses_Completed.l1 + const + trend 
#> 
#>                                Estimate Std. Error t value Pr(>|t|)    
#> All_Houses.l1                -0.0131837  0.0123836  -1.065   0.2879    
#> Houses_Not_Started.l1         0.0007554  0.0290849   0.026   0.9793    
#> Houses_Under_Construction.l1  0.0363783  0.0291903   1.246   0.2137    
#> Houses_Completed.l1           0.8813374  0.0278282  31.671   <2e-16 ***
#> const                        24.2426945 10.7941494   2.246   0.0254 *  
#> trend                         0.0057398  0.0212034   0.271   0.7868    
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> 
#> Residual standard error: 23.08 on 295 degrees of freedom
#> Multiple R-Squared: 0.8697,  Adjusted R-squared: 0.8674 
#> F-statistic: 393.6 on 5 and 295 DF,  p-value: < 2.2e-16 
#> 
#> 
#> 
#> Covariance matrix of residuals:
#>                           All_Houses Houses_Not_Started
#> All_Houses                  2025.808              17.78
#> Houses_Not_Started            17.784             661.36
#> Houses_Under_Construction      5.268             161.90
#> Houses_Completed             -57.793              46.92
#>                           Houses_Under_Construction Houses_Completed
#> All_Houses                                    5.268           -57.79
#> Houses_Not_Started                          161.903            46.92
#> Houses_Under_Construction                   757.492           169.62
#> Houses_Completed                            169.615           532.78
#> 
#> Correlation matrix of residuals:
#>                           All_Houses Houses_Not_Started
#> All_Houses                  1.000000            0.01536
#> Houses_Not_Started          0.015364            1.00000
#> Houses_Under_Construction   0.004253            0.22874
#> Houses_Completed           -0.055629            0.07904
#>                           Houses_Under_Construction Houses_Completed
#> All_Houses                                 0.004253         -0.05563
#> Houses_Not_Started                         0.228744          0.07904
#> Houses_Under_Construction                  1.000000          0.26699
#> Houses_Completed                           0.266995          1.00000

lag_select <- VARselect(data_TSe, type="both", lag.max=10,)
opt_lags <- lag_select$selection["AIC(n)"]

varp_m <- VAR(data_TSe, type="both",  p=opt_lags,)

summary(varp_m)
#> 
#> VAR Estimation Results:
#> ========================= 
#> Endogenous variables: All_Houses, Houses_Not_Started, Houses_Under_Construction, Houses_Completed 
#> Deterministic variables: both 
#> Sample size: 299 
#> Log Likelihood: -5629.097 
#> Roots of the characteristic polynomial:
#> 0.9758 0.9758 0.9442 0.8969 0.5263 0.5263 0.5003 0.5003 0.3725 0.1773 0.1521 0.1521
#> Call:
#> VAR(y = data_TSe, p = opt_lags, type = "both")
#> 
#> 
#> Estimation results for equation All_Houses: 
#> =========================================== 
#> All_Houses = All_Houses.l1 + Houses_Not_Started.l1 + Houses_Under_Construction.l1 + Houses_Completed.l1 + All_Houses.l2 + Houses_Not_Started.l2 + Houses_Under_Construction.l2 + Houses_Completed.l2 + All_Houses.l3 + Houses_Not_Started.l3 + Houses_Under_Construction.l3 + Houses_Completed.l3 + const + trend 
#> 
#>                               Estimate Std. Error t value Pr(>|t|)    
#> All_Houses.l1                 0.806326   0.059237  13.612   <2e-16 ***
#> Houses_Not_Started.l1        -0.099270   0.110186  -0.901   0.3684    
#> Houses_Under_Construction.l1  0.065466   0.107138   0.611   0.5417    
#> Houses_Completed.l1           0.103924   0.122296   0.850   0.3962    
#> All_Houses.l2                 0.092182   0.075462   1.222   0.2229    
#> Houses_Not_Started.l2         0.002864   0.129002   0.022   0.9823    
#> Houses_Under_Construction.l2  0.062661   0.117313   0.534   0.5937    
#> Houses_Completed.l2          -0.247902   0.141376  -1.753   0.0806 .  
#> All_Houses.l3                 0.028256   0.058553   0.483   0.6298    
#> Houses_Not_Started.l3         0.025111   0.109009   0.230   0.8180    
#> Houses_Under_Construction.l3 -0.080000   0.105734  -0.757   0.4499    
#> Houses_Completed.l3           0.147971   0.123062   1.202   0.2302    
#> const                        48.505142  21.995375   2.205   0.0282 *  
#> trend                        -0.010926   0.042841  -0.255   0.7989    
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> 
#> Residual standard error: 44.56 on 285 degrees of freedom
#> Multiple R-Squared: 0.8798,  Adjusted R-squared: 0.8743 
#> F-statistic: 160.4 on 13 and 285 DF,  p-value: < 2.2e-16 
#> 
#> 
#> Estimation results for equation Houses_Not_Started: 
#> =================================================== 
#> Houses_Not_Started = All_Houses.l1 + Houses_Not_Started.l1 + Houses_Under_Construction.l1 + Houses_Completed.l1 + All_Houses.l2 + Houses_Not_Started.l2 + Houses_Under_Construction.l2 + Houses_Completed.l2 + All_Houses.l3 + Houses_Not_Started.l3 + Houses_Under_Construction.l3 + Houses_Completed.l3 + const + trend 
#> 
#>                               Estimate Std. Error t value Pr(>|t|)    
#> All_Houses.l1                -0.036667   0.032865  -1.116  0.26550    
#> Houses_Not_Started.l1         0.661609   0.061132  10.823  < 2e-16 ***
#> Houses_Under_Construction.l1  0.191177   0.059441   3.216  0.00145 ** 
#> Houses_Completed.l1           0.167271   0.067851   2.465  0.01428 *  
#> All_Houses.l2                 0.003475   0.041867   0.083  0.93391    
#> Houses_Not_Started.l2         0.287112   0.071571   4.012 7.71e-05 ***
#> Houses_Under_Construction.l2 -0.060719   0.065086  -0.933  0.35166    
#> Houses_Completed.l2          -0.176780   0.078436  -2.254  0.02497 *  
#> All_Houses.l3                 0.019651   0.032486   0.605  0.54573    
#> Houses_Not_Started.l3        -0.009821   0.060479  -0.162  0.87112    
#> Houses_Under_Construction.l3 -0.091566   0.058662  -1.561  0.11965    
#> Houses_Completed.l3          -0.012069   0.068276  -0.177  0.85981    
#> const                        21.452016  12.203199   1.758  0.07984 .  
#> trend                        -0.039610   0.023768  -1.666  0.09672 .  
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> 
#> Residual standard error: 24.72 on 285 degrees of freedom
#> Multiple R-Squared: 0.9649,  Adjusted R-squared: 0.9633 
#> F-statistic: 603.2 on 13 and 285 DF,  p-value: < 2.2e-16 
#> 
#> 
#> Estimation results for equation Houses_Under_Construction: 
#> ========================================================== 
#> Houses_Under_Construction = All_Houses.l1 + Houses_Not_Started.l1 + Houses_Under_Construction.l1 + Houses_Completed.l1 + All_Houses.l2 + Houses_Not_Started.l2 + Houses_Under_Construction.l2 + Houses_Completed.l2 + All_Houses.l3 + Houses_Not_Started.l3 + Houses_Under_Construction.l3 + Houses_Completed.l3 + const + trend 
#> 
#>                               Estimate Std. Error t value Pr(>|t|)    
#> All_Houses.l1                -0.002853   0.034395  -0.083  0.93396    
#> Houses_Not_Started.l1         0.029299   0.063978   0.458  0.64733    
#> Houses_Under_Construction.l1  0.550766   0.062208   8.854  < 2e-16 ***
#> Houses_Completed.l1           0.059138   0.071010   0.833  0.40565    
#> All_Houses.l2                -0.032793   0.043816  -0.748  0.45482    
#> Houses_Not_Started.l2         0.188880   0.074903   2.522  0.01223 *  
#> Houses_Under_Construction.l2  0.193233   0.068116   2.837  0.00488 ** 
#> Houses_Completed.l2           0.048423   0.082088   0.590  0.55573    
#> All_Houses.l3                 0.032421   0.033998   0.954  0.34109    
#> Houses_Not_Started.l3        -0.113352   0.063294  -1.791  0.07438 .  
#> Houses_Under_Construction.l3  0.151107   0.061393   2.461  0.01444 *  
#> Houses_Completed.l3          -0.128855   0.071454  -1.803  0.07239 .  
#> const                         1.866551  12.771288   0.146  0.88390    
#> trend                         0.055907   0.024875   2.248  0.02537 *  
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> 
#> Residual standard error: 25.87 on 285 degrees of freedom
#> Multiple R-Squared: 0.9503,  Adjusted R-squared: 0.9481 
#> F-statistic: 419.4 on 13 and 285 DF,  p-value: < 2.2e-16 
#> 
#> 
#> Estimation results for equation Houses_Completed: 
#> ================================================= 
#> Houses_Completed = All_Houses.l1 + Houses_Not_Started.l1 + Houses_Under_Construction.l1 + Houses_Completed.l1 + All_Houses.l2 + Houses_Not_Started.l2 + Houses_Under_Construction.l2 + Houses_Completed.l2 + All_Houses.l3 + Houses_Not_Started.l3 + Houses_Under_Construction.l3 + Houses_Completed.l3 + const + trend 
#> 
#>                               Estimate Std. Error t value Pr(>|t|)    
#> All_Houses.l1                 0.003486   0.028635   0.122  0.90320    
#> Houses_Not_Started.l1        -0.003717   0.053264  -0.070  0.94441    
#> Houses_Under_Construction.l1 -0.007191   0.051790  -0.139  0.88966    
#> Houses_Completed.l1           0.584435   0.059118   9.886  < 2e-16 ***
#> All_Houses.l2                -0.064935   0.036478  -1.780  0.07613 .  
#> Houses_Not_Started.l2         0.076236   0.062360   1.223  0.22252    
#> Houses_Under_Construction.l2 -0.032391   0.056709  -0.571  0.56833    
#> Houses_Completed.l2           0.116283   0.068341   1.702  0.08994 .  
#> All_Houses.l3                 0.047710   0.028305   1.686  0.09297 .  
#> Houses_Not_Started.l3        -0.091497   0.052695  -1.736  0.08358 .  
#> Houses_Under_Construction.l3  0.087647   0.051112   1.715  0.08747 .  
#> Houses_Completed.l3           0.221952   0.059488   3.731  0.00023 ***
#> const                        17.129689  10.632561   1.611  0.10827    
#> trend                         0.003784   0.020709   0.183  0.85517    
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> 
#> Residual standard error: 21.54 on 285 degrees of freedom
#> Multiple R-Squared: 0.8903,  Adjusted R-squared: 0.8853 
#> F-statistic: 177.9 on 13 and 285 DF,  p-value: < 2.2e-16 
#> 
#> 
#> 
#> Covariance matrix of residuals:
#>                           All_Houses Houses_Not_Started
#> All_Houses                  1985.330             -18.20
#> Houses_Not_Started           -18.197             611.11
#> Houses_Under_Construction      9.165             175.04
#> Houses_Completed             -38.974              75.56
#>                           Houses_Under_Construction Houses_Completed
#> All_Houses                                    9.165           -38.97
#> Houses_Not_Started                          175.038            75.56
#> Houses_Under_Construction                   669.329           150.88
#> Houses_Completed                            150.877           463.92
#> 
#> Correlation matrix of residuals:
#>                           All_Houses Houses_Not_Started
#> All_Houses                  1.000000           -0.01652
#> Houses_Not_Started         -0.016521            1.00000
#> Houses_Under_Construction   0.007951            0.27369
#> Houses_Completed           -0.040610            0.14191
#>                           Houses_Under_Construction Houses_Completed
#> All_Houses                                 0.007951         -0.04061
#> Houses_Not_Started                         0.273686          0.14191
#> Houses_Under_Construction                  1.000000          0.27076
#> Houses_Completed                           0.270757          1.00000

Var1_AIC <- AIC(var1_m)
Var1_BIC <- BIC(var1_m)

Varp_AIC <- AIC(varp_m)
Varp_BIC <- BIC(varp_m)

cat("VAR(1) AIC", Var1_AIC, "\n BIC", Var1_BIC, "\n")
#> VAR(1) AIC 11532.74 
#>  BIC 11621.71

cat("VAR(p) AIC", Varp_AIC, "\n BIC", Varp_BIC, "\n")
#> VAR(p) AIC 11370.19 
#>  BIC 11577.42

if(Var1_AIC < Varp_AIC && Var1_BIC < Varp_BIC) {
  cat("Based on the AIC and BIC criteria, the VAR(1) model is the preferred choice.\n")
} else if(Varp_AIC < Var1_AIC && Varp_BIC < Var1_BIC) {
  cat("Based on the AIC and BIC criteria, the VAR(p) model is the preferred choice..\n")
} else {
  cat("Additional diagnostics and factors may need to be evaluated.\n")
}
#> Based on the AIC and BIC criteria, the VAR(p) model is the preferred choice..

f_var1 <- predict(var1_m, n.ahead=1)

f_varp <- predict(varp_m, n.ahead=1)

print(f_var1)
#> $All_Houses
#>                     fcst    lower    upper       CI
#> All_Houses.fcst 671.9503 583.7343 760.1663 88.21597
#> 
#> $Houses_Not_Started
#>                             fcst    lower    upper       CI
#> Houses_Not_Started.fcst 90.41392 40.00979 140.8181 50.40414
#> 
#> $Houses_Under_Construction
#>                                    fcst   lower    upper       CI
#> Houses_Under_Construction.fcst 284.7912 230.848 338.7345 53.94325
#> 
#> $Houses_Completed
#>                           fcst    lower    upper       CI
#> Houses_Completed.fcst 275.0266 229.7867 320.2665 45.23989

print(f_varp)
#> $All_Houses
#>                     fcst    lower    upper      CI
#> All_Houses.fcst 659.1575 571.8273 746.4877 87.3302
#> 
#> $Houses_Not_Started
#>                             fcst    lower    upper       CI
#> Houses_Not_Started.fcst 87.51118 39.05973 135.9626 48.45145
#> 
#> $Houses_Under_Construction
#>                                    fcst    lower    upper       CI
#> Houses_Under_Construction.fcst 280.5758 229.8688 331.2828 50.70699
#> 
#> $Houses_Completed
#>                           fcst    lower    upper       CI
#> Houses_Completed.fcst 282.5343 240.3189 324.7497 42.21541

plot(f_var1, main="One-Month Forecast Based on a First-Order Vector Autoregression (VAR(1)) Model")


plot(f_varp, main="One-Month Forecast Based on VAR(p) Model")


test_gag <- causality(varp_m)
#> Warning in causality(varp_m): 
#> Argument 'cause' has not been specified;
#> using first variable in 'x$y' (All_Houses) as cause variable.

print(test_gag)
#> $Granger
#> 
#>  Granger causality H0: All_Houses do not Granger-cause
#>  Houses_Not_Started Houses_Under_Construction Houses_Completed
#> 
#> data:  VAR object varp_m
#> F-Test = 0.83935, df1 = 9, df2 = 1140, p-value = 0.5798
#> 
#> 
#> $Instant
#> 
#>  H0: No instantaneous causality between: All_Houses and
#>  Houses_Not_Started Houses_Under_Construction Houses_Completed
#> 
#> data:  VAR object varp_m
#> Chi-squared = 0.68609, df = 3, p-value = 0.8765

data_m <- as.matrix(data_TSe)

s_var_m <- BigVAR.fit(data_m,lambda = 0.1,p = 16, struct = "Lag")

print(summary(s_var_m))
#>     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
#> -5.85423 -0.05124  0.00143  0.41160  0.07419 68.16797

Created on 2024-04-11 with reprex v2.0.2