In [1]:
options(repr.plot.width=10, repr.plot.height=6.5) # this command just formats the size of the figures. Adapt to view them nicely
# in your browser.
In [2]:
# Visualize the t_n distribution and compare it to the normal distribution, z.
# Blue: Standard normal distribution Z~N(0,1).
# Red: T-distribution with df degrees of freedom.
df=2; # degrees of freedom in the t-distribution, t_df. df=#datapoints -1
x=seq(-7,7,by=0.01)
plot(x,dnorm(x),type="l",col="blue", ylab = "probability density", xlab = "T/Z test statistic")
lines(x,dt(x,df),col="red")
In [3]:
# Visualize the t_n distribution for different degrees of freedom.
df=c(1,2,3,4,5,6,7,8) # build a vector with different values for df
x=seq(-7,7,by=0.01)
plot(x,dnorm(x),type="l", ylab = "probability density", xlab = "T/Z test statistic",ylim=c(0,0.5)) # plots a z-distribution
# Plot T-distributions at all the values contained in the df vector
index=0
for (i in df){
index=index+1
lines(x,dt(x,i),type="l",col=rainbow(length(df))[index])
}
In [7]:
# Visualize the t_n distribution for different degrees of freedom in log
df=c(1,2,3,4,5,6,7,8,50000)
x=seq(-7,7,by=0.01)
plot(x,log(dnorm(x)),type="l",col="blue", ylab = "probability density", xlab = "T/Z test statistic")
index=0
for (i in df){
index=index+1
lines(x,log(dt(x,i)),type="l",col=rainbow(length(df))[index])
}
In [ ]: