Dear R users, I would like to show the estimated density of a (0, 1) uniformly distributed random variable. The density curve, however, goes beyond 0 and 1 because of the kernel smoothing. Example: x = runif(10000) plot(density(x)) Is there a way to estimate the density curve strictly within (0, 1) and still use some sort of smoothing? Any help would be greatly appreciated. Best regards, Justine Rochon ________________________ Justine Rochon - Biostatistician - Center for Clinical Studies University Hospital Regensburg Franz-Josef-Strau?-Allee 11 D-93053 Regensburg Phone: ++49-(0)941-944-5626 Fax: ++49-(0)941-944-5632 Email: justine.rochon at klinik.uni-regensburg.de
Dear R users, I would like to show the estimated density of a (0, 1) uniformly distributed random variable. The density curve, however, goes beyond 0 and 1 because of the kernel smoothing. Example: x = runif(10000) plot(density(x)) Is there a way to estimate the density curve strictly within (0, 1) and still use some sort of smoothing? Any help would be greatly appreciated. Best regards, Justine Rochon -- GRATIS f?r alle GMX-Mitglieder: Die maxdome Movie-FLAT!
On 05/11/2009 4:35 AM, Justine Rochon wrote:> Dear R users, > > I would like to show the estimated density of a (0, 1) uniformly distributed > random variable. The density curve, however, goes beyond 0 and 1 because of the > kernel smoothing. > > Example: > > x = runif(10000) > plot(density(x)) > > Is there a way to estimate the density curve strictly within (0, 1) and still > use some sort of smoothing? > > Any help would be greatly appreciated.One way is to extend the data by reflection on each end. That is, x <- runif(10000) ex_x <- c(-x, x, 2-x) den <- density(ex_x) plot(den$x, 3*den$y, xlim=c(0,1), type="l") You need the rescaling to 3*den$y because you've tripled the range. Duncan Murdoch
I think the cleanest solution would be to use kernels whose support is (included in) (0,1). For example you could use Beta kernels instead of Normal kernels. Implementing this approach requires a little work, though -- but not much if you just want a density estimate. Best, Giovanni ps: please do not post the same question multiple times.> Date: Thu, 05 Nov 2009 10:35:21 +0100 > From: Justine Rochon <Justine.Rochon at klinik.uni-regensburg.de> > Sender: r-help-bounces at r-project.org > Precedence: list > > Dear R users, > > I would like to show the estimated density of a (0, 1) uniformly distributed > random variable. The density curve, however, goes beyond 0 and 1 because of the > kernel smoothing. > > Example: > > x = runif(10000) > plot(density(x)) > > Is there a way to estimate the density curve strictly within (0, 1) and still > use some sort of smoothing? > > Any help would be greatly appreciated. > > Best regards, > > Justine Rochon > > > > ________________________ > Justine Rochon > - Biostatistician - > Center for Clinical Studies > University Hospital Regensburg > Franz-Josef-Strau?-Allee 11 > D-93053 Regensburg > Phone: ++49-(0)941-944-5626 > Fax: ++49-(0)941-944-5632 > Email: justine.rochon at klinik.uni-regensburg.de > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > >-- Giovanni Petris <GPetris at uark.edu> Associate Professor Department of Mathematical Sciences University of Arkansas - Fayetteville, AR 72701 Ph: (479) 575-6324, 575-8630 (fax) http://definetti.uark.edu/~gpetris/
You may be interested in the logspline package. It uses a different method from kernel density estimation, but it estimates densities from data and allows the specification of lower and/or upper bounds. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Justine Rochon > Sent: Thursday, November 05, 2009 2:38 AM > To: r-help at r-project.org > Subject: [R] Density estimate with bounds > > Dear R users, > > I would like to show the estimated density of a (0, 1) uniformly > distributed random variable. The density curve, however, goes beyond 0 > and 1 because of the kernel smoothing. > > Example: > > x = runif(10000) > plot(density(x)) > > Is there a way to estimate the density curve strictly within (0, 1) and > still use some sort of smoothing? > > Any help would be greatly appreciated. > > Best regards, > > Justine Rochon > > -- > GRATIS f?r alle GMX-Mitglieder: Die maxdome Movie-FLAT! > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.
Hi Greg, Thank you very much for your help. The logspline package seems to solve the problem. Best regards, Justine -------- Original-Nachricht --------> Datum: Thu, 5 Nov 2009 11:11:31 -0700 > Von: Greg Snow <Greg.Snow at imail.org> > An: Justine Rochon <rochon at gmx.de>, "r-help at r-project.org" <r-help at r-project.org> > Betreff: RE: [R] Density estimate with bounds> You may be interested in the logspline package. It uses a different > method from kernel density estimation, but it estimates densities from data and > allows the specification of lower and/or upper bounds. > > Hope this helps, > > -- > Gregory (Greg) L. Snow Ph.D. > Statistical Data Center > Intermountain Healthcare > greg.snow at imail.org > 801.408.8111 > > > > -----Original Message----- > > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > > project.org] On Behalf Of Justine Rochon > > Sent: Thursday, November 05, 2009 2:38 AM > > To: r-help at r-project.org > > Subject: [R] Density estimate with bounds > > > > Dear R users, > > > > I would like to show the estimated density of a (0, 1) uniformly > > distributed random variable. The density curve, however, goes beyond 0 > > and 1 because of the kernel smoothing. > > > > Example: > > > > x = runif(10000) > > plot(density(x)) > > > > Is there a way to estimate the density curve strictly within (0, 1) and > > still use some sort of smoothing? > > > > Any help would be greatly appreciated. > > > > Best regards, > > > > Justine Rochon > > > > -- > > GRATIS f?r alle GMX-Mitglieder: Die maxdome Movie-FLAT! > > > > ______________________________________________ > > R-help at r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting- > > guide.html > > and provide commented, minimal, self-contained, reproducible code.-- Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 - sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser