in R language
(d) Write a computer program to simulate a fair dice. Generate output. Use the output to make a plot.
Solution :
We know that outcomes of fair dice are equally likely.
Let X be sample space.
X= (1:6)
Hence we use simple random sampling from X to simulate a fair dice.
R code :
X= c(1:6)
#take random sample of size 100 from X.
die= sample(X, size = 100, replace = TRUE)
die
# We plot Histogram using output
hist(die)
Output :
[1] 6 2 4 3 4 1 5 3 4 2 6 5 5 5 5 3 6 2 5 6 3 6 6 5 2 3 2 2 3 2 5 4 2 6 5 4 2
[38] 6 3 2 1 1 3 1 1 2 3 5 2 4 3 6 2 1 2 6 5 5 3 4 3 5 4 6 2 5 4 4 1 6 5 5 5 4
[75] 3 3 4 3 4 1 3 3 6 5 6 2 6 5 4 1 1 1 3 4 1 2 4 1 2 5
Plot :
Get Answers For Free
Most questions answered within 1 hours.