Quiz 2 (10 minutes, 3 points): Write code to a) Simulate/generate the number of heads in an experiment where 100 fair coins are tossed 1000 times. Assign the 1000 numbers to a variable called x. Hint: this is just one line of code. b) Plot the histogram of x on a density scale. Hint: one line of code; use the default number of breaks. c) Overlay on the histogram, a plot of the binomial distribution with n=100, pi=0.5, for x values ranging from 0 to 100. Hint: use lines(). Soln: # a) x = rbinom(1000,100,0.5) # b) hist(x,freq=F) # c) lines(dbinom(0:100, 100, 0.5)) Note the agreement between the distrbution (according to dbinom()) and the histogram of the sample taken from it (rbinom(1000,100,0.5). The slight relative shift is because of the way R places the histogram bins.