World Bank Ornek 1 CO2 EMİSYONLARI (KİŞİ BAŞINA METRİK TON)

library(WDI)
gsyh <- WDI(country=c("MX", "TR","US"), indicator=c("EN.ATM.CO2E.PC"), start=1960, end=2018)
names(gsyh) <- c("iso2c", "Ülke", "KisiBasiGSYH", "Sene")
head(gsyh)
##   iso2c   Ülke KisiBasiGSYH Sene
## 1    MX Mexico     3.741478 2018
## 2    MX Mexico     3.781216 2017
## 3    MX Mexico     3.885809 2016
## 4    MX Mexico     3.878195 2015
## 5    MX Mexico     3.808063 2014
## 6    MX Mexico     3.954147 2013
library(ggplot2)
ggplot(gsyh, aes(Sene, KisiBasiGSYH, color=Ülke, linetype=Ülke)) + geom_line()

TR <- cbind(gsyh$KisiBasiGSYH[gsyh$Ülke == "Turkey"], gsyh$Sene[gsyh$Ülke == "Turkey"])
TR <- TR[order(TR[,2]),]
TR
##            [,1] [,2]
##  [1,] 0.6122715 1960
##  [2,] 0.6168793 1961
##  [3,] 0.7502431 1962
##  [4,] 0.7676379 1963
##  [5,] 0.8707899 1964
##  [6,] 0.8842807 1965
##  [7,] 0.9946306 1966
##  [8,] 1.0321978 1967
##  [9,] 1.0919471 1968
## [10,] 1.1395512 1969
## [11,] 1.2226033 1970
## [12,] 1.3362971 1971
## [13,] 1.4720211 1972
## [14,] 1.5874667 1973
## [15,] 1.5933224 1974
## [16,] 1.6726724 1975
## [17,] 1.8343412 1976
## [18,] 1.9843300 1977
## [19,] 1.8376876 1978
## [20,] 1.7578452 1979
## [21,] 1.7228474 1980
## [22,] 1.7754482 1981
## [23,] 1.8900119 1982
## [24,] 1.9234167 1983
## [25,] 1.9910295 1984
## [26,] 2.1719622 1985
## [27,] 2.3316446 1986
## [28,] 2.5421679 1987
## [29,] 2.4265261 1988
## [30,] 2.6289894 1989
## [31,] 2.5818891 1990
## [32,] 2.6225098 1991
## [33,] 2.6875844 1992
## [34,] 2.7470351 1993
## [35,] 2.6740574 1994
## [36,] 2.8769055 1995
## [37,] 3.1208309 1996
## [38,] 3.2065886 1997
## [39,] 3.1607869 1998
## [40,] 3.0964533 1999
## [41,] 3.4253531 2000
## [42,] 3.0810576 2001
## [43,] 3.1947020 2002
## [44,] 3.3161141 2003
## [45,] 3.3516920 2004
## [46,] 3.4609429 2005
## [47,] 3.7972966 2006
## [48,] 4.1529506 2007
## [49,] 4.0784672 2008
## [50,] 4.0356748 2009
## [51,] 4.1080099 2010
## [52,] 4.3260610 2011
## [53,] 4.4055645 2012
## [54,] 4.1905578 2013
## [55,] 4.4107634 2014
## [56,] 4.4771760 2015
## [57,] 4.6924716 2016
## [58,] 5.1271967 2017
## [59,] 5.0154184 2018
TR <- ts(TR[,1], start=min(gsyh$Sene), end=max(gsyh$Sene))
plot(TR, ylab="Kişi başı GSYH", xlab="Sene")

acf(TR)

pacf(TR)

plot(TR, ylab="Kişi başı GSYH", xlab="Sene")

library(dynlm)
## Zorunlu paket yükleniyor: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
Ilkgecikme <- dynlm(TR ~ L(TR, 1))
summary(Ilkgecikme)
## 
## Time series regression with "ts" data:
## Start = 1961, End = 2018
## 
## Call:
## dynlm(formula = TR ~ L(TR, 1))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.42589 -0.05730 -0.00554  0.07628  0.34509 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.05983    0.04244    1.41    0.164    
## L(TR, 1)     1.00635    0.01514   66.47   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1387 on 56 degrees of freedom
## Multiple R-squared:  0.9875, Adjusted R-squared:  0.9873 
## F-statistic:  4418 on 1 and 56 DF,  p-value: < 2.2e-16

