[R] Convolve 2 uniform distributed variables

Prof. Dr. Matthias Kohl Matthias.Kohl at stamats.de
Thu May 24 09:22:23 CEST 2012


take a look at the distr package

library(distr)
U <- Unif()
U2 <- U + U
# or
U2 <- convpow(U, 2)
plot(U2)
# or
curve(d(U2)(x), from = 0, to = 2)


Best
Matthias

On 24.05.2012 08:29, corn at mail.tu-berlin.de wrote:
> Hi,
> I want to convolve 2 uniform distributed [0,1] variables, so that I get
> this graphic:
> http://de.wikipedia.org/wiki/Benutzer:Alfred_Heiligenbrunner/Liste_von_Verteilungsdichten_der_Summe_gleichverteilter_Zufallsvariabler
> (second graphic)
>
> if I do
>
> u1<-seq(0,1,length=100)
> fu1=dunif(u1,min=0,max=1)
>
> plot(u1,fu1,type="l",xlim=c(-2,2))
>
>
> u2<-seq(0,1,length=100)
> fu2=dunif(u2,min=0,max=1)
>
> u1u2<-convolve(u1,rev(u1),typ="o")
>
> plot(u1u2)
>
> it does not work, could you help me please? The point is the convolve
> function I think, what do I have to type, to get the correct convolution
> of two uniform distributed [0,1] variables as to be seen in the second
> graphic in the given link?
>
> Thanks a lot
>
> ______________________________________________
> 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.

-- 
Prof. Dr. Matthias Kohl
www.stamats.de



More information about the R-help mailing list