C3_W2_Assignment Exercise 10

I just finished assignment for W2, the exercise 10 seems weird to me. I feel like there’s no correct answer. I selected the 4th statement, and I received the grade, but I don’t understand why the 4th statement is true.
I tried programming and no answer is correct. Can anyone help me?

Exercise 10:

Given a 6-sided loaded dice. You throw it twice and record the sum. Which of the following statemets is true?

  • the mean and variance is the same regardless of which side is loaded
  • having the sides 3 or 4 loaded will yield a higher covariance than any other sides
  • the mean will decrease as the value of the loaded side increases
  • changing the loaded side from 1 to 6 will yield a higher mean but the same variance

@lil_xiang presuming you are asking exclusively about the fourth statement, consider the physical side of the die that is weighted is completely independent from whatever number is on it.

I mean, really, you don’t even have to change the load of the die at all-- Just reconfigure what numbers are written on it.

Putting a 6 on the loaded side, your mean will be higher because it will now tend more favorably to this higher number (as one reads the values)–

Now, imagine that same die with no numbers on it at all-- Is the ‘way it falls’, the distribution, or the variance, ever going to change ?

No-- You could put any order of numbers there, but as the die falls it will always vary in the same way.

2 Likes

Thank you for your reply!
I wrote code to verify the 4th statement, below is my simple code:

def load_dice(n_sides, loaded_number):
    
    # All probabilities are initially the same
    probs = np.array([1/(n_sides+1) for _ in range(n_sides)])
    
    # Assign the loaded side a probability that is twice as the other ones
    probs[loaded_number-1] = 1 - sum(probs[:-1])
    
    # Check that all probabilities sum up to 1
    if not np.isclose(sum(probs), 1):
        print("All probabilities should add up to 1")
        return
    
    return probs 


n_sides = 6
for loaded_number in range(1,7):
    print(f"the loaded_number is: {loaded_number}")
    prob = load_dice(n_sides, loaded_number)
    # key: the sum result of two dice
    # value: the probability to the corresponding sum
    s_p_map = {num: 0 for num in range(2,13)}
    for i in range(6):
        for j in range(6):
            s = i + j + 2
            prob_s = prob[i] * prob[j]
            s_p_map[s] = s_p_map[s] + prob_s
    expectation = 0
    exp_square = 0
    
    for s,p in s_p_map.items():
        
        expectation += s * p
        exp_square += (s**2) * p

    print(f"expectation: {expectation}")
    # calculate the variance based on: var(X) = E(X^2) - (E(X))^2
    var_calculated = exp_square - expectation**2
    print(f"calculated variance: {var_calculated}")
    var = 0
    for s,p in s_p_map.items():
        var += ((s - expectation)**2) * p
    print(f"naive  variance: {var}")

the loaded side will have probability 2/7, and other sides will have probability 1/7, and this is the output:

the loaded_number is: 1
expectation: 6.2857142857142865
c variance: 6.530612244897952
  variance: 6.530612244897961
the loaded_number is: 2
expectation: 6.571428571428573
c variance: 5.551020408163247
  variance: 5.551020408163266
the loaded_number is: 3
expectation: 6.8571428571428585
c variance: 5.0612244897959116
  variance: 5.0612244897959195
the loaded_number is: 4
expectation: 7.142857142857146
c variance: 5.061224489795883
  variance: 5.061224489795919
the loaded_number is: 5
expectation: 7.42857142857143
c variance: 5.551020408163254
  variance: 5.551020408163266
the loaded_number is: 6
expectation: 7.714285714285717
c variance: 6.530612244897938
  variance: 6.53061224489796

it shows that 1 and 6 have same variance, 2 and 5, 3 and 4
basically I calculated the variance in two different ways:

Variance(X) = E(X^2) - (E(X))^2
Variance(X) = sum of [((X - E(X))^2) * prob]

this output really conflicts with all statements…

1 Like

But your results are consistent with what are described in option 4. Maybe you want to go through it again?

Cheers,
Raymond

1 Like

ahhhh, i see, it’s comparing variances of 1 and 6, I was comparing the variances from 1 through 6, thanks! :grinning:

1 Like

I would just add, though IMHO I feel it is a bit of an ‘overkill’ to write a program to solve, what is in this case probably done much more easily theoretically on pen and paper… You might be really interested though in learning/designing Monte Carlo methods in Python;