user3083324
user3083324

Reputation: 585

Convolution of densities

If x is the data and hist$density gives me the empirical densities how do I obtain the convolution of x with itself. Convolve() gives me a lot of possibilities but I am not sure what to use. I need a function for this: http://en.wikipedia.org/wiki/Convolution#Discrete_convolution (actually just the real case would suffice)

Simple test: convolution of Bernoullies gives me a Binomial

Pr=c(0.7, 0.3)

Right answer should be a Binomial of parameters n=2 p=0.3

Upvotes: 1

Views: 2081

Answers (1)

user3083324
user3083324

Reputation: 585

Ok right answer is:

> convolve(Pr,rev(Pr),type="o")
[1] 0.49 0.42 0.09

a binomial of parameters n=2 and p=0.3. So to convolute densities one could use:

convolve(his$density, rev(his$density), type="o")

This works well with discrete distributions but may work (very) badly for continuous distributions.

Note: if u want the fdr use cumsum() on the result of the convolution

Suggestion: for continuous distributions table(x)/sum(table(x)) gives a more accurate input for convolution

Upvotes: 1

Related Questions