---
title: "Introduction to combcoint"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Introduction to combcoint}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  echo = TRUE,
  collapse = TRUE,
  comment = "#>"
)
```

```{r setup, include = FALSE}
library(combcoint)
```

# Overview
The `combcoint` package implements the combined non-cointegration test developed by Bayer and Hanck (2013) <doi:10.1111/j.1467-9892.2012.00814.x>. This statistical approach improves the reliability of cointegration detection by aggregating p-values from multiple individual cointegration tests into a single joint test statistic. Specifically, it combines the outcomes of the Engle-Granger, Johansen, Boswijk and Banerjee tests using a Fisher-type combination method. The approach enhances the power and robustness of cointegration testing, particularly in situations where individual tests yield mixed or inconclusive results.

# Methodology
The combined test aggregates p-values from the following individual cointegration tests:
*Engle-Granger
*Johansen
*Boswijk
*Banerjee

The combined test statistic is calculated using Fisher’s combination formula:

$$C = -2 \sum_{i=1}^{k} \ln(p_i)$$
where $p_i$ are the $p$-values from the individual tests. Under the null hypothesis of no cointegration, C follows a chi-squared distribution with 2$\cdot$k degrees of freedom.

# Installation
You can install the package from CRAN:
```{r, eval=FALSE}
install.packages("combcoint")
```

Or from GitHub
```{r, eval=FALSE}
remotes::install_github("Janine-Langerbein/combcoint")
```


# Dataset
The package includes an example dataset taken from Luetkepohl (2007) <http://www.jmulti.de/download/datasets/e1.dat>, often used for cointegration testing exercises.

The dataset is automatically available when the package is loaded. You can load it as follows:
```{r}
data("lutkepohl_e1")
```

# Applied Example
We demonstrate the application of both the classical Engle-Granger cointegration test and the combined Bayer-Hanck cointegration test using the dataset `lutkepohl_e1` included in the package.

We first apply the Engle-Granger test:
```{r}
englegranger(linvestment ~ lincome + lconsumption, data = lutkepohl_e1)
```

Next, we apply the combined cointegration test on the same dataset:
```{r}
bayerhanck(linvestment ~ lincome + lconsumption, data = lutkepohl_e1)
```
By default, the function uses the lags = 1. Optionally, the user can specify the lag length manually, e.g., with 4 lags:
```{r}
bayerhanck(linvestment ~ lincome + lconsumption, data = lutkepohl_e1, lags = 4)
```