İlk gecikme 1.00 olarak görünüyor.

Ikincigecikme <- dynlm(TR ~ L(TR, 2))
summary(Ikincigecikme)
## 
## Time series regression with "ts" data:
## Start = 1962, End = 2018
## 
## Call:
## dynlm(formula = TR ~ L(TR, 2))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.40622 -0.07069  0.00022  0.10234  0.51571 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.10553    0.05629   1.875   0.0661 .  
## L(TR, 2)     1.02045    0.02051  49.758   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.18 on 55 degrees of freedom
## Multiple R-squared:  0.9783, Adjusted R-squared:  0.9779 
## F-statistic:  2476 on 1 and 55 DF,  p-value: < 2.2e-16

Diğer gecikmeleri katmadan ikinci gecikme için yapılan regresyonda yine gecikmenin katsayısı 1.02 ve anlamlı.

Ucuncugecikme <- dynlm(TR ~ L(TR, 3))
summary(Ucuncugecikme)
## 
## Time series regression with "ts" data:
## Start = 1963, End = 2018
## 
## Call:
## dynlm(formula = TR ~ L(TR, 3))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.47827 -0.09608 -0.00104  0.08028  0.54672 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.16199    0.06463   2.506   0.0152 *  
## L(TR, 3)     1.02761    0.02396  42.888   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2034 on 54 degrees of freedom
## Multiple R-squared:  0.9715, Adjusted R-squared:  0.971 
## F-statistic:  1839 on 1 and 54 DF,  p-value: < 2.2e-16

Üçüncü gecikme katsayısı 1.02 ve anlamlılık düzeyi çok yüksek.

AR10 <- dynlm(TR ~ L(TR, c(1:10)))
summary(AR10)
## 
## Time series regression with "ts" data:
## Start = 1970, End = 2018
## 
## Call:
## dynlm(formula = TR ~ L(TR, c(1:10)))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.39733 -0.08223  0.01245  0.10758  0.27066 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       0.20918    0.06866   3.047 0.004193 ** 
## L(TR, c(1:10))1   0.59929    0.15644   3.831 0.000465 ***
## L(TR, c(1:10))2  -0.02049    0.20188  -0.102 0.919675    
## L(TR, c(1:10))3   0.06919    0.20353   0.340 0.735756    
## L(TR, c(1:10))4   0.12336    0.20141   0.612 0.543863    
## L(TR, c(1:10))5   0.02415    0.19961   0.121 0.904331    
## L(TR, c(1:10))6  -0.26983    0.21020  -1.284 0.207018    
## L(TR, c(1:10))7   0.16279    0.21364   0.762 0.450783    
## L(TR, c(1:10))8  -0.16370    0.21914  -0.747 0.459646    
## L(TR, c(1:10))9   0.16412    0.22357   0.734 0.467394    
## L(TR, c(1:10))10  0.35836    0.18749   1.911 0.063525 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1365 on 38 degrees of freedom
## Multiple R-squared:  0.9871, Adjusted R-squared:  0.9837 
## F-statistic: 290.9 on 10 and 38 DF,  p-value: < 2.2e-16

Random Walk Örneği(YAHOO FİNANCE)

n<-200
TSLA <- ts(rnorm(n))
AAPL <- ts(rnorm(n))
u <- ts(rnorm(n))
v <- ts(rnorm(n))
TSLA <- ts(rep(0,n))
for (t in 2:n){
  TSLA[t]<- TSLA[t-1]+u[t]
}
AAPL <- ts(rep(0,n))
for (t in 2:n){
  AAPL[t]<- AAPL[t-1]+v[t]
}
plot(TSLA,type='l', TSLAlab="TSLA[t-1]+u[t]")
## Warning in plot.window(xlim, ylim, log, ...): "TSLAlab" bir grafiksel parametre
## değil
## Warning in title(main = main, xlab = xlab, ylab = ylab, ...): "TSLAlab" bir
## grafiksel parametre değil
## Warning in axis(1, ...): "TSLAlab" bir grafiksel parametre değil
## Warning in axis(2, ...): "TSLAlab" bir grafiksel parametre değil
## Warning in box(...): "TSLAlab" bir grafiksel parametre değil

