sample_nfunction takes a random sample of observations (i.e. rows) from the dataset, you can still refer to the variables in the dataset with the same names. Code you presented earlier for visualizing and summarising the population data will still be useful for the sample, however be careful to not label your proportion
psince you’re now calculating a sample statistic, not a population parameters. You can customize the label of the statistics to indicate that it comes from the sample.
Since we are sampling proportions, we use the variable p-hat for the proportion sample, rather than p for proportion which refers to the population as a whole. The distribution of these proportions should be approximately normal for sufficient n
I believe no. This is because the 50 people in samp1 are randomly selected so the sample mean should be slightly different for each iteration. If we re-run sampl chunk to choose 50 above: 1st time p_hat was .16, 2nd time was .24.
Take a second sample, also of size 50, and call it samp2. How does the sample proportion of samp2 compare with that of samp1? Suppose we took two more samples, one of size 100 and one of size 1000. Which would you think would provide a more accurate estimate of the population proportion?
Upon running below it seems size 1000 would be more accurate, but not necessarily the case. 100 may be big enough.
How many elements are there in sample_props50? Describe the sampling distribution, and be sure to specifically note its center. Make sure to include a plot of the distribution in your answer. 4 elements (replicate, scientist_work, n, p_hat); it is approximaely normal with a center p of .1999, or rounded .20 as is the actual population mean, se = .0566.
There was 15000 samples taken, meaning there are 15000 data pts used to make this plot. This plot is mostly normally distributed. Also with a slight skew to the right.The center seems to be around .2 which is consistent with the population parameter.
To make sure you understand how sampling distributions are built, and exactly what the rep_sample_n function does, try modifying the code to create a sampling distribution of 25 sample proportions from samples of size 10, and put them in a data frame named sample_props_small. Print the output. How many observations are there in this object called sample_props_small? What does each observation represent?
There is 25 observations. Each observation counts the number of times “doesn’t benefit” appears in the sample variable for each sample
Use the app below to create sampling distributions of proportions of Doesn’t benefit from samples of size 10, 50, and 100. Use 5,000 simulations. What does each observation in the sampling distribution represent? How does the mean, standar error, and shape of the sampling distribution change as the sample size increases? How (if at all) do these values change if you increase the number of simulations? (You do not need to include plots in your answer.)
Each observation is the proportion that came out of one simulation. n=10
mean= .22 se= .11 n=50
mean= .2 se= .06 n=100
mean= .2 se= .04
Upon observing above, the mean of these gets closer to .2, the true mean as you increase the number of samples. The se decreases which means that as you increase the sample size there is less variability. The distribution begins to appear normal when you make the sample larger, since at n=10 there is a right skew.
Take a sample of size 15 from the population and calculate the proportion of people in this sample who think the work scientists do enchances their lives. Using this sample, what is your best point estimate of the population proportion of people who think the work scientists do enchances their lives?
Based on this sampling the best estimate is that 80% believe that the work of scientists is beneficial.
Since you have access to the population, simulate the sampling distribution of proportion of those who think the work scientists do enchances their lives for samples of size 15 by taking 2000 samples from the population of size 15 and computing 2000 sample proportions. Store these proportions in as sample_props15. Plot the data, then describe the shape of this sampling distribution. Based on this sampling distribution, what would you guess the true proportion of those who think the work scientists do enchances their lives to be? Finally, calculate and report the population proportion.
I believe it looks normal but skewed to the left. My guess is 75% from the histogram for proportion who said “Benefits”. Actual proportion is 80%
Change your sample size from 15 to 150, then compute the sampling distribution using the same method as above, and store these proportions in a new object called sample_props150. Describe the shape of this sampling distribution and compare it to the sampling distribution for a sample size of 15. Based on this sampling distribution, what would you guess to be the true proportion of those who think the work scientists do enchances their lives?
It appears a good estimate of around 80%
sample_props150 <- global_monitor %>% rep_sample_n(size = 150, reps = 2000, replace = TRUE) %>% count(scientist_work) %>% mutate(p_hat = n /sum(n)) %>% filter(scientist_work == "Benefits") ggplot(data = sample_props150, aes(x = p_hat)) + geom_histogram(binwidth = 0.02) + labs( x = "p_hat (Benefits)", title = "Sampling distribution of p_hat", subtitle = "Sample size = 150, Number of samples = 2000")
Of the sampling distributions from 2 and 3, which has a smaller spread? If you’re concerned with making estimates that are more often close to the true value, would you prefer a sampling distribution with a large or small spread?
The spread of the n=150 sampling distribution is smaller than the sampling distribution where n=15. a smaller spread which gives a closer approximation because the standard error will be smaller, so the proportions will be closer to the mean