r - Multiply Probability Distribution Functions -


i'm having hard time building efficient procedure adds , multiplies probability density functions predict distribution of time take complete 2 process steps.

let "a" represent probability distribution function of how long takes complete process "a". 0 days = 10%, 1 day = 40%, 2 days = 50%. let "b" represent probability distribution function of how long takes complete process "b". 0 days = 10%, 1 day = 20%, etc.

process "b" can't started until process "a" complete, "b" dependent upon "a".

a <- c(.1, .4, .5) b <- c(.1,.2,.3,.3,.1) 

how can calculate probability density function of time complete "a" , "b"?

this i'd expect output or following example:

totallength <- 0 # initialize totallength[1:(length(a) + length(b))] <- 0 # initialize totallength[1] <- a[1]*b[1] totallength[2] <- a[1]*b[2] + a[2]*b[1] totallength[3] <- a[1]*b[3] + a[2]*b[2] + a[3]*b[1] totallength[4] <- a[1]*b[4] + a[2]*b[3] + a[3]*b[2] totallength[5] <- a[1]*b[5] + a[2]*b[4] + a[3]*b[3] totallength[6] <- a[2]*b[5] + a[3]*b[4] totallength[7] <- a[3]*b[5]  print(totallength) [1] [1] 0.01 0.06 0.16 0.25 0.28 0.19 0.05 sum(totallength) [1] 1 

i have approach in visual basic used 3 loops (one each of steps, , 1 output) hope don't have loop in r.

since seems pretty standard process flow question, part 2 of question whether libraries exist model operations flow i'm not creating scratch.

the efficient way sort of operation use convolution:

convolve(a, rev(b), type="open") # [1] 0.01 0.06 0.16 0.25 0.28 0.19 0.05 

this efficient both because it's less typing computing each value individually , because it's implemented in efficient way (using fast fourier transform, or fft).

you can confirm each of these values correct using formulas posted:

(expected <- c(a[1]*b[1], a[1]*b[2] + a[2]*b[1], a[1]*b[3] + a[2]*b[2] + a[3]*b[1], a[1]*b[4] + a[2]*b[3] + a[3]*b[2], a[1]*b[5] + a[2]*b[4] + a[3]*b[3], a[2]*b[5] + a[3]*b[4], a[3]*b[5])) # [1] 0.01 0.06 0.16 0.25 0.28 0.19 0.05 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -