library("ggplot2")
  1. Write a program to carry out the following experiment. A coin is tossed 100 times and the number of heads that turn up is recorded. This experiment is then repeated 1000 times. Have your program plot a bar graph for the proportion of the 1000 experiments in which the number of heads is n, for each n in the interval [35, 65]. Does the bar graph look as though it can be fit with a normal curve?

Simulation

coin <- c("heads", "tails")
heads <- rep(0, 1000)
for(i in 1:1000){
  trials <- sample(coin, size = 100, replace = TRUE)
  heads[i] <- length( which(trials == "heads" ) )
}

Plot

x = rep(0, 31)
y = rep(0, 31)

for(i in 35:65){
  x[i - 34] = i
  y[i - 34] = length( which(heads == i ) )
}

results <- data.frame(n = x, heads = y)

ggplot(data=results, aes(x=n, y=heads)) +
  geom_bar(stat="identity", fill="steelblue") +
  labs( title="1000 Simulations of 100 Coin Tosses", x= " of Heads", y = "Frequency") +
  theme_minimal()

The graph isn’t highly skewed and it is near symmetrical. I would say that a normal curve may be fitted to this graph.