This page was last updated on October 04, 2019.
sample
function as above, sample 20 individuals at random from this populationSOLUTION
Set the population parameters.
The population comprises 52% males and 48% females.
Generate the population
Set the random value seed to 133 and build the population.
set.seed(133)
sex.pop <- sample(sexes, size = pop.size,
prob = sex.props, replace = TRUE)
sex.pop.prop <- xtabs(~ sex.pop) / pop.size
sex.pop.prop
## sex.pop
## female male
## 0.48111 0.51889
Sample the population
Use the sample()
to randomly draw 20 individuals from the population generated above (sex.pop.prop
).
calculate the sample-based estimate of the proportion of males “successes” (male, in this case) to get the sample
## [1] 0.5
The sample-based estimate of the proportion of males in this population is 0.5.
Calculate the Agresti-Coull 95% confidence interval of the proportion of males in the population.
library(binom)
ac.male.conf <- binom.confint(x = n.male,
n = sex.samp.size,
conf.level = 0.95,
methods = "ac")
ac.male.conf
## method x n mean lower upper
## 1 agresti-coull 10 20 0.5 0.299298 0.700702
Our 95% confidence interval is 0.299 \(\leq\) p \(\leq\) 0.701. This interval does include the known proportion of males of 0.519