An open API service indexing awesome lists of open source software.

https://github.com/inseefr/jdcruncher

Interface entre le cruncher JDemetra+ et R et création de bilans qualité
https://github.com/inseefr/jdcruncher

extension jdemetra jwsacruncher quality-assessment r r-package

Last synced: 8 months ago
JSON representation

Interface entre le cruncher JDemetra+ et R et création de bilans qualité

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.align = "center",
fig.path = "README-"
)
```

# **{JDCruncheR}**

[![CRAN status](https://www.r-pkg.org/badges/version/JDCruncheR)](https://cran.r-project.org/package=JDCruncheR)
[![Linting code](https://github.com/InseeFr/JDCruncheR/actions/workflows/lint.yaml/badge.svg)](https://github.com/InseeFr/JDCruncheR/actions/workflows/lint.yaml)
[![R-CMD-check](https://github.com/InseeFr/JDCruncheR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/InseeFr/JDCruncheR/actions/workflows/R-CMD-check.yaml)



## [🇫🇷 README en français](#présentation) | [🇬🇧 README in english](#overview)

### Présentation

Le but premier du package **{JDCruncheR}** est de fournir un accès rapide et facile au cruncher (`JWSACruncher`) depuis R. Le cruncher est un outil de mise à jour des workspaces de JDemetra+ sans avoir à ouvrir la GUI (Graphical User Interface). La dernière version peut être téléchargée ici : https://github.com/jdemetra/jwsacruncher/releases. Pour plus d'information, vous pouvez visiter la page [wiki](https://github.com/jdemetra/jwsacruncher/wiki).

Avec **{JDCruncheR}**, vous pouvez aussi générer des *bilans qualité* utilisant l'output du cruncher. Ce bilan est un résumé des diagnostiques de la désaisonnalisation. Il peut être utilisé pour repérer les séries les plus problématiques qui nécessitent une analyse plus fine. Cela est très utile lorsqu'on a beaucoup de séries à désaisonnaliser.

### Installation

**🎉 {JDCruncheR} est maintenant disponible sur le CRAN ! 🎉**

Pour installer, il suffit de lancer la ligne de code suivante :

```{r fr-CRAN-installation, eval = FALSE}
install.packages("JDCruncheR")
```

Pour obtenir la version en cours de développement depuis GitHub :

```{r fr-gh-devel-installation, eval = FALSE}
# Si le package remotes n'est pas installé
# install.packages("remotes")

# Installer la version en cours de développement depuis GitHub
remotes::install_github("InseeFr/JDCruncheR")
```

### Usage

#### Chargement du package

```{r fr-loading-JDCruncheR, eval = TRUE}
library("JDCruncheR")
```

#### Changer les seuils des tests statistiques

Les seuils des tests du bilan qualité sont personnalisables.
Pour cela, il faut modifier l'option `"jdc_thresholds"`.

Pour récupérer les valeurs des tests par défault, il faut appeler la fonction `get_thresholds()` :

```{r fr-get-threshold, eval = TRUE}
get_thresholds("m7", default = TRUE)
get_thresholds(default = TRUE)
```

Pour changer la valeur de l'option, on peut utiliser la fonction `set_thresholds()` :

```{r fr-set-threshold, eval = TRUE}
# Fixer les seuils à une certaine valeur
set_thresholds(test_name = "m7", thresholds = c(Good = 0.8, Bad = 1.4, Severe = Inf))
get_thresholds(test_name = "m7", default = FALSE)

