[R] density estimation: compute sum(value * probability) for given distribution
bogdan romocea
br44114 at yahoo.com
Sat Nov 13 15:45:00 CET 2004
Andy,
Thanks a lot for the clarifications. I was running a simulation a
number of times and trying to come up with a number to summarize the
results. And, I failed to realize from the beginning that what I was
trying to compute was just the mean.....
Regards,
b.
--- "Liaw, Andy" <andy_liaw at merck.com> wrote:
> First thing you probably should realize is that density is _not_
> probability. A probability density function _integrates_ to one,
> not _sum_
> to one. If X is an absolutely continuous RV with density f, then
> Pr(X=x)=0
> for all x, and Pr(a < X < b) = \int_a^b f(x) dx.
>
> sum x*Pr(X=x) (over all possible values of x) for a discrete
> distribution is
> just the expectation, or mean, of the distribution. The
> expectation for a
> continuous distribution is \int x f(x) dx, where the integral is
> over the
> support of f. This is all elementary math stat that you can find
> in any
> textbook.
>
> Could you tell us exactly what you are trying to compute, or why
> you're
> computing it?
>
> HTH,
> Andy
>
> > From: bogdan romocea
> >
> > Dear R users,
> >
> > This is a KDE beginner's question.
> > I have this distribution:
> > > length(cap)
> > [1] 200
> > > summary(cap)
> > Min. 1st Qu. Median Mean 3rd Qu. Max.
> > 459.9 802.3 991.6 1066.0 1242.0 2382.0
> > I need to compute the sum of the values times their probability
> of
> > occurence.
> >
> > The graph is fine,
> > den <- density(cap, from=min(cap),
> > to=max(cap), give.Rkern=F)
> > plot(den)
> >
> > However, how do I compute sum(values*probabilities)? The
> > probabilities produced by the density function sum to only 26%:
> > > sum(den$y)
> > [1] 0.2611142
> >
> > Would it perhaps be ok to simply do
> > > sum(den$x*den$y) * (1/sum(den$y))
> > [1] 1073.22
> > ?
> >
> > Thank you,
> > b.
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
> >
> >
>
>
>
------------------------------------------------------------------------------
> Notice: This e-mail message, together with any attachments,
> contains information of Merck & Co., Inc. (One Merck Drive,
> Whitehouse Station, New Jersey, USA 08889), and/or its affiliates
> (which may be known outside the United States as Merck Frosst,
> Merck Sharp & Dohme or MSD and in Japan, as Banyu) that may be
> confidential, proprietary copyrighted and/or legally privileged. It
> is intended solely for the use of the individual or entity named on
> this message. If you are not the intended recipient, and have
> received this message in error, please notify us immediately by
> reply e-mail and then delete it from your system.
>
------------------------------------------------------------------------------
>
More information about the R-help
mailing list