############################################### ## Author: Joshua M. Tebbs ## Date: 27 July 2016 ## Update: 15 March 2024 ## STAT 110 course notes: R Code Chapter 3 ############################################### # Figure 3.1 # Page 14 # Simulate sample proportions from a SRS n = 992 # sample size B = 10000 # number of samples that we will simulate p = 0.70 # population proportion # This code generates the samples and calculates the sample proportions binomial.data = rbinom(B,n,p) sample.prop = binomial.data/n # Make histogram of 10000 sample proportions (one from each sample) hist(sample.prop,xlab="Sample Proportion",ylab="Count",main = "",col="lightblue") # Figure 3.2 # Page 15 # Simulate sample proportions from a SRS n = 9920 # sample size (10 times larger) B = 10000 # number of samples that we will simulate p = 0.70 # population proportion # This code generates the samples and calculates the sample proportions binomial.data = rbinom(B,n,p) sample.prop = binomial.data/n # Make histogram of 10000 sample proportions (one from each sample) hist(sample.prop,xlab="Sample Proportion",ylab="Count",main = "",col="lightblue")