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 (n=30n=30 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 (n=4n=4) may yield a significant percentage of error (e.g., 6%6\% error).

    • Increasing replication to 400400 times can reduce that error (e.g., down to 2%2\% error).

    • At 2,0002,000 replications, the error between the mean of means and the true population mean can drop to a negligible value, such as 44.

  • 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 3272.37500623272.3750062 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 (25%25\% probability). However, as the number of trials increases significantly, the proportion of heads will converge on its true probability of 50%50\%.

    • 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 50th50^{th} percentile or the second quartile.

  • Quantiles:

    • A quantile is equivalent to a percentile but expressed as a decimal.

    • Median: Equivalent to the 0.500.50 quantile.

    • R Syntax: quantile(data, probs = c(0.25, 0.75)) checks for thresholds between the 25th25^{th} and 75th75^{th} percentiles.

Lab 4 Analysis: Inferencing Populations

  • Problem Statement:

    • A sample of 3030 students (n=30n=30) is provided.

    • Goal: Determine if the sample is from a population of Undergraduates (Mean Age = 2020 years) or Graduates (Mean Age = 2525 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 2.5%2.5\% and top 97.5%97.5\%.

  • 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 2020 and a standard deviation of 33.

    • test_sample: A variable created using an if/else statement to flip a coin (comparing a random uniform distribution value to 0.50.5) to decide if the sample will be undergrads or grads.

  • Analytical Steps:

    1. Generate 100100 replicated means from the Undergraduate population.

    2. Calculate the mean(test_sample). In the lab demonstration, this returned 24.8924.89.

    3. Define the range using quantile(replicated_means, c(0.025, 0.975)).

    4. The lower end of the undergrad range was approximately 17.717.7, and the higher end was approximately 21.0721.07.

    5. Compare the mean(test_sample) (24.8924.89) to the range.

    6. Conclusion: Because 24.8924.89 is far above the undergrad threshold of 21.0721.07, 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.