Finding Critical Values
The density function of t-distribution is given by dt() with degree of freedom n. The quantile function of t-distribution is obtained by qt().
t = qt(alpha,n,lower.tail=F)returns the critical value of t-distribution with level alpha.
Here is the graphical demonstration for the concept of critical value.
df=5; alpha = 0.05; range = c(-4,4); x = seq(range[1], range[2], length=100); y = dt(x,df); ymax = dnorm(0); plot(x, y, type='l', lwd=1, frame.plot=F, ylim=c(0,ymax), main=paste('Critical point with', alpha)); cvalue = qt(alpha,df,lower.tail=F) xx = seq(max(c(range[1],cvalue)), range[2], length = 50); y = dt(xx,df); polygon(c(xx,max(xx),min(xx)), c(y,0,0), col = 'green'); text(min(xx),1.2*max(y), round(cvalue,digits=4)); lines(x, dnorm(x), lty=2, col=2); legend(range[2]*0.4, ymax*.95, lty=c(1,2), col=c(1,2), legend=c(paste('t(',df,' df)',sep=”), 'N(0,1)'));
Programming Note. In the arguments to plot(), "frame.plot=F" suppresses the drawing of frame box for a plot.
paste(string1, string2, ...)concatenates values string1, string2, and so on, and returns the concatenated string.
Sample R code. You can download tdemo.R, and run it.
© TTU Mathematics