Students often leave a first-semester statistics course thinking basically everything is normal, or at least if we sample enough, we’ll end up with a normal distribution. The animation here is the distribution of the sample maximum from an exponential rate 0.25 distribution for increasing sample sizes.
As you can see, the distribution is skewed to the right, and this skewness doesn’t go away as the sample size increases. As a quiz question, why does the distribution move to the right?
This is a short post, but hopefully illustrative. Below is the graph of the exponential rate 0.25 density, and the R code for the animation is at the end.
Please share and like
Please help me find readers by forwarding this article to your friends (and even those who aren't your friends), sharing this post on social media, and clicking like. If you're on Twitter, you can find me at BriefedByData. If you have any article ideas, feedback, or other views, please email me at briefedbydata@substack.com.
Thank you
In a crowded media market, it's hard to get people to read your work. I have a long way to go and I want to say thank you to everyone who has helped me find and attract subscribers.
R code for animation
# Libraries
library(dplyr)
library(tidyr)
library(ggplot2)
library(gganimate)
## Colors
MyPurple <- "#5B005B"
MyLightP <- "#dfdbdf"
MyLightP2 <- "#f8f4f8"
MyLightP3 <- "#fcfafc"
## Data
nReplicate <- 10000
Data <- data.frame("Sample" = replicate( nReplicate, max( rexp( 1, rate = 0.25 ))), "Number" = 1)
for (i in c(2, 4, 6, 8, 10, 15, 20, 30, 40, 50, 100)) {
DataTemp <- data.frame( "Sample" = replicate( nReplicate, max( rexp( i, rate = 0.25))), "Number" = i)
Data <- rbind( Data, DataTemp)
}
p <- ggplot(Data, aes( Sample, fill = factor( Number))) +
geom_density( alpha = 0.4, bw = 3) +
scale_x_continuous( limits = c(-5, 40)) +
transition_states( Number, transition_length = 3, state_length = 1 ) +
enter_fade() +
exit_fade() +
shadow_mark( alpha = alpha / 4, color = alpha( "grey", 0.25)) +
guides( fill = "none") +
ease_aes( "linear") +
theme( strip.background = element_blank(), strip.text.x = element_blank())+
theme( axis.text = element_text( size = 14),
axis.title = element_text( size = 16),
plot.title = element_text( size = 20),
plot.background = element_rect( fill = MyLightP3),
panel.background = element_rect( fill = MyLightP),
legend.background = element_rect( fill = MyLightP2),
plot.caption = element_text( hjust = c(1), size = c(14),
color = c(MyPurple))) +
labs(title="Distribution of Sample Maximum from an Exponential rate 0.25 Distribution\n Sample Size = {closest_state}",
y = NULL, x = NULL,
caption = c("Briefed by Data || Thomas J Pfaff"))+
theme(legend.position = "none")
animate(p, fps = 5, duration = 10, width = 1456/2, height = 936/2)