Call:
lm(formula = LCANGBP ~ LPCAN + LPGBP, data = tsdiff)
Residuals:
Min 1Q Median 3Q Max
-0.090594 -0.006432 0.004908 0.012063 0.045436
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.014362 0.002909 -4.937 7.27e-06 ***
LPCAN -0.952632 0.069827 -13.643 < 2e-16 ***
LPGBP 0.889222 0.039567 22.474 < 2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.02231 on 57 degrees of freedom
Multiple R-squared: 0.9122, Adjusted R-squared: 0.9091
F-statistic: 296.2 on 2 and 57 DF, p-value: < 2.2e-16
Call:
lm(formula = LCANGBP ~ LPCAN + LPGBP + fitted_sq, data = tsdiff)
Residuals:
Min 1Q Median 3Q Max
-0.088881 -0.006975 0.002050 0.011550 0.044398
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.010408 0.003609 -2.884 0.00556 **
LPCAN -0.952956 0.068514 -13.909 < 2e-16 ***
LPGBP 0.869412 0.040369 21.537 < 2e-16 ***
fitted_sq -0.751761 0.419816 -1.791 0.07875 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.02189 on 56 degrees of freedom
Multiple R-squared: 0.917, Adjusted R-squared: 0.9125
F-statistic: 206.1 on 3 and 56 DF, p-value: < 2.2e-16
Shapiro-Francia normality test
data: residu
W = 0.85317, p-value = 1.548e-05
studentized Breusch-Pagan test
data: fit
BP = 0.24178, df = 2, p-value = 0.8861
Durbin-Watson test
data: fit
DW = 0.95565, p-value = 4.015e-06
alternative hypothesis: true autocorrelation is greater than 0
Breusch-Godfrey test for serial correlation of order up to 4
data: fit
LM test = 20.537, df = 4, p-value = 0.0003911
RESET test
data: fit
RESET = 2.9673, df1 = 2, df2 = 55, p-value = 0.05973
Linear hypothesis test
Hypothesis:
LPCAN = - 1
LPGBP = 1
Model 1: restricted model
Model 2: LCANGBP ~ LPCAN + LPGBP
Res.Df RSS Df Sum of Sq F Pr(>F)
1 59 0.032272
2 57 0.028364 2 0.0039079 3.9266 0.02526 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Augmented Dickey-Fuller Test
data: timeseries[, "LPCAN"]
Dickey-Fuller = -2.4367, Lag order = 3, p-value = 0.3982
alternative hypothesis: stationary
Augmented Dickey-Fuller Test
data: timeseries[, "LPGBP"]
Dickey-Fuller = -4.2747, Lag order = 3, p-value = 0.01
alternative hypothesis: stationary
Augmented Dickey-Fuller Test
data: tsdiff[, "LPCAN"]
Dickey-Fuller = -3.4135, Lag order = 3, p-value = 0.06224
alternative hypothesis: stationary
Augmented Dickey-Fuller Test
data: tsdiff[, "LPGBP"]
Dickey-Fuller = -5.0831, Lag order = 3, p-value = 0.01
alternative hypothesis: stationary
KPSS Test for Level Stationarity
data: timeseries[, "LPCAN"]
KPSS Level = 0.25524, Truncation lag parameter = 1, p-value = 0.1
KPSS Test for Level Stationarity
data: timeseries[, "LPGBP"]
KPSS Level = 2.4808, Truncation lag parameter = 1, p-value = 0.01
KPSS Test for Level Stationarity
data: tsdiff[, "LPCAN"]
KPSS Level = 0.10651, Truncation lag parameter = 1, p-value = 0.1
KPSS Test for Level Stationarity
data: tsdiff[, "LPGBP"]
KPSS Level = 0.063306, Truncation lag parameter = 1, p-value = 0.1
| Estimate | Std. Error | t value | Pr(>|t|) | |
|---|---|---|---|---|
| LPGBP | 1.028 | 0.006593 | 155.9 | 5.713e-80 |
Time series regression with "ts" data:
Start = 1951, End = 2010
Call:
dynlm(formula = d(ehat) ~ L(ehat) - 1)
Residuals:
Min 1Q Median 3Q Max
-0.177465 -0.055125 -0.003977 0.042022 0.179673
Coefficients:
Estimate Std. Error t value Pr(>|t|)
L(ehat) -0.07421 0.04442 -1.67 0.1
Residual standard error: 0.07843 on 59 degrees of freedom
Multiple R-squared: 0.04516, Adjusted R-squared: 0.02897
F-statistic: 2.79 on 1 and 59 DF, p-value: 0.1001
VAR Estimation Results:
=========================
Endogenous variables: Dc, Dy
Deterministic variables: const
Sample size: 59
Log Likelihood: 184.011
Roots of the characteristic polynomial:
0.3585 0.3585
Call:
VAR(y = varmat)
Estimation results for equation Dc:
===================================
Dc = Dc.l1 + Dy.l1 + const
Estimate Std. Error t value Pr(>|t|)
Dc.l1 0.309089 0.125788 2.457 0.0171 *
Dy.l1 0.148574 0.067888 2.189 0.0328 *
const 0.001074 0.005003 0.215 0.8308
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.03813 on 56 degrees of freedom
Multiple R-Squared: 0.1976, Adjusted R-squared: 0.169
F-statistic: 6.897 on 2 and 56 DF, p-value: 0.0021
Estimation results for equation Dy:
===================================
Dy = Dc.l1 + Dy.l1 + const
Estimate Std. Error t value Pr(>|t|)
Dc.l1 -0.132664 0.237520 -0.559 0.57870
Dy.l1 0.351940 0.128190 2.745 0.00811 **
const 0.005199 0.009447 0.550 0.58429
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.072 on 56 degrees of freedom
Multiple R-Squared: 0.1186, Adjusted R-squared: 0.08717
F-statistic: 3.769 on 2 and 56 DF, p-value: 0.02912
Covariance matrix of residuals:
Dc Dy
Dc 0.0014541 0.0003193
Dy 0.0003193 0.0051846
Correlation matrix of residuals:
Dc Dy
Dc 1.0000 0.1163
Dy 0.1163 1.0000
---
title: "Projekt z Ekonometrii finansowej"
author: "Patryk Formela"
output:
flexdashboard::flex_dashboard:
orientation: columns
#vertical_layout: fill
#social: menu
source_code: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(dygraphs)
library(xts)
library(pander)
dane <- read.csv(file = 'cw_4_PPP.csv', header = TRUE, sep = ',')
timeseries <- ts(dane, start = (1950), end = (2010), frequency(1))
can <- timeseries[,3]
```
Poziomy
=====================================
Column {data-width=350}
-----------------------------------------------------------------------
### CANGBP
```{r}
dygraph(timeseries[,16]) %>%
dySeries(label = "CANGBP")
```
### PCAN
```{r}
dygraph(timeseries[,4])%>%
dySeries(label = 'PCAN')
```
### PGBP
```{r}
dygraph(timeseries[,12])%>%
dySeries(label = 'PGBP')
```
Column {data-width=350}
------------------------------------------------------------------------
### LCANGBP
```{r}
dygraph(timeseries[,32])%>%
dySeries(label = 'LCANGBP')
```
### LPCAN
```{r}
dygraph(timeseries[,20])%>%
dySeries(label = 'LPCAN')
```
### LPGBP
```{r}
dygraph(timeseries[,28])%>%
dySeries(label = 'LPGBP')
```
```{r setupe, include=FALSE}
tsdiff <- diff(timeseries, differences = 1)
```
Różnice
=====================================
Column {data-width=350}
-----------------------------------------------------------------------
### DIFFCANGBP
```{r}
dygraph(tsdiff[,16]) %>%
dySeries(label = "CANGBP")
```
### DIFFPCAN
```{r}
dygraph(tsdiff[,4])%>%
dySeries(label = 'PCAN')
```
### DIFFPGBP
```{r}
dygraph(tsdiff[,12])%>%
dySeries(label = 'PGBP')
```
Column {data-width=350}
------------------------------------------------------------------------
### DIFFLCANGBP
```{r}
dygraph(tsdiff[,32])%>%
dySeries(label = 'LCANGBP')
```
### DIFFLPCAN
```{r}
dygraph(tsdiff[,20])%>%
dySeries(label = 'LPCAN')
```
### DIFFLPGBP
```{r}
dygraph(tsdiff[,28])%>%
dySeries(label = 'LPGBP')
```
```{r setupes, include=FALSE}
fit <- lm(LCANGBP ~ LPCAN + LPGBP, data = tsdiff)
```
Model
=====================================
Column {data-width=600}
------------------------------------------------------------------------
### Model
```{r}
summary(fit)
```
### Model z wartością wyrównaną
```{r, echo= FALSE}
fitedvalues <- fitted(fit)
```
```{r, echo= FALSE}
library(lmtest)
library(nortest)
library(car)
fitedvalues <- fitted(fit)
fitted_sq<- fitedvalues^2
fit2 <- lm(LCANGBP ~ LPCAN + LPGBP + fitted_sq, data = tsdiff)
residu <- residuals(fit)
```
```{r}
summary(fit2)
```
Column {.tabset}
-----------------------------------------------------------------------
### Test normalności
```{r}
sf.test(residu)
```
### Test na heteroskedastyczność
```{r}
bptest(fit)
```
### Test na autokorelację
```{r}
dwtest(fit, alternative = c("greater", "two.sided", "less"), iterations = 15)
```
### Seryjna autokorelacja
```{r}
bgtest(fit, order = 4, type = 'Chisq')
```
### Test na zgodność
```{r}
resettest(fit, power = 2:3, type = 'fitted')
```
### Test liniowych restrykcji
```{r}
linearHypothesis(fit, c('LPCAN = -1', 'LPGBP = 1'), test = 'F')
```
Row
------------------------------------------------------------------------
### Wykres funkcji acf
```{r}
acf(residu, type = 'correlation', plot = TRUE, lag.max = 25)
```
### Wykres funkcji pacf
```{r}
acf(residu, type = 'partial', plot = TRUE, lag.max = 25)
```
VAR, VECM
=====================================
Column{.tabset}
------------------------------------------------------------------------
```{r setap, include= FALSE}
library(tseries)
library(vars)
library(dynlm) #for function `dynlm()`
library(nlWaldTest) # for the `nlWaldtest()` function
library(broom) #for `glance(`) and `tidy()`
library(sandwich)
library(knitr) #for `kable()`
library(forecast)
```
### ADF tests LPCAN
```{r}
adf.test(timeseries[,'LPCAN'])
```
### ADF tests LPGBP
```{r}
adf.test(timeseries[,'LPGBP'])
```
### ADF tests dLPCAN
```{r}
adf.test(tsdiff[,'LPCAN'])
```
### ADF tests dLPGBP
```{r}
adf.test(tsdiff[,'LPGBP'], k = trunc((length(tsdiff[,1])-1)^(1/3)))
```
### KPSS tests LPCAN
```{r}
kpss.test(timeseries[,'LPCAN'])
```
### KPSS tests LPGBP
```{r}
kpss.test(timeseries[,'LPGBP'])
```
### KPSS tests dLPCAN
```{r}
kpss.test(tsdiff[,'LPCAN'])
```
### KPSS tests dLPGBP
```{r}
kpss.test(tsdiff[,'LPGBP'])
```
### Test kointegracji 1
```{r}
cint1.dyn <- dynlm(LPCAN~LPGBP-1, data=timeseries)
#kable(tidy(cint1.dyn), digits=4)
pander(cint1.dyn)
```
### Test kointegracji 2
```{r}
ehat <- resid(cint1.dyn)
cint2.dyn <- dynlm(d(ehat)~L(ehat)-1)
summary(cint2.dyn)
```
Column {data-width=600}
------------------------------------------------------------------------
### Model VAR
```{r}
library(vars)
Dc <- tsdiff[,'LPCAN']
Dy <- tsdiff[,'LPGBP']
varmat <- as.matrix(cbind(Dc,Dy))
varfit <- VAR(varmat) # `VAR()` from package `vars`
summary(varfit)
```
Źródła:
====================================
### Online
- [ADF, VAR](https://bookdown.org/ccolonescu/RPoE4/vec-and-var-models.html)
- [Restrykcje](https://stats.stackexchange.com/questions/211584/testing-linear-restriction-in-r)
- [Regresja](https://www.statmethods.net/stats/regression.html)