Statistical Sampling, Theoretical Laws, and Population Inference Lab
The Importance and Logic of Sampling
Definition and Necessity of Sampling:
Sampling is the process of selecting a subset of individuals from a population to estimate characteristics of the whole.
Testing an entire population (census) is often impossible due to size, cost, and logistics.
A high-quality sample must be representative of the population to avoid bias.
The Risk of Bias:
If a sample is not representative, result accuracy is compromised.
Named Example: Product reviews. People typically write reviews when they are dissatisfied. If you only look at these reviews, the sample reflects only upset individuals rather than the general user base.
Critical Considerations for Obtaining Data:
Population: Defining the full group being studied.
Sample Size: Ensuring the number of subjects is sufficient ( in the lab example).
Frequency: How many times the sampling process is conducted.
Representation: Does the sample accurately reflect population characteristics?
Sampling Types:
Random Sampling: Every member has an equal chance of selection (the primary focus for this course).
Stratified Sampling.
Systematic Sampling.
Cluster Sampling.
Replication and Accuracy in Statistics
Concept of Replication:
Replication involves performing the sampling process multiple times to understand the limitations of a single sample and the behavior of the data over time.
It helps account for the inherent risk and randomness associated with the sampling process.
Hypothetical Scenario: Drawing red and brown balls from a jar. If you sample multiple times, you gain a better understanding of the true distribution of colors in the jar.
Numerical Impact of Replication:
Sampling a mean four times () may yield a significant percentage of error (e.g., error).
Increasing replication to times can reduce that error (e.g., down to error).
At replications, the error between the mean of means and the true population mean can drop to a negligible value, such as .
R Programming Commands for Replication:
replicate(): Used to run a function multiple times and store the results in a list.simplify = TRUE: A parameter that ensures the output makes decimal sense by rounding to the closest logical decimal rather than displaying excessively long floating-point numbers (e.g., turning into a cleaner figure).mean(replicated_means): Used to calculate the "Mean of Means."
Core Statistical Laws: LLN and CLT
The Law of Large Numbers (LLN):
Definition: If you run a statistical process (like sampling) a large number of times, the results will generally converge on a specific result.
Coin Toss Example: Tossing a fair coin four times might yield only one head ( probability). However, as the number of trials increases significantly, the proportion of heads will converge on its true probability of .
Key Outcome: The LLN provides accuracy.
The Central Limit Theorem (CLT):
Definition: If you take a large enough number of random samples from any population, the distribution of the averages (means) of those samples will form a normal curve (bell-shaped), regardless of whether the original population was normally distributed.
Apple Weight Example: Individual apple weights at different stores might vary significantly and not be normally distributed. However, if you take the average weight from many groups of apples, those average weights will resemble a normal curve.
Key Outcome: The CLT provides the distribution shape (the bell curve).
Position Metrics: Percentiles and Quantiles
Percentiles and Quartiles:
These terms identify a specific position within a collection of values.
The Median represents the percentile or the second quartile.
Quantiles:
A quantile is equivalent to a percentile but expressed as a decimal.
Median: Equivalent to the quantile.
R Syntax:
quantile(data, probs = c(0.25, 0.75))checks for thresholds between the and percentiles.
Lab 4 Analysis: Inferencing Populations
Problem Statement:
A sample of students () is provided.
Goal: Determine if the sample is from a population of Undergraduates (Mean Age = years) or Graduates (Mean Age = years).
Judgment Thresholds:
A sample statistic is judged as "extreme" or "not extreme" based on its position in the population distribution.
Common thresholds are set at the bottom and top .
Code Implementation Details:
set.seed(2): Used to ensure all students generate the same "random" output for consistency in results.rnorm(20000, mean = 20, sd = 3): Random sampling from a normal distribution with a mean of and a standard deviation of .test_sample: A variable created using anif/elsestatement to flip a coin (comparing a random uniform distribution value to ) to decide if the sample will be undergrads or grads.
Analytical Steps:
Generate replicated means from the Undergraduate population.
Calculate the
mean(test_sample). In the lab demonstration, this returned .Define the
rangeusingquantile(replicated_means, c(0.025, 0.975)).The lower end of the undergrad range was approximately , and the higher end was approximately .
Compare the
mean(test_sample)() to the range.Conclusion: Because is far above the undergrad threshold of , the sample mean is considered "extreme" for undergraduates and is identified as belonging to graduate students.
Questions & Discussion
Question: Why is sampling from a population an important process?
Response: You cannot possibly test an entire population. You need good, representative samples to make accurate inferences.
Question: How do I type the two vertical lines (pipe operator logic) in R on a Windows keyboard?
Response: The key is located right under the Backspace key, sharing the key with the backslash (
\).Question: When knitting the file, do we go to HTML first?
Response: Yes, knit to HTML first, open it in a browser, and then use the print function to save it as a PDF for submission.