How can I use R to enter a data set, along with the probability for each data point, and find the expected values for each?
Lets consider the random variable X taking value x=0,1,2,3,4,5 with respective probabilities p=0.1,0.2,0.3,0.1,0.2,0.1
### By using r command we enter the data set as follows.
> x=c(0,1,2,3,4,5)#####command to read value of random
variable
> x
[1] 0 1 2 3 4 5
> p=c(0.1,0.2,0.3,0.1,0.2,0.1)#####command to read
probabilities
> p
[1] 0.1 0.2 0.3 0.1 0.2 0.1
> cbind(x,p)#####command to make probability distribution
table
x p
[1,] 0 0.1
[2,] 1 0.2
[3,] 2 0.3
[4,] 3 0.1
[5,] 4 0.2
[6,] 5 0.1
> sum(x*p)####command to obtain expected value
[1] 2.4
Since we know that the expected value of a random variable X
is:
Get Answers For Free
Most questions answered within 1 hours.