Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 01 Fair dice Similar to the Exercise in Lab01. We want to set up rolling

ID: 3042174 • Letter: P

Question

Problem 01 Fair dice Similar to the Exercise in Lab01. We want to set up rolling die random variable and related event here. The program should be able to calculate the probability that a given sequence of die rolls appears. You may follow the process below to code. But it is totally up to you to compose your own work. Just make sure it can run and give the required results. Ingredients: 1. sample space: 2. random variable X : R 3. probability function assuming fair die set up functions 1. A sample space of rolling a 6-sided die labelled 1,2,3,4,5,6 2. A random variable X on the sample space 3. A probability mass function pm f f), assuming the die is fair 4. A function that calculate probability of any given string to appear. round the result to 5 decimal place. Like in the coin case, probability that HTH shows up. Your code should be able to do the following: note that: You don't have to use the comments I wrote below, but you should write your own comments so that our grader can follow your ideas For each roll in rolls ['1',133345', 123456','12,'17] Note: roll '12 means you roll a die 2 times, '1 shows up first, then '2" shows up. You want to calculate the probability this occurs

Explanation / Answer

The is made in R, and is given as follows

### Solution Code R ###
>
> # sample space
>
> rolls = c('1', '133345', '123456', '12', '17')

> # Create a function to seperate integers from string and then get n for calculating probability as (1/6)^n


> pmf = function(event){
+ n = length(as.numeric(strsplit(event, "")[[1]]))
+ pmf = (1/6)^n
+ return(pmf)
+ }
>
> probability = c()
> result = c()
>
> for(i in 1:length(rolls)){
+ probability[i] = pmf(rolls[i])
+ result[i] = sprintf("roll = %s, Probability = %s ", rolls[i], probability[i])
+ }
> result
[1] "roll = 1, Probability = 0.166666666666667 "   
[2] "roll = 133345, Probability = 2.14334705075446e-05 "
[3] "roll = 123456, Probability = 2.14334705075446e-05 "
[4] "roll = 12, Probability = 0.0277777777777778 "   
[5] "roll = 17, Probability = 0.0277777777777778 "   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote