where $x_h^ {\left( i \right)}$ are the N historical observations with standard deviation $\sigma_h$ and $\Phi$ is the cumulative distribution function of the standard normal distribution.
We can implement this approach as an example for China GDP as follows.
$\$
Applying it to all series example quantiles gives:
$\$
(sample_kde_de <- kde(x = gdp$de, quantile = 1.3))
# Visualization
We can visualize the KDE against the normal distribution for a range of sample quantiles.
$\\$
```{r}
sample_quantiles <-
seq(from = -10, to = 20, by = 0.01)
We create a function to generate a vector of probabilities for the sample quantiles (given large enough size, the curve is smooth). Simultaneously, we draw the probabilities from a normal distribution with same mean and standard deviation.
$\$
We can plot the KDE-derived cumulative distribution function against the one that is derived from the normal distribution. One could create a generic plotting function to safe some typing.
$\$
kde_all %>%
ggplot(aes(x = sample_quantiles)) +
geom_line(aes(y = kde_de, color = "kde_de")) +
geom_line(aes(y = sdnorm_de, color = "sdnorm_de")) +
labs(title = "KDE vs Normal for DE", x = "Quantile", y = "P(x) \n")
The formula to compute the corresponding quantile of a given forecast $x_f$ is
$$CDF_{KDE} \left( xf \right) = 1- \frac{1}{N} \sum{i=1}^{N} \Phi \left( \frac{x_h^ {\left( i \right)} - x_f}{\frac{1}{2} \sigma_h} \right)$$
where $x_h^ {\left( i \right)}$ are the N historical observations with standard deviation $\sigma_h$ and $\Phi$ is the cumulative distribution function of the standard normal distribution.
We can implement this approach as an example for China GDP as follows. $\$
Functional approach
We can create a function for parametric usage as follows. $\$
Applying it to all series example quantiles gives: $\$
We create a function to generate a vector of probabilities for the sample quantiles (given large enough size, the curve is smooth). Simultaneously, we draw the probabilities from a normal distribution with same mean and standard deviation. $\$
\pagebreak
We can plot the KDE-derived cumulative distribution function against the one that is derived from the normal distribution. One could create a generic plotting function to safe some typing. $\$