# Remettre tous les seuils à leur valeur par défaut
set_thresholds()
get_thresholds(test_name = "m7", default = FALSE)
```

#### Changer les notes des modalités `Good`, `Uncertain`, `Bad` et `Severe`

Le mécanisme est le même que pour les seuils des tests statistiques avec la valeur `"grade"` :

Pour récupérer la valeur par défault des notes, il faut appeler la fonction `get_thresholds()` :

```{r fr-get-grade, eval = TRUE}
get_thresholds("grade", default = TRUE)
```

Pour changer la valeur de la note, on peut utiliser la fonction `set_thresholds()` :

```{r fr-set-grade, eval = TRUE}
# Fixer les notes à une certaine valeur
set_thresholds(test_name = "grade", thresholds = c(Good = 0, Uncertain = 0.1, Bad = 1, Severe = 10))
get_thresholds(test_name = "grade", default = FALSE)
```

#### Calculer un bilan qualité

Par exemple, en partant d'une matrice `demetra_m.csv` :

| | n | start | end | mean | skewness | | kurtosis | | lb2 | | p | d | q | bp | bd | bq | m7 | q | q.m2 |
|--------|-----|------------|------------|------|----------|-----|----------|-----|------|-----|---|---|---|----|----|----|-----|-----|------|
| France | 88 | 2012-10-01 | 2020-01-01 | 0.6 | 0.0 | 0.9 | 2.9 | 0.8 | 36.1 | 0.0 | 0 | 1 | 1 | 0 | 1 | 1 | 0.2 | 0.5 | 2.0 |
| Spain | 78 | 2015-10-01 | 2022-03-01 | 0.4 | -0.4 | 0.0 | 4.6 | 0.0 | 17.3 | 0.7 | 0 | 0 | 1 | 0 | 1 | 1 | 0.8 | 1.5 | 1.3 |
| Greece | 112 | 2010-10-01 | 2020-01-01 | 0.5 | -0.3 | 0.0 | 3.7 | 0.0 | 46.9 | 0.0 | 3 | 1 | 1 | 0 | 1 | 1 | 0.3 | 0.4 | 0.8 |

On peut générer un bilan qualité :

```{r fr-set-demetra_m, eval = TRUE, echo = FALSE}
demetra_m <- data.frame(
X = c("France", "Spain", "Greece"),
n = c(88L, 78L, 112L),
start = c("2012-10-01", "2015-10-01", "2010-10-01"),
end = c("2020-01-01", "2022-03-01", "2020-01-01"),
mean = c(0.608599, 0.418266, 0.51853),
skewness = c(0.014553, -0.414881, -0.336935),
X.1 = c(0.9093, 0.0011, 0.0083),
kurtosis = c(2.931535, 4.628171, 3.739243),
X.2 = c(0.7886, 0, 0.0038),
lb2 = c(36.14241, 17.263369, 46.853219),
X.3 = c(0.0293, 0.7487, 4e-04),
p = c(0L, 0L, 3L),
d = c(1L, 0L, 1L),
q = c(1L, 1L, 1L),
bp = c(0L, 0L, 0L),
bd = c(1L, 1L, 1L),
bq = c(1L, 1L, 1L),
m7 = c(0.239737242, 0.785293416, 0.309003156),
q.1 = c(0.510868052, 1.524804319, 1.131292538),
q.m2 = c(2.00493169, 1.342476763, 0.816821294),
stringsAsFactors = FALSE
)
```

```{r fr-extract_QR, eval = TRUE, warning = FALSE}
BQ <- extract_QR(x = demetra_m)
print(BQ$modalities)
```

#### Calculer un score

Il est possible maintenant de calculer un score à partir du bilan qualité

```{r fr-compute_score, eval = TRUE, warning = FALSE}
BQ_score <- compute_score(
x = BQ,
score_pond = c(
oos_mean = 15L,
residuals_kurtosis = 15L,
residuals_homoskedasticity = 5L,
residuals_skewness = 5L,
m7 = 5L,
q_m2 = 5L
)
)
extract_score(x = BQ_score)
```

#### Exporter un bilan qualité

Enfin il est possible d'exporter un bilan qualité via la fonction `export_xlsx`.

### Autres informations

Pour plus d'informations sur l'installation et la configuration du package **{JDCruncheR}**, vous pouvez visiter la page [wiki](https://github.com/jdemetra/jwsacruncher/wiki)

Pour une description plus complète des packages R pour JDemetra+ voir le document de travail Insee [Les packages R pour JDemetra+ : une aide à la désaisonnalisation](https://www.insee.fr/fr/statistiques/5019786)

### Overview

The primary objective of the **{JDCruncheR}** package is to provide a quick and easy access to the JDemetra+ cruncher (`JWSACruncher`) from R. The cruncher is a tool for updating JDemetra+ workspaces, without having to open the graphical user interface. The latest version can be downloaded here: . For more information, please refer to the [wiki page](https://github.com/jdemetra/jwsacruncher/wiki).

With **{JDCruncheR}**, you can also generate a *quality report* based on the cruncher's output. This report is a formatted summary of the seasonal adjustment process master diagnostics and parameters. It can be used to spot the most problematic series which will require a finer analysis. This is most useful when dealing with a large number of series.

### Installation

**🎉 {JDCruncheR} is now available on CRAN! 🎉**

To install it, you have to launch the following command line:

```{r en-CRAN-installation, eval = FALSE}
install.packages("JDCruncheR")
```

To get the current development version from GitHub:

```{r en-gh-devel-installation, eval = FALSE}
# If remotes packages is not installed
# install.packages("remotes")

# Install development version from GitHub
remotes::install_github("InseeFr/JDCruncheR")
```

### Usage

#### Loading the package

```{r en-loading-JDCruncheR, eval = TRUE}
library("JDCruncheR")
```

#### Changing statistical test thresholds

The thresholds of the QR tests can be customised
You have to modify the option `"jdc_thresholds"`.

To get the (default or not) values of the thresholds of the tests, you can call the fonction `get_thresholds()` :

```{r en-get-threshold, eval = TRUE}
get_thresholds("m7")
get_thresholds(default = TRUE)
```

To change the value of the option, you can use the fonction `set_thresholds()`:

```{r en-set-threshold, eval = TRUE}
# Set threshold to imposed value
set_thresholds(test_name = "m7", thresholds = c(Good = 0.8, Bad = 1.4, Severe = Inf))
get_thresholds(test_name = "m7", default = FALSE)

