3
$\begingroup$

I have a set of observation, let's call it $X$ and would like to fit a cdf to it. $X$ has a distribution which is roughly approximable with the normal distribution. This CDF should correspond to a continuous distribution function.

So far I've used a parametric approach by estimating mean and standard deviation and using a normal cdf but I would like to know what other options are available and how to use them.

How does the set of available option change if I require the cdf to be a smooth curve?

$\endgroup$
4
  • 1
    $\begingroup$ Search our site for kernel density estimation (or try the kernel-density-estimate tag, on which there are hundreds of posts. For example, there's one with pictures here. There are other forms of nonparametric density estimation, but this is the most common. There's also wikipedia. It's a standard function in many stats packages. ... ctd $\endgroup$
    – Glen_b
    Commented Oct 5, 2015 at 23:10
  • $\begingroup$ ctd ... this gives a smooth pdf, as a finite mixture of the density of the kernel. One way to get a smooth cdf, is to take the cdf corresponding to that kernel and take the same mixture over it. (... now I read the answer more closely, I see that's what it's getting at, but I'll leave my comment as it offers more detail, including an easy way to get a bandwidth, even if it's not optimal for the cdf). $\endgroup$
    – Glen_b
    Commented Oct 5, 2015 at 23:23
  • $\begingroup$ A rougher but simpler method to program would simply cumulate the density (scaled by the gap in x-values), which you could do in R like so: y=rgamma(100,10,1);plot(ecdf(y));d=density(y); lines(d$x,cumsum(d$y)*(d$x[2]-d$x[1]),type="l",col=2,lwd=2) $\endgroup$
    – Glen_b
    Commented Oct 6, 2015 at 0:12
  • $\begingroup$ To get the first thing, replace that "lines" command above with something like (remove semicolons if you don't do it all on one line): h=d(y)$bw; r=diff(range(y)); xx=seq(min(y)-r/10,max(y)+r/7,.1); cdf=rowSums(outer(xx,y,function(x,y) pnorm(x,y,h)))/length(y); lines(xx,cdf,col=4,lwd=2) $\endgroup$
    – Glen_b
    Commented Oct 6, 2015 at 0:18

1 Answer 1

6
$\begingroup$

Let $F(x)$ be the CDF of $\mathcal{N}(0,1)$. For various positive real values of $h$ you could compute: $$ G_h(x) = \frac{h}{N} \sum_{i=1}^{n} F\left(h \cdot (x_i-x)\right). $$

This is the resulting CDF from doing Kernel Density Estimation (KDE) with a Gaussian Kernel. Essentially, that is, replacing each of your data points with a small Normal Distribution. Unfortunately, I don't have time to write the R code.

$\endgroup$
5
  • $\begingroup$ ok that's fine, I upvoted anyway since it is useful, thanks. $\endgroup$
    – mickkk
    Commented Oct 5, 2015 at 20:34
  • 1
    $\begingroup$ A more usual notation would use a capital letter for cdf and reserve a lower case for pdf. Similarity to the usual exposition for a kernel density estimate (combined with explicit mention of it) tricked me for a minute, until I read more closely. I imagine I wouldn't be the only one. $\endgroup$
    – Glen_b
    Commented Oct 5, 2015 at 23:21
  • $\begingroup$ @Glen_b Edited, thanks. My phone alerted me that someone said it was the PDF, and when I got here all I saw was this nice message. Always feel free to edit my posts (if you could possibly remember this comment) $\endgroup$ Commented Oct 6, 2015 at 0:41
  • $\begingroup$ If it suits you, feel free to use the R code in the comment above. $\endgroup$
    – Glen_b
    Commented Oct 6, 2015 at 2:13
  • 2
    $\begingroup$ @jlimahaverford: I think there is a slight mistake in that the factor $h$ should not appear in front, contrary to the density estimate (as it integrates out by a change of variable). $\endgroup$
    – Xi'an
    Commented May 24, 2016 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.