![]() |
VOOZH | about |
To calculate the expected value in R, we use the formula for the expected value of a probability distribution. This value represents the average or mean of all possible outcomes, weighted by their probabilities.
Given:
X: 0.2, 0.3, 0.4, 0.5, 0.6
P(x): .1, .3, .5, .1, .2
sum() method is used to calculate the sum of given vector
Syntax:
sum(x)
Parameters:
Example: Calculate expected value
Output:
0.48
It is used to get the weighted arithmetic mean of input vector values.
Syntax:
weighted.mean(x, weights)
Parameters:
Example: Calculate expected value
Output:
0.4
It is used to combine the arguments passed to it. And %% operator is used to multiply a matrix with its transpose.
Syntax:
c(…)
Parameters:
Example: Calculate expected value
Output:
0.48
Matrix multiplication returns the expected value 0.48.