Consider flipping nn times a coin. The probability for heads is given by pp where pp...

50.1K

Verified Solution

Question

Basic Math

Consider flipping nn times a coin. The probability for heads isgiven by pp where pp is some parameter which can be chosen from theinterval (0,1)(0,1).

Write a Python code to simulate nn coin flips with headsprobability pp and compute the running proportion of heads X¯nX¯nfor nn running from 1 to 1,000 trials. Plot your results. Your plotshould illustrate how the proportion of heads appears to convergeto pp as nn approaches 1,000.

In [ ]:

### Insert your code here for simulating the coin flips and for computing the average
?
?

In [2]:

### Complete the plot commands accordingly for also plotting the computed running averages in the graph below
?
p = 0.25 # just an example
?
plt.figure(figsize=(10,5))
plt.title("Proportion of heads in 1,000 coin flips")
plt.plot(np.arange(1000),p*np.ones(1000),'-',color="red",label="true probability") 
plt.xlabel("Number of coin flips")
plt.ylabel("Running average")
plt.legend(loc="upper right")

Answer & Explanation Solved by verified expert
4.5 Ratings (992 Votes)
The R code for simulating the coin toss is given below    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students