Description Usage Arguments Value Examples
View source: R/Expected Value.R
This function is an implementation of computing expected value for ramdon variables given function f.
1 | Expected(f, rv)
|
f |
the function that we would need to compute its expected value |
rv |
the random variabel would be given |
the expected value of the given function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | f<- function(x) {ifelse(-1< x & x < 0, 3*x^2, 0)}
w=oneDSample1(f,50000,-1,0)
Expected(f,w)
f<- function(x) {1/pi/(1+x^2)}
w=oneDSample1(f,50000)
Expected(f,w)
jointPFF <- function(x){
x1 = x[1]
x2 = x[2]
ifelse(0<x1 & x1<1 & 0<x2 & x2<1 , 24*x1*x2, 0)}
w = twoDsample(f = jointPFF, N=10000,0,1,0,1)
g=function(x,y){x*y}
Expected(g,w)
f <- function(x){
x1 = x[1]
x2 = x[2]
ifelse(x2>0, 1/pi/(1+x1^2) * 0.05*exp(-0.05*x2), 0)}
w=twoDsample(f = f, N=10000)
g=function(x,y){x+y}
Expected(g,w)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.