[R] density ranges for uniform law
Roger Bivand
Roger.Bivand at nhh.no
Tue Apr 8 10:57:47 CEST 2003
On Tue, 8 Apr 2003, ZABALZA-MEZGHANI Isabelle wrote:
> Hello,
>
> I would have some details and explanations about the results I get.
> In fact, I start with a uniform sample between -1 and 1, and then plot its
> density.
> My problem is that the density ranges are much more longer than I expected :
>
> samp <- runif(10000,-1,1)
> plot(density(samp))
>
> Instead of varying between -1 and 1, the density varies between approximaly
> -1.5 and 1.5
> Could someone explain me what is happening ? Maybe some arguments for
> density estimation need to be set ?
>
Try:
> samp <- runif(10000,-1,1)
> range(samp)
[1] -0.9995812 0.9996801
(for this samp)
> plot(density(samp), ylim=c(0,0.6))
> abline(v=c(-1,1))
> lines(density(samp, cut=0), col="green")
> lines(density(samp, from=-1, to=1), col="red")
So you can add arguments to density() - see help(density) - but they will
not affect the fact that for the chosen bandwidth and kernel, the kernel
will extend outside the data range.
Does:
> samp1 <- runif(10000,-1.5,1.5)
> plot(density(samp1, from=-1, to=1), ylim=c(0,0.6))
> abline(v=c(-1,1))
"look" "better"?
Roger
> Waiting for an answer,
> Thanks in advance
>
> Isabelle.
>
> Isabelle Zabalza-Mezghani, PhD
> IFP - Research Reservoir Engineer
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no
More information about the R-help
mailing list