# Expected values: why are they so cool !?

In this tutorial, we are going to revisit the notion of expected value and understand in-depth what they truly mean from a statistical perspective. If you are ready, let's dive in!

First we need to upload the tidyverse package with library. In this package, we are going to make use of the `ggplot2` packages. You don't have to upload the ggplot2 package because it will be automatically uploaded with the tidyverse. So, at the prompt of your computer write the following:

library(tidyverse)

game<-data.frame(gain=c(0,1,2,3,6),
prob=c(0.34,0.3,0.19,0.15,0.02))
game

(expected_v<-sum(apply(game,1,prod)))

fonc_gain<-function(){
gain<-c(0,1,2,3,6)
gain_obt<-sample(x=gain, size = 1, prob = c(0.34,0.3,0.19,0.15,0.02))
sum(gain_obt)
}
fonc_gain()

nexp<-replicate(30, fonc_gain())
mean(nexp)

Exp_V<-NULL
s<-seq(300,30000,150)
for(n in s){
nexp<-replicate(n, fonc_gain())
Exp_V[which(s==n)]<-mean(nexp)
}

x<-seq(300,30000,by=150)
y<-Exp_V
qplot(x,y,geom = c("point","line"))+
geom_hline(yintercept=1.25,col="red")+
labs(x="Number of trials", y="Expected Values")