2026-fall
In statistics, a population is the entire group of individuals, objects, measurements or outcomes that you want to learn about.
If you had the data for the entire population, you would be able ask and answer very direct questions.
Below we read in a dataset of 1000 numbers, draw a histogram of their values, then overlay a density plot from a probability distribution that fits the data.
## [1] 1000 1
## x
## Min. : 59.21
## 1st Qu.: 91.85
## Median :100.44
## Mean :100.62
## 3rd Qu.:109.18
## Max. :152.43
hist(numdat[,1], probability=T, breaks=100)
curve(dnorm(x, mean = 100, sd = 13),
col = "red", lwd = 2, add = TRUE)If we can figure out a way to represent the data as a parametric mathematical function, then we can ask questions using that mathematical function instead of having to deal with the full set of numbers.
In the plot above, the red line comes from a normal(Gaussian) probability distribution with mean=100 and standard dev=13. It’s a pretty good fit for the numbers we just read in.
A normal(Gaussian) distribution can be fully described by two parameters:
If you know the 2 parameters \(\mu\) and \(\sigma\), then you know everything there is know about the distribution.
That red line captures the ‘essence’ of 1000 numbers with just 2 parameters.
.
Calculus Quiz 1
calculate this probability in R
## [1] 0.0619679
We can also use R to visualize the problem.
# Parameters
mu <- 100
sigma <- 13
# Create a sequence of x values
x_vals <- seq(mu - 4*sigma, mu + 4*sigma, length = 500)
# Normal density values
y_vals <- dnorm(x_vals, mean = mu, sd = sigma)
# Base plot
plot(x_vals, y_vals, type = "l", lwd = 2, col = "black",
ylab = "Density", xlab = "x", main = "P(X > 120) under Normal Curve")
# Shade area where x > 120
x_shade <- seq(120, max(x_vals), length = 100)
y_shade <- dnorm(x_shade, mean = mu, sd = sigma)
polygon(c(120, x_shade, max(x_shade)),
c(0, y_shade, 0),
col = "lightblue", border = NA)
# Add vertical line at x = 120
abline(v = 120, col = "red", lty = 2)
# Add legend with computed probability
p_gt_120 <- 1 - pnorm(120, mean = mu, sd = sigma)
legend("topright", legend = paste0("P(X > 120) = ", round(p_gt_120, 4)),
bty = "n").
It’s a subset of population observations that we use to draw conclusions about the population.
In studying lung cancer in the Bronx, it’s a lot easier to collect info on 30 patients than every single patient that’s ever been treated here at Montefiore and the surrounding hospitals.
how do we make inferences about the population parameters?
What are the point estimates?
What are some examples of point estimates?
.
We use the sample point estimates to figure out the population parameters.
When we take a sample from a population and calculate a point estimate (like a sample mean or proportion), the result will vary from sample to sample because of the natural randomness in the sampling process.
the standard error (SE) is a measurement of the spread in the sample point estimate.
Remember this distinction:
.
Without having the complete observations of the entire population at hand it will be very hard to prove the underlying assumptions you make about the population parameters are true. The closest we can do is to show they are reasonable.
There are standard procedures for testing the assumptions of every common statistical test (e.g., Shapiro Wilk, Bartlett’s),
But it’s always a good idea to start with a visualization that shows how the distribution of your sample fairs against the distribution you’re assuming it to take.
Stands for the quantile-quantile plot. Here we show a scatterplot of the quantiles of our sample with the expected quantiles of the distribution we’re expecting it to follow. If the plots coincide with each other, then we can proceed with our test. If not, we should figure out a different test that doesn’t violate its assumptions.
# Step 1: Simulate some data
x <- rnorm(100, mean = 5, sd = 2) # Normally distributed sample
# Step 2: Sort the sample data
x_sorted <- sort(x)
# Step 3: Compute theoretical quantiles from the standard normal
n <- length(x_sorted)
# Use (i - 0.5)/n quantile levels
p <- (1:n - 0.5) / n
theoretical_q <- qnorm(p, mean = mean(x), sd = sd(x)) # match sample mean/sd
# Step 4: Plot
plot(theoretical_q, x_sorted,
main = "QQ Plot from Scratch",
xlab = "Theoretical Quantiles",
ylab = "Sample Quantiles",
pch = 19, col = "blue")
# Step 5: Add reference line (through first and third quartiles)
q_theo <- quantile(theoretical_q, c(0.25, 0.75))
q_sample <- quantile(x_sorted, c(0.25, 0.75))
slope <- diff(q_sample) / diff(q_theo)
intercept <- q_sample[1] - slope * q_theo[1]
abline(intercept, slope, col = "red", lwd = 2)But in practice, you would just use the built-in functions. To check
if your data follows a normal distribution, you can use
the qqnorm, and shapiro.test functions.
##
## Shapiro-Wilk normality test
##
## data: x
## W = 0.98348, p-value = 0.2456
In the past we had to use lookup tables to find our probabilities.
Now we use computers.
In R, the functions for working with probability distributions all have a similar format.
| Distribution | Name in R | Notes |
|---|---|---|
| Normal | norm |
Continuous |
| Binomial | binom |
Discrete |
| Poisson | pois |
Discrete |
| Exponential | exp |
Continuous |
| Chi-squared | chisq |
Continuous |
| Student’s t | t |
Continuous |
| F-distribution | f |
Continuous |
| Uniform | unif |
Continuous |
| Geometric | geom |
Discrete |
| Negative Binomial | nbinom |
Discrete |
| Hypergeometric | hyper |
Discrete |
| Gamma | gamma |
Continuous |
| Beta | beta |
Continuous |
| Weibull | weibull |
Continuous |
| Logistic | logis |
Continuous |
What’s the area under the curve to the the left of 0, in a standard normal distribution?
## [1] 0.5
What value of x would give you an area under the curve of 0.5?
## [1] 0
Plot the values from -3 to 3 of the standard normal distribution
#first get the range of x values you to to plot
xvals = seq(-3, 3, 0.01)
#then get the probabilites of each of those values
yvals = dnorm(xvals)
#now plot them in a scatter plot
plot(xvals, yvals)Find the area to the right of 1.96 in a standard normal
## [1] 0.9750021
## [1] 0.0249979
What’s the area between -1.96 and 1.96 in a standard normal?
## [1] 0.9500042
What’s the area under the curve of all the values higher than 1.96, or lower than -1.96?
## [1] 0.0249979
## [1] 0.0249979
## [1] 0.04999579
generate 30 random numbers from a standard normal distribution
## [1] -0.95432215 -0.28515122 -1.57502819 -0.33562222 -2.21865419 0.80735407
## [7] -0.91664212 0.77078600 -0.01685817 -1.88395141 0.56094278 -0.27729275
## [13] 1.93240750 0.38904165 -1.42447942 1.44688360 0.24233406 -0.26041695
## [19] 0.05200804 -1.61673287 2.00346078 -1.07664766 -0.48237020 -1.38009043
## [25] 0.91965947 -0.07994883 1.04690813 -2.47708298 -2.13654282 -0.03938584
.