[R] density at particular values
William Dunlap
wdunlap at tibco.com
Sun Nov 21 20:11:20 CET 2010
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of Shant Ch
> Sent: Saturday, November 20, 2010 6:34 PM
> To: David Winsemius
> Cc: r-help at r-project.org
> Subject: Re: [R] density at particular values
>
> David, I did look at ?density many times. I think I didn't
> explain what I have
> to find.
>
> Suppose I have a data.
> x<- c(rnorm(40,5,3),rcauchy(30,0,4),rexp(30,6))
>
> Suppose I don't have information about the mixture, I have
> been given only the
> data.
>
> density(x) will give the 6 number summary of the data, given
> as x and also the 6
> number summary of the density of density given as y.
print(density(x)) displays a 6-number summary of the
x and y outputs of density, which are only tangentially
related to the data. (The default x output is a evenly
spaced seqence of n=512 values covering the range of
the input x.) I don't know why this display was chosen.
> I want to find the density of the given data at x=1. I
> basically want the value
> of y(=density) for x=1 i.e. kernel density at x=1.
If you really just want the density at a single
point, x0 (=1 in your case), you can do
d0 <- density(x, from=x0, to=x0, n=1)$y
(density only lets you choose the output x vector
as an evenly spaced sequence parameterized by
from, to, and n.)
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
>
> Shant
>
>
>
>
>
>
>
>
>
>
>
>
>
> ________________________________
> From: David Winsemius <dwinsemius at comcast.net>
>
> Cc: r-help at r-project.org
> Sent: Sat, November 20, 2010 8:54:32 PM
> Subject: Re: [R] density at particular values
>
>
> On Nov 20, 2010, at 8:07 PM, Shant Ch wrote:
>
> > Hello everyone!
> >
> > I want to use density function of R to compute the density
> at x(=0, say). But
> >it
> > is giving me the 5-number summary and mean of the data and
> densities at that
> > point.
> > I just want the densities at different values specified by
> me. Can anyone let
> >me
> > know how can I find that?
>
> Here's what you should have done (even before posting):
>
> ?density
> <Read the help page to see the structure of what density() returns.>
> "Value
> x the n coordinates of the points where the density is estimated.
>
> y the estimated density values. These will be non-negative,
> but can be zero."
>
> Realize that the "specified by me" part is either going to be
> modified to "pick
> an existing estimate near my specification" or that you will
> need to approximate
> the value. So what is the actual problem (and the actual data setup) ?
>
> --David.
>
>
> >
> > For example
> >
> >
> > Thanks in advance for your help.
> >
> >
> > Shant
> >
> >
> >
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > 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.
>
> David Winsemius, MD
> West Hartford, CT
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list