Reputation: 5
Given a fair four-sided die and let X denote the associated random variable. What is the probability distribution of X? What is the expectation of X?
sample
-function to roll the four-sided die 20 times.prob
-argument to roll the unfair dice 20 times and provide summary statistics.#1
x <- 1:4
sample_function <- sample (1:4, size=20,replace = TRUE, prob = NULL)
sample_function <- sum(sample (1:4, size=20,replace = TRUE, prob = NULL))
#2
my.sample <- function(die1=1:4, prob1=NULL,Nsample=20) {
die <- sample(die1, prob=prob1, replace = TRUE, size = Nsample)
return(die)
}
my.sample()
my.sample(die1 = 1:4, prob1 = c(1/2 , 1/6,1/6, 1/6), Nsample = 20)
I do not understand how can I calculate the probability distribution of x
and how can I use prob function for unfair dice.
Upvotes: 0
Views: 1130
Reputation: 101848
As Roland mentioned, your Nsample
should be sufficient large (otherwise the Monte Carlo simulation result would be rather biased). If you wants the empirical probability distribution, you can use prop.table
+ table
like below
s <- prop.table(table(my.sample(die1 = 1:4, prob1 = c(1/2, 1/6,1/6, 1/6), Nsample = 1e8)))
which gives
> s
1 2 3 4
0.4999951 0.1666763 0.1666949 0.1666338
Upvotes: 0