The goal of this study is to compare Probability Sampling (Simple Random Sampling - SRS) and Non-Probability Sampling (Convenience Sampling) in handling Margin of Error (MoE) when estimating the average monthly food expenses of university students.
A university wants to conduct a survey to estimate the average monthly food expenses of its students. However, researchers must ensure their estimates are accurate and generalizable, with a reasonable margin of error (MoE).
We will conduct a simulation using Simple Random Sampling (SRS) and Convenience Sampling, and compare their effects on MoE.
# Load necessary libraries
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.2
# Set seed for reproducibility
set.seed(123)
# Simulate a population of university students with food expenses (in USD)
pop_size <- 5000
population <- data.frame(
ID = 1:pop_size,
Food_Expense = rnorm(pop_size, mean = 250, sd = 50) # Mean $250, SD $50
)
# Sample size
sample_size <- 100
srs_sample <- population[sample(1:pop_size, sample_size), ]
srs_mean <- mean(srs_sample$Food_Expense)
srs_se <- sd(srs_sample$Food_Expense) / sqrt(sample_size)
srs_moe <- qt(0.975, df = sample_size - 1) * srs_se
convenience_sample <- population[1:sample_size, ]
conv_mean <- mean(convenience_sample$Food_Expense)
conv_se <- sd(convenience_sample$Food_Expense) / sqrt(sample_size)
conv_moe <- qt(0.975, df = sample_size - 1) * conv_se
# Create a result dataframe
result <- data.frame(
Method = c("Simple Random Sampling", "Convenience Sampling"),
Mean_Estimate = c(srs_mean, conv_mean),
Standard_Error = c(srs_se, conv_se),
Margin_of_Error = c(srs_moe, conv_moe)
)
# Display the result table
print(result)
## Method Mean_Estimate Standard_Error Margin_of_Error
## 1 Simple Random Sampling 247.4783 5.098629 10.116786
## 2 Convenience Sampling 254.5203 4.564079 9.056124
ggplot(result, aes(x = Method, y = Mean_Estimate, fill = Method)) +
geom_bar(stat = "identity", position = "dodge") +
geom_errorbar(aes(ymin = Mean_Estimate - Margin_of_Error, ymax = Mean_Estimate + Margin_of_Error), width = 0.2) +
labs(title = "Comparison of Sampling Methods in Handling Margin of Error",
y = "Estimated Average Food Expense (USD)",
x = "Sampling Method") +
theme_minimal()