I've got a univariate dataset (timeseries) for two kind of simulated systems, and I want to explore the differences between the two.
To do that, I can build a univariate gaussian KDE for each dataset and check the differences in the densities. I am attaching an example of what the two time series I want to compare look like, as well as the pdf's I obtain using R's package ggplot2 (sorry for the color mismatch, green time series data is the blue line in the density plot).
My problem is that the shape of the distribution depends on the amount of data that I use to construct it, and the two datasets that I have to compare actually have different amount of data. The dataset comes from the distance between two atoms in a Molecular Dynamics simulation, and as you can see it contains a fair bit of history-dependence.
I was wondering if one could apply a resampling technique such as cross-validation or bootstrap to this problem and estimate a range of uncertainty for the density plots, to compare the distributions in a more statistically-rigorous way.
Any comments will be of much help.
Best Answer
Here is a simple bootstrap approach to estimate (pointwise!) confidence bands around a kernel density estimate
$$\widehat f(x)=\frac{1}{nh}\sum^n_{i=1}k\left(\frac{x_i-x}{h}\right).$$ Basically, you just resample a bootstrap sample
xstar
from your original samplex
($=x_1,\ldots,x_n$), compute a new kernel density estimatedstar
, do thatB
times and then compute quantiles from the resulting distribution at each evaluation point in the vectorxax
(all the different $x$ at which you desire a density estimate, I takeevalpoints
$=100$ equispaced points from $-3$ to $3$ here) of the kernel density estimates.Result:
Suggestions for references for nonparametric estimation can be found here: Book for introductory nonparametric econometrics/statistics