bogdan romocea wrote:
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)?

I don't get the point. You are estimating using a gaussian kernel. Hint: What's the probability to get x=0 for a N(0,1) distribution? So sum(values*probabilities) is zero!

> The
probabilities produced by the density function sum to only 26%:

and could also sum to, e.g., 783453.9, depending on the number of observations and the estimated parameters of the desnity ...


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 ?

No. den$x is a point where the density function is equal to den$y, but den$y is not the probability to get den$x (you know, the stuff with intervals)! I fear you are mixing theory from discrete with continuous distributions.


Uwe Ligges



Thank you,
b.

______________________________________________
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

______________________________________________ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to