plot(AAPL,type='l', AAPLlab="AAPL[t-1]+v[t]")
## Warning in plot.window(xlim, ylim, log, ...): "AAPLlab" bir grafiksel parametre
## değil
## Warning in title(main = main, xlab = xlab, ylab = ylab, ...): "AAPLlab" bir
## grafiksel parametre değil
## Warning in axis(1, ...): "AAPLlab" bir grafiksel parametre değil
## Warning in axis(2, ...): "AAPLlab" bir grafiksel parametre değil
## Warning in box(...): "AAPLlab" bir grafiksel parametre değil

Spurious <- lm(TSLA~AAPL)
summary(Spurious)
## 
## Call:
## lm(formula = TSLA ~ AAPL)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -8.7884 -3.4417  0.0994  3.1067  6.8641 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  5.74497    0.56481  10.172   <2e-16 ***
## AAPL         0.10336    0.04909   2.106   0.0365 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.831 on 198 degrees of freedom
## Multiple R-squared:  0.0219, Adjusted R-squared:  0.01696 
## F-statistic: 4.434 on 1 and 198 DF,  p-value: 0.03649
duragan <- dynlm(d(TSLA) ~ d(AAPL))
summary(duragan)
## 
## Time series regression with "ts" data:
## Start = 2, End = 200
## 
## Call:
## dynlm(formula = d(TSLA) ~ d(AAPL))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.19374 -0.70829 -0.03427  0.63684  3.06387 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept)  0.05118    0.07390   0.693    0.489
## d(AAPL)     -0.07733    0.07317  -1.057    0.292
## 
## Residual standard error: 1.042 on 197 degrees of freedom
## Multiple R-squared:  0.005637,   Adjusted R-squared:  0.0005898 
## F-statistic: 1.117 on 1 and 197 DF,  p-value: 0.2919

Durağanlık testi (Dickey Fuller)

library(tseries)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
adf.test(AAPL)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  AAPL
## Dickey-Fuller = -1.2791, Lag order = 5, p-value = 0.878
## alternative hypothesis: stationary
adf.test(TSLA)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  TSLA
## Dickey-Fuller = -2.3034, Lag order = 5, p-value = 0.449
## alternative hypothesis: stationary
adf.test(TR)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  TR
## Dickey-Fuller = -2.0204, Lag order = 3, p-value = 0.5665
## alternative hypothesis: stationary
kpss.test(TR)
## Warning in kpss.test(TR): p-value smaller than printed p-value
## 
##  KPSS Test for Level Stationarity
## 
## data:  TR
## KPSS Level = 1.5569, Truncation lag parameter = 3, p-value = 0.01
Deltax <- diff(AAPL)
adf.test(Deltax)
## Warning in adf.test(Deltax): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  Deltax
## Dickey-Fuller = -5.3637, Lag order = 5, p-value = 0.01
## alternative hypothesis: stationary

Artık olasılık değeri 0.01 ve ß1 değerinin sıfır olma ihtimali çok düşük hale gelir.

Random Walk Örneği 2 (FRED ÖRNEKLERİ)

n<-200
u <- ts(rnorm(n))
v <- ts(rnorm(n))
LRUN74FETRQ156S <- ts(rep(0,n))
for (t in 2:n){
 LRUN74FETRQ156S[t]<- LRUN74FETRQ156S[t-1]+u[t]
}
SLUEM1524ZSTUR <- ts(rep(0,n))
for (t in 2:n){
 SLUEM1524ZSTUR[t]<- SLUEM1524ZSTUR[t-1]+v[t]
}
plot(LRUN74FETRQ156S,type='l', LRUN74FETRQ156Slab="LRUN74FETRQ156S[t-1]+u[t]")
## Warning in plot.window(xlim, ylim, log, ...): "LRUN74FETRQ156Slab" bir grafiksel
## parametre değil
## Warning in title(main = main, xlab = xlab, ylab = ylab, ...):
## "LRUN74FETRQ156Slab" bir grafiksel parametre değil
## Warning in axis(1, ...): "LRUN74FETRQ156Slab" bir grafiksel parametre değil
## Warning in axis(2, ...): "LRUN74FETRQ156Slab" bir grafiksel parametre değil
## Warning in box(...): "LRUN74FETRQ156Slab" bir grafiksel parametre değil

plot(SLUEM1524ZSTUR,type='l', SLUEM1524ZSTURlab="SLUEM1524ZSTUR[t-1]+v[t]")
## Warning in plot.window(xlim, ylim, log, ...): "SLUEM1524ZSTURlab" bir grafiksel
## parametre değil
## Warning in title(main = main, xlab = xlab, ylab = ylab, ...):
## "SLUEM1524ZSTURlab" bir grafiksel parametre değil
## Warning in axis(1, ...): "SLUEM1524ZSTURlab" bir grafiksel parametre değil
## Warning in axis(2, ...): "SLUEM1524ZSTURlab" bir grafiksel parametre değil
## Warning in box(...): "SLUEM1524ZSTURlab" bir grafiksel parametre değil

Spurious <- lm(LRUN74FETRQ156S~SLUEM1524ZSTUR)
summary(Spurious)
## 
## Call:
## lm(formula = LRUN74FETRQ156S ~ SLUEM1524ZSTUR)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -13.258  -7.261  -1.208   6.268  16.872 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      4.7585     1.0480   4.541 9.73e-06 ***
## SLUEM1524ZSTUR   0.2672     0.1882   1.420    0.157    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.559 on 198 degrees of freedom
## Multiple R-squared:  0.01007,    Adjusted R-squared:  0.005075 
## F-statistic: 2.015 on 1 and 198 DF,  p-value: 0.1573
duragan <- dynlm(d(LRUN74FETRQ156S) ~ d(SLUEM1524ZSTUR))
summary(duragan)
## 
## Time series regression with "ts" data:
## Start = 2, End = 200
## 
## Call:
## dynlm(formula = d(LRUN74FETRQ156S) ~ d(SLUEM1524ZSTUR))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.8147 -0.5264  0.1012  0.6246  2.3946 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)
## (Intercept)        0.10462    0.07166   1.460    0.146
## d(SLUEM1524ZSTUR)  0.03702    0.06904   0.536    0.592
## 
## Residual standard error: 1.011 on 197 degrees of freedom
## Multiple R-squared:  0.001457,   Adjusted R-squared:  -0.003611 
## F-statistic: 0.2875 on 1 and 197 DF,  p-value: 0.5924

Durağanlık testi (Dickey Fuller)

library(tseries)
adf.test(SLUEM1524ZSTUR)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  SLUEM1524ZSTUR
## Dickey-Fuller = -2.1982, Lag order = 5, p-value = 0.4931
## alternative hypothesis: stationary
adf.test(LRUN74FETRQ156S)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  LRUN74FETRQ156S
## Dickey-Fuller = -2.3359, Lag order = 5, p-value = 0.4354
## alternative hypothesis: stationary
adf.test(TR)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  TR
## Dickey-Fuller = -2.0204, Lag order = 3, p-value = 0.5665
## alternative hypothesis: stationary
kpss.test(TR)
## Warning in kpss.test(TR): p-value smaller than printed p-value
## 
##  KPSS Test for Level Stationarity
## 
## data:  TR
## KPSS Level = 1.5569, Truncation lag parameter = 3, p-value = 0.01
Deltax <- diff(SLUEM1524ZSTUR)
adf.test(Deltax)
## Warning in adf.test(Deltax): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  Deltax
## Dickey-Fuller = -6.0276, Lag order = 5, p-value = 0.01
## alternative hypothesis: stationary

Artık olasılık değeri 0.01 ve ß1 değerinin sıfır olma ihtimali çok düşük hale gelir.