Question

Write an R script to simulate tossing a coin. Plot the evolution of the relative frequency...

Write an R script to simulate tossing a coin. Plot the evolution of the relative frequency of heads in a sequence of 100 coin tosses?

please use R script

Homework Answers

Answer #1

Solution: The R script to simulate tossing a coin is given here:
We can write a function to flip a coin n times as:

> FlipCoin = function(n) sample(0:1,n,rep=T)
> e1=FlipCoin(100)
> e1
[1] 1 1 1 1 1 0 1 0 1 0 1 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 0 1 0 0 1 0 0 0 1 1
[38] 1 1 1 0 0 1 1 1 1 0 1 0 0 1 0 1 1 1 0 0 0 0 1 1 1 0 1 1 0 0 1 1 0 1 1 1 0
[75] 0 0 1 1 0 1 1 0 0 1 1 1 1 1 0 0 1 0 1 1 1 0 1 1 1 0
> hist(e1,breaks=c(-0.5,0.5,1.5), prob=T)

The evolution of the relative frequency of heads in a sequence of 100 coin tosses is given here


Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Language: Python Write a program to simulate an experiment of tossing a fair coin 16 times...
Language: Python Write a program to simulate an experiment of tossing a fair coin 16 times and counting the number of heads. Repeat this experiment 10**5 times to obtain the number of heads for every 16 tosses; save the number of heads in a vector of size 10**5 (call it headCounts). You should be able to do this in 1-3 lines of numpy code. (Use np.random.uniform1 to generate a 2d array of 10**5 x 16 random numbers between 0 and...
Using R, simulate tossing 4 coins as above, and compute the random variable X(the outcome of...
Using R, simulate tossing 4 coins as above, and compute the random variable X(the outcome of tossing a fair coin 4 times & X = num of heads - num of tails.). Estimate the probability mass function you computed by simulating 1000 times and averaging.
You have a coin that you suspect is not fair (i.e., the probability of tossing a...
You have a coin that you suspect is not fair (i.e., the probability of tossing a head (PH) is not equal to the probability of tossing a tail (PT) or stated in another way: PH ≠ 0.5). To test yoursuspicion, you record the results of 25 tosses of the coin. The 25 tosses result in 17 heads and 8 tails. a) Use the results of the 25 tosses in SPSS to construct a 98% confidence interval around the probability of...
Amanda, Becky, and Charise toss a coin in sequence until one person “wins” by tossing the...
Amanda, Becky, and Charise toss a coin in sequence until one person “wins” by tossing the first head. a) If the coin is fair, find the probability that Amanda wins. b) If the coin is fair, find the probability that Becky wins. c) If the coin is not necessarily fair, but has a probability p of coming up heads, find an expression involving p for the probability that Becky wins. d) As in part c) find similar expressions for Amanda...
Using R or R-studio. 3. A fair coin is tossed until the first head occurs. Do...
Using R or R-studio. 3. A fair coin is tossed until the first head occurs. Do this experiment T = 10; 100; 1,000; 10,000 times in R, and plot the relative frequencies of this occurring at the ith toss, for suitable values of i. Compare this plot to the pmf that should govern such an experiment. Show that they converge as T increases. What is the expected number of tosses required? For each value of T, what is the sample...
A coin is flipped 10,000 times and it is found that the relative frequency of heads...
A coin is flipped 10,000 times and it is found that the relative frequency of heads is 0.51. How sure can you be that the coin is biased? Φ(1) − Φ(−1) = 0.68, Φ(2) − Φ(−2) = 0.95, Φ(3) − Φ(−3) = 0.997
In need of assistance. Please show your work -----> Given: Chance Experiment involving tossing a biased...
In need of assistance. Please show your work -----> Given: Chance Experiment involving tossing a biased coin. Probability of heads: p = .20 A) The coin is tossed 12 times. Let z = the # of heads tossed. i) What type of distribution would you use to find probabilities in this case? What is the general distribution function, p(z), you would use to find probabilities? ii) Find the probability of tossing exactly 5 heads iii) Probability of tossing at least...
in R language (d) Write a computer program to simulate a fair dice. Generate output. Use...
in R language (d) Write a computer program to simulate a fair dice. Generate output. Use the output to make a plot.
Write Matlab script to plot the spectrum (-? to ? radians) of DTMF signal for keys...
Write Matlab script to plot the spectrum (-? to ? radians) of DTMF signal for keys 1, A and B. Choose an appropriate sampling frequency. The DTMF frequencies are indicated in table 1.     Critically analyze the design specification.                                           Row/column 1209HZ 1336Hz 1477HZ 1633HZ 697 1 2 3 A 770 4 5 6 B 852 7 8 9 C 941 * 0 # D     Write Matlab script to plot the spectrum (-? to ? radians) of DTMF signal for...
(a)Assuming that we toss a in-balanced coin for 100 times, and we get 40 heads from...
(a)Assuming that we toss a in-balanced coin for 100 times, and we get 40 heads from our experiment. Assuming that the relative frequency is just the true probability for tossing to get a head. Then we want to know: Probability for getting a head:   Expected variance if tossing 70 times:   (b)Given a poisson distribution with expectation 4, so the standard deviation of this distribution should be
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT