library(WDI)
issizlik <- WDI(country=c("US", "TR","JP"), indicator=c("SL.UEM.TOTL.ZS"), start=1990, end=2020)
names(issizlik) <- c("iso2c", "Ülke", "oran", "Sene")
head(issizlik)
## iso2c Ülke oran Sene
## 1 JP Japan 2.8 2020
## 2 JP Japan 2.4 2019
## 3 JP Japan 2.4 2018
## 4 JP Japan 2.8 2017
## 5 JP Japan 3.1 2016
## 6 JP Japan 3.4 2015
library(ggplot2)
ggplot(issizlik, aes(Sene, oran, color=Ülke, linetype=Ülke)) + geom_line()
## Warning: Removed 3 row(s) containing missing values (geom_path).
TR <- cbind(issizlik$oran[issizlik$Ülke == "Turkey"], issizlik$Sene[issizlik$Ülke == "Turkey"])
TR <- TR[order(TR[,2]),]
TR
## [,1] [,2]
## [1,] NA 1990
## [2,] 8.21 1991
## [3,] 8.51 1992
## [4,] 8.96 1993
## [5,] 8.58 1994
## [6,] 7.64 1995
## [7,] 6.63 1996
## [8,] 6.84 1997
## [9,] 6.89 1998
## [10,] 7.69 1999
## [11,] 6.50 2000
## [12,] 8.38 2001
## [13,] 10.36 2002
## [14,] 10.54 2003
## [15,] 10.84 2004
## [16,] 10.64 2005
## [17,] 8.72 2006
## [18,] 8.87 2007
## [19,] 9.71 2008
## [20,] 12.55 2009
## [21,] 10.66 2010
## [22,] 8.80 2011
## [23,] 8.15 2012
## [24,] 8.73 2013
## [25,] 9.88 2014
## [26,] 10.24 2015
## [27,] 10.84 2016
## [28,] 10.82 2017
## [29,] 10.89 2018
## [30,] 13.67 2019
## [31,] 13.11 2020
TR <- ts(TR[,1], start=min(issizlik$Sene), end=max(issizlik$Sene))
plot(TR, ylab="İssizlik Oranı", xlab="Sene")
plot(TR, ylab="İssizlik Oranı", 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 = 1992, End = 2020
##
## Call:
## dynlm(formula = TR ~ L(TR, 1))
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.86111 -0.60707 0.07293 0.34186 2.88144
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.7522 1.2326 1.422 0.167
## L(TR, 1) 0.8298 0.1303 6.367 8.1e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.2 on 27 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.6002, Adjusted R-squared: 0.5854
## F-statistic: 40.53 on 1 and 27 DF, p-value: 8.102e-07
Ikincigecikme <- dynlm(TR ~ L(TR, 2))
summary(Ikincigecikme)
##
## Time series regression with "ts" data:
## Start = 1993, End = 2020
##
## Call:
## dynlm(formula = TR ~ L(TR, 2))
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.6422 -1.5442 0.1647 0.9234 3.2123
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.3002 1.9560 2.198 0.0370 *
## L(TR, 2) 0.5691 0.2110 2.697 0.0121 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.702 on 26 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.2187, Adjusted R-squared: 0.1886
## F-statistic: 7.276 on 1 and 26 DF, p-value: 0.0121
Ucuncugecikme <- dynlm(TR ~ L(TR, 3))
summary(Ucuncugecikme)
##
## Time series regression with "ts" data:
## Start = 1994, End = 2020
##
## Call:
## dynlm(formula = TR ~ L(TR, 3))
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.8500 -1.3634 -0.3321 1.2823 3.4925
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6.1559 2.1894 2.812 0.00945 **
## L(TR, 3) 0.3710 0.2378 1.560 0.13134
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.871 on 25 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.0887, Adjusted R-squared: 0.05225
## F-statistic: 2.433 on 1 and 25 DF, p-value: 0.1313
AR10 <- dynlm(TR ~ L(TR, c(1:10)))
summary(AR10)
##
## Time series regression with "ts" data:
## Start = 2001, End = 2020
##
## Call:
## dynlm(formula = TR ~ L(TR, c(1:10)))
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.42283 -0.70275 0.07598 0.43933 1.75770
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.49907 3.09631 1.453 0.1802
## L(TR, c(1:10))zoo(coredata(x), tt).1 0.72113 0.24521 2.941 0.0165 *
## L(TR, c(1:10))zoo(coredata(x), tt).2 -0.28303 0.36321 -0.779 0.4558
## L(TR, c(1:10))zoo(coredata(x), tt).3 -0.10595 0.37493 -0.283 0.7839
## L(TR, c(1:10))zoo(coredata(x), tt).4 0.04635 0.37561 0.123 0.9045
## L(TR, c(1:10))zoo(coredata(x), tt).5 0.07820 0.37650 0.208 0.8401
## L(TR, c(1:10))zoo(coredata(x), tt).6 -0.14423 0.38149 -0.378 0.7141
## L(TR, c(1:10))zoo(coredata(x), tt).7 0.15156 0.37705 0.402 0.6971
## L(TR, c(1:10))zoo(coredata(x), tt).8 -0.08407 0.37528 -0.224 0.8277
## L(TR, c(1:10))zoo(coredata(x), tt).9 -0.31279 0.37508 -0.834 0.4259
## L(TR, c(1:10))zoo(coredata(x), tt).10 0.52954 0.27715 1.911 0.0884 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.288 on 9 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.6602, Adjusted R-squared: 0.2826
## F-statistic: 1.748 on 10 and 9 DF, p-value: 0.207
\[ Random-Walk-Örneği \]
n<-200
u <- ts(rnorm(n))
v <- ts(rnorm(n))
y <- ts(rep(0,n))
for (t in 2:n){
y[t]<- y[t-1]+u[t]
}
x <- ts(rep(0,n))
for (t in 2:n){
x[t]<- x[t-1]+v[t]
}
plot(y,type='l', ylab="y[t-1]+u[t]")
plot(x,type='l', ylab="x[t-1]+v[t]")
Spurious <- lm(y~x)
summary(Spurious)
##
## Call:
## lm(formula = y ~ x)
##
## Residuals:
## Min 1Q Median 3Q Max
## -7.4844 -1.9178 0.3547 1.9113 6.1274
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.48438 0.23238 -10.691 < 2e-16 ***
## x -0.39140 0.05843 -6.698 2.13e-10 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.986 on 198 degrees of freedom
## Multiple R-squared: 0.1847, Adjusted R-squared: 0.1806
## F-statistic: 44.87 on 1 and 198 DF, p-value: 2.132e-10
duragan <- dynlm(d(y) ~ d(x))
summary(duragan)
##
## Time series regression with "ts" data:
## Start = 2, End = 200
##
## Call:
## dynlm(formula = d(y) ~ d(x))
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.3225 -0.6005 0.0542 0.6307 2.6028
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.008358 0.068834 0.121 0.903
## d(x) -0.038071 0.066761 -0.570 0.569
##
## Residual standard error: 0.9706 on 197 degrees of freedom
## Multiple R-squared: 0.001648, Adjusted R-squared: -0.00342
## F-statistic: 0.3252 on 1 and 197 DF, p-value: 0.5692
library(tseries)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
adf.test(x)
##
## Augmented Dickey-Fuller Test
##
## data: x
## Dickey-Fuller = -3.4123, Lag order = 5, p-value = 0.05409
## alternative hypothesis: stationary
adf.test(y)
##
## Augmented Dickey-Fuller Test
##
## data: y
## Dickey-Fuller = -2.5721, Lag order = 5, p-value = 0.3365
## alternative hypothesis: stationary
kpss.test(TR)
##
## KPSS Test for Level Stationarity
##
## data: TR
## KPSS Level = 0.65122, Truncation lag parameter = 2, p-value = 0.01798
Deltax <- diff(x)
adf.test(Deltax)
## Warning in adf.test(Deltax): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: Deltax
## Dickey-Fuller = -6.11, Lag order = 5, p-value = 0.01
## alternative hypothesis: stationary
\[ NÜFUS-BÜYÜME-ORANI \]
library(WDI)
nufus <- WDI(country=c("CN", "AF","SY"), indicator=c("SP.POP.GROW"), start=1960, end=2020)
names(nufus) <- c("iso2c", "Ulke", "NufusBuyumeOrani", "Sene")
head(nufus)
## iso2c Ulke NufusBuyumeOrani Sene
## 1 AF Afghanistan 2.303812 2020
## 2 AF Afghanistan 2.313073 2019
## 3 AF Afghanistan 2.384309 2018
## 4 AF Afghanistan 2.547833 2017
## 5 AF Afghanistan 2.778035 2016
## 6 AF Afghanistan 3.077054 2015
library(ggplot2)
ggplot(nufus, aes(Sene, NufusBuyumeOrani, color=Ulke, linetype=Ulke)) + geom_line()
## Warning: Removed 3 row(s) containing missing values (geom_path).
CN <- cbind(nufus$NufusBuyumeOrani[nufus$Ulke == "China"], nufus$Sene[nufus$Ulke == "China"])
CN <- CN[order(CN[,2]),]
CN
## [,1] [,2]
## [1,] NA 1960
## [2,] -1.0155278 1961
## [3,] 0.8204555 1962
## [4,] 2.4576474 1963
## [5,] 2.3206830 1964
## [6,] 2.3813681 1965
## [7,] 2.7873318 1966
## [8,] 2.5706976 1967
## [9,] 2.6109026 1968
## [10,] 2.7400021 1969
## [11,] 2.7616756 1970
## [12,] 2.7469155 1971
## [13,] 2.4573569 1972
## [14,] 2.2833954 1973
## [15,] 2.0659550 1974
## [16,] 1.7663918 1975
## [17,] 1.5473380 1976
## [18,] 1.3627795 1977
## [19,] 1.3381823 1978
## [20,] 1.3339280 1979
## [21,] 1.2542211 1980
## [22,] 1.2809523 1981
## [23,] 1.4726748 1982
## [24,] 1.4449497 1983
## [25,] 1.3120688 1984
## [26,] 1.3616991 1985
## [27,] 1.4873989 1986
## [28,] 1.6036051 1987
## [29,] 1.6100711 1988
## [30,] 1.5331700 1989
## [31,] 1.4673032 1990
## [32,] 1.3644340 1991
## [33,] 1.2255362 1992
## [34,] 1.1496194 1993
## [35,] 1.1302606 1994
## [36,] 1.0865092 1995
## [37,] 1.0481415 1996
## [38,] 1.0234500 1997
## [39,] 0.9595504 1998
## [40,] 0.8658514 1999
## [41,] 0.7879566 2000
## [42,] 0.7263806 2001
## [43,] 0.6699996 2002
## [44,] 0.6228609 2003
## [45,] 0.5939328 2004
## [46,] 0.5881250 2005
## [47,] 0.5583744 2006
## [48,] 0.5222719 2007
## [49,] 0.5123869 2008
## [50,] 0.4973814 2009
## [51,] 0.4829597 2010
## [52,] 0.5464576 2011
## [53,] 0.6783455 2012
## [54,] 0.6660730 2013
## [55,] 0.6303264 2014
## [56,] 0.5814561 2015
## [57,] 0.5730509 2016
## [58,] 0.6052450 2017
## [59,] 0.4676721 2018
## [60,] 0.3547409 2019
## [61,] 0.2259476 2020
CN <- ts(CN[,1], start=min(nufus$Sene), end=max(nufus$Sene))
plot(CN, ylab="Nufus Buyume Orani", xlab="Sene")
library(dynlm)
Ilkgecikme <- dynlm(CN ~ L(CN, 1))
summary(Ilkgecikme)
##
## Time series regression with "ts" data:
## Start = 1962, End = 2020
##
## Call:
## dynlm(formula = CN ~ L(CN, 1))
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.29126 -0.15387 -0.08725 0.00153 1.54702
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.21753 0.08092 2.688 0.0094 **
## L(CN, 1) 0.84478 0.05451 15.498 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.3247 on 57 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.8082, Adjusted R-squared: 0.8048
## F-statistic: 240.2 on 1 and 57 DF, p-value: < 2.2e-16
Ikincigecikme <- dynlm(CN ~ L(CN, 2))
summary(Ikincigecikme)
##
## Time series regression with "ts" data:
## Start = 1963, End = 2020
##
## Call:
## dynlm(formula = CN ~ L(CN, 2))
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.49134 -0.25942 -0.12898 0.08636 2.79305
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.38536 0.12559 3.068 0.00331 **
## L(CN, 2) 0.70974 0.08393 8.457 1.38e-11 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4939 on 56 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.5608, Adjusted R-squared: 0.553
## F-statistic: 71.52 on 1 and 56 DF, p-value: 1.378e-11
Ucuncugecikme <- dynlm(CN ~ L(CN, 3))
summary(Ucuncugecikme)
##
## Time series regression with "ts" data:
## Start = 1964, End = 2020
##
## Call:
## dynlm(formula = CN ~ L(CN, 3))
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.5790 -0.2733 -0.1402 0.1115 2.6177
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.39348 0.13073 3.010 0.00394 **
## L(CN, 3) 0.67991 0.08668 7.844 1.56e-10 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5051 on 55 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.528, Adjusted R-squared: 0.5195
## F-statistic: 61.53 on 1 and 55 DF, p-value: 1.565e-10
AR10 <- dynlm(CN ~ L(CN, c(1:10)))
summary(AR10)
##
## Time series regression with "ts" data:
## Start = 1971, End = 2020
##
## Call:
## dynlm(formula = CN ~ L(CN, c(1:10)))
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.153799 -0.026897 -0.003844 0.028790 0.151033
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.0064475 0.0229402 0.281 0.780152
## L(CN, c(1:10))zoo(coredata(x), tt).1 1.7751671 0.1673650 10.607 4.7e-13
## L(CN, c(1:10))zoo(coredata(x), tt).2 -1.2474057 0.3328002 -3.748 0.000577
## L(CN, c(1:10))zoo(coredata(x), tt).3 0.8773870 0.3764456 2.331 0.025032
## L(CN, c(1:10))zoo(coredata(x), tt).4 -0.7368314 0.3704370 -1.989 0.053739
## L(CN, c(1:10))zoo(coredata(x), tt).5 0.5726644 0.3403353 1.683 0.100434
## L(CN, c(1:10))zoo(coredata(x), tt).6 -0.7134078 0.2835037 -2.516 0.016081
## L(CN, c(1:10))zoo(coredata(x), tt).7 0.5997102 0.2280475 2.630 0.012166
## L(CN, c(1:10))zoo(coredata(x), tt).8 -0.2021611 0.1831883 -1.104 0.276543
## L(CN, c(1:10))zoo(coredata(x), tt).9 0.0456964 0.1381970 0.331 0.742670
## L(CN, c(1:10))zoo(coredata(x), tt).10 -0.0004422 0.0541377 -0.008 0.993525
##
## (Intercept)
## L(CN, c(1:10))zoo(coredata(x), tt).1 ***
## L(CN, c(1:10))zoo(coredata(x), tt).2 ***
## L(CN, c(1:10))zoo(coredata(x), tt).3 *
## L(CN, c(1:10))zoo(coredata(x), tt).4 .
## L(CN, c(1:10))zoo(coredata(x), tt).5
## L(CN, c(1:10))zoo(coredata(x), tt).6 *
## L(CN, c(1:10))zoo(coredata(x), tt).7 *
## L(CN, c(1:10))zoo(coredata(x), tt).8
## L(CN, c(1:10))zoo(coredata(x), tt).9
## L(CN, c(1:10))zoo(coredata(x), tt).10
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.06345 on 39 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.9899, Adjusted R-squared: 0.9873
## F-statistic: 383.1 on 10 and 39 DF, p-value: < 2.2e-16
n<-200
u <- ts(rnorm(n))
v <- ts(rnorm(n))
y <- ts(rep(0,n))
for (t in 2:n){
y[t]<- y[t-1]+u[t]
}
x <- ts(rep(0,n))
for (t in 2:n){
x[t]<- x[t-1]+v[t]
}
plot(y,type='l', ylab="y[t-1]+u[t]")
plot(x,type='l', ylab="x[t-1]+v[t]")
Spurious <- lm(y~x)
summary(Spurious)
##
## Call:
## lm(formula = y ~ x)
##
## Residuals:
## Min 1Q Median 3Q Max
## -9.517 -4.091 1.121 4.571 8.544
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -4.92903 0.61608 -8.001 1.02e-13 ***
## x -0.06445 0.05331 -1.209 0.228
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.961 on 198 degrees of freedom
## Multiple R-squared: 0.007328, Adjusted R-squared: 0.002315
## F-statistic: 1.462 on 1 and 198 DF, p-value: 0.2281
duragan <- dynlm(d(y) ~ d(x))
summary(duragan)
##
## Time series regression with "ts" data:
## Start = 2, End = 200
##
## Call:
## dynlm(formula = d(y) ~ d(x))
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.43458 -0.70252 -0.03582 0.71794 2.58849
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.001492 0.072672 -0.021 0.984
## d(x) 0.013001 0.073656 0.177 0.860
##
## Residual standard error: 1.018 on 197 degrees of freedom
## Multiple R-squared: 0.0001581, Adjusted R-squared: -0.004917
## F-statistic: 0.03115 on 1 and 197 DF, p-value: 0.8601
library(tseries)
adf.test(x)
##
## Augmented Dickey-Fuller Test
##
## data: x
## Dickey-Fuller = -2.7486, Lag order = 5, p-value = 0.2626
## alternative hypothesis: stationary
adf.test(y)
##
## Augmented Dickey-Fuller Test
##
## data: y
## Dickey-Fuller = -1.2932, Lag order = 5, p-value = 0.8721
## alternative hypothesis: stationary
kpss.test(TR)
##
## KPSS Test for Level Stationarity
##
## data: TR
## KPSS Level = 0.65122, Truncation lag parameter = 2, p-value = 0.01798
Deltax <- diff(x)
adf.test(Deltax)
## Warning in adf.test(Deltax): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: Deltax
## Dickey-Fuller = -5.8536, Lag order = 5, p-value = 0.01
## alternative hypothesis: stationary