# Reset all thresholds to default
set_thresholds()
get_thresholds(test_name = "m7", default = FALSE)
```

#### Changing the scores for the `Good`, `Uncertain`, `Bad` and `Severe` modalities

The mechanism is the same as for the statistical test thresholds with the `"grade"` value:

To retrieve the default grade value, call the `get_thresholds()` function:

```{r en-get-grade, eval = TRUE}
get_thresholds("grade", default = TRUE)
```

To change the value of the grade, you can use the `set_thresholds()` function:

```{r en-set-grade, eval = TRUE}
# Set grades to a certain value
set_thresholds(test_name = "grade", thresholds = c(Good = 0, Uncertain = 0.1, Bad = 1, Severe = 10))
get_thresholds(test_name = "grade", default = FALSE)
```

#### Calculate a quality report

For example, starting from a matrix `demetra_m.csv` :

| | n | start | end | mean | skewness | | kurtosis | | lb2 | | p | d | q | bp | bd | bq | m7 | q | q.m2 |
|--------|-----|------------|------------|------|----------|-----|----------|-----|------|-----|---|---|---|----|----|----|-----|-----|------|
| France | 88 | 2012-10-01 | 2020-01-01 | 0.6 | 0.0 | 0.9 | 2.9 | 0.8 | 36.1 | 0.0 | 0 | 1 | 1 | 0 | 1 | 1 | 0.2 | 0.5 | 2.0 |
| Spain | 78 | 2015-10-01 | 2022-03-01 | 0.4 | -0.4 | 0.0 | 4.6 | 0.0 | 17.3 | 0.7 | 0 | 0 | 1 | 0 | 1 | 1 | 0.8 | 1.5 | 1.3 |
| Greece | 112 | 2010-10-01 | 2020-01-01 | 0.5 | -0.3 | 0.0 | 3.7 | 0.0 | 46.9 | 0.0 | 3 | 1 | 1 | 0 | 1 | 1 | 0.3 | 0.4 | 0.8 |

A quality report can be generated:

```{r en-set-demetra_m, eval = TRUE, echo = FALSE}
demetra_m <- data.frame(
X = c("France", "Spain", "Greece"),
n = c(88L, 78L, 112L),
start = c("2012-10-01", "2015-10-01", "2010-10-01"),
end = c("2020-01-01", "2022-03-01", "2020-01-01"),
mean = c(0.608599, 0.418266, 0.51853),
skewness = c(0.014553, -0.414881, -0.336935),
X.1 = c(0.9093, 0.0011, 0.0083),
kurtosis = c(2.931535, 4.628171, 3.739243),
X.2 = c(0.7886, 0, 0.0038),
lb2 = c(36.14241, 17.263369, 46.853219),
X.3 = c(0.0293, 0.7487, 4e-04),
p = c(0L, 0L, 3L),
d = c(1L, 0L, 1L),
q = c(1L, 1L, 1L),
bp = c(0L, 0L, 0L),
bd = c(1L, 1L, 1L),
bq = c(1L, 1L, 1L),
m7 = c(0.239737242, 0.785293416, 0.309003156),
q.1 = c(0.510868052, 1.524804319, 1.131292538),
q.m2 = c(2.00493169, 1.342476763, 0.816821294),
stringsAsFactors = FALSE
)
```

```{r en-extract_QR, eval = TRUE, warning = FALSE}
BQ <- extract_QR(x = demetra_m)
print(BQ$modalities)
```

#### Calculate a score

It is now possible to calculate a score from the quality report:

```{r en-compute_score, eval = TRUE, warning = FALSE}
BQ_score <- compute_score(
x = BQ,
score_pond = c(
oos_mean = 15L,
residuals_kurtosis = 15L,
residuals_homoskedasticity = 5L,
residuals_skewness = 5L,
m7 = 5L,
q_m2 = 5L
)
)
extract_score(x = BQ_score)
```

#### Exporting a quality report

Finally, you can export a quality report using the `export_xlsx` function.

### Other informations

For more informations on installing and configuring the **{JDCruncheR}** package, you can visit the [wiki](https://github.com/jdemetra/jwsacruncher/wiki) page.

For a more comprehensive description of the R packages for JDemetra+ check the Insee working paper [R Tools for JDemetra+: Seasonal adjustment made easier](https://www.insee.fr/en/statistiques/5019812)