#Packages List
library(readr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
x_values <- seq(-4, 4, 0.01)
normal_data <- data.frame(x = x_values, y = dnorm(x_values))
t_dist_df2 <- data.frame(x = x_values, y = dt(x_values, df = 2))
t_dist_df5 <- data.frame(x = x_values, y = dt(x_values, df = 5))
t_dist_df15 <- data.frame(x = x_values, y = dt(x_values, df = 15))
t_dist_df30 <- data.frame(x = x_values, y = dt(x_values, df = 30))
t_dist_df120 <- data.frame(x = x_values, y = dt(x_values, df = 120))
combined_data <- bind_rows(
data.frame(distribution = "Normal", normal_data),
data.frame(distribution = "t (df=2)", t_dist_df2),
data.frame(distribution = "t (df=5)", t_dist_df5),
data.frame(distribution = "t (df=15)", t_dist_df15),
data.frame(distribution = "t (df=30)", t_dist_df30),
data.frame(distribution = "t (df=120)", t_dist_df120))
ggplot(data = combined_data,
mapping = aes(x = x,
y = y,
color = distribution)) +
geom_line(size = 1.5,
linetype = ifelse(test = combined_data$distribution == "Normal",
yes = "solid",
no = "solid")) +
labs(title = "Normal and Student's t-Distributions",
x = "Value",
y = "Density") +
theme_minimal()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
As we can see, when the degrees of freedom increase, the t-distribution approaches a normal distribution.
set.seed(123)
mu <- 108
sigma <- 7.2
data_values <- rnorm(n = 1000, mean = mu, sd = sigma)
pdf <- dnorm(x = data_values,
mean = mu,
sd = sigma)
plot(x = data_values,
y = pdf,
col = 'black',
lwd = .5,
xlab = 'Pounds',
ylab = 'Density',
main = 'Normal Distribution')
z_scores <- (data_values - mu) / sigma
hist(z_scores,
breaks = 30,
col = "lightblue",
border = "black",
main = "Z-distribution",
xlab = "Z-scores")
Both distributions do have the same distributional shape. This is due to the fact that a z-distribution is a standard normal distribution but centered at 0 and a standard distribution of 1.
The p-value indicates how unusual or likely the observed data is, assuming that the null hypothesis is true. For example, if the p value is 0.05, that means that 5% of the time you would see a test statistic at least as extreme as the one you found if the null hypothesis was true.