In: Statistics and Probability
preform a Monte Carlo simulation in R to generate the probability distribution of the sum of two die (for example 1st die is 2 and second die is 3 the random variable is 2+3=5). The R-script should print out (display in R-studio) or have saved files for the following well labeled results:
1. Histrogram or barchart of probability distribution
2. Mean of probability distribution
3. Standard deviation of probability distribution
Answer:-
Given That:-
preform a Monte Carlo simulation in R to generate the probability distribution of the sum of two die (for example 1st die is 2 and second die is 3 the random variable is 2+3=5). The R-script should print out (display in R-studio) or have saved files for the following well labeled results:
R code with comments
All Code in text format
---
title: "the sum of two dice"
output: html_document
---
{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
Simulate the toss of 2 dice
{r}
#set the number of simulations
n<-10000
#simulate 2*n tosses
x<-sample(1:6,size=2*n,replace=TRUE,prob=rep(1/6,6))
#convert this into a matrix of 2xn
x<-matrix(x,nrow=2)
#get the column sums, represeting the sum of 2 dice
y<-colSums(x)
1. Histrogram or barchart of probability distribution?
plot the histogram of the sums
{r}
hist(y,main=" the probability distribution of the sum of two
dice",freq=FALSE,breaks=12)
2. Mean of probability distribution?
Mean of the distribution
{r}
sprintf('Mean of probability distribution is %.4f',mean(y) )
3. Standard deviation of probability distribution?
Standard deviation of probability distribution
```{r}
sprintf('Standard deviation of probability distribution is
%.4f',sd(y) )