vivek - 3 months ago 15

R Question

I have got

`n>2`

`Random Variables(RV)`

`4 Uniform RVs`

`Upper and lowers`

`W~U[-1,5], X~U[0,1], Y~[0,2], Z~[0.5,2]`

I am trying to find out the approximate PDF for the sum of these RVs i.e. for

`T=W+X+Y+Z`

`1 million points`

`1 million samples for T`

`P(t<T)`

`P(0.5<T)`

Thanks

Answer

Consider the `ecdf`

function:

```
set.seed(123)
W <- runif(1e6, -1, 5)
X <- runif(1e6, 0, 1)
Y <- runif(1e6, 0, 2)
Z <- runif(1e6, 0.5, 2)
T <- Reduce(`+`, list(W, X, Y, Z))
cdfT <- ecdf(T)
1 - cdfT(0.5) # Pr(T > 0.5)
# [1] 0.997589
```

See How to calculate cumulative distribution in R? for more details.

Source (Stackoverflow)

Comments