Skip to content

Instantly share code, notes, and snippets.

@grantbrown
Created June 4, 2013 22:08
Show Gist options
  • Save grantbrown/5710043 to your computer and use it in GitHub Desktop.
Save grantbrown/5710043 to your computer and use it in GitHub Desktop.
Animated illustration of how degrees of freedom affect the shape of the student's-t distribution.
# T Distribution Illustration
TimeDelay = 0.5
plotT = function(df, add = FALSE)
{
f = function(x)
{
return(dt(x, df))
}
curve(f, xlim = c(-6,6), ylim = c(0, 0.5), add = add, main = "T Distribution vs. Standard Normal",ylab = "Density")
curve(dnorm, add=T, lty = 2, col = "red")
legend(x = -6,y=0.5,legend = c("Normal"), lty = 2, col = "red")
text(x = 2.5, y = 0.4, labels = paste("Degrees of Freedom: ", df, sep = ""))
}
for (i in 1:100)
{
plotT(i)
Sys.sleep(TimeDelay)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment