[R] Density estimate with bounds

Gavin Simpson gavin.simpson at ucl.ac.uk
Thu Nov 5 10:44:36 CET 2009


On Thu, 2009-11-05 at 10:37 +0100, 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?

Read ?density and in particular the arguments 'from' and 'to':

 from,to: the left and right-most points of the grid at which the
          density is to be estimated; the defaults are 'cut * bw'
          outside of 'range(x)'.


HTH

G

> 
> Any help would be greatly appreciated.
> 
> Best regards,
> 
> Justine Rochon
> 
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%




More information about the R-help mailing list