\documentclass[12pt]{article}

\usepackage{Math203}

\usepackage{amsmath,amssymb}
\usepackage{hyperref}
\usepackage{color}
\usepackage{xcolor}
\usepackage{enumitem}
\usepackage{xcolor}
\usepackage{longtable}
\usepackage{booktabs}


\pagestyle{plain}

\renewcommand{\labelenumi}{\arabic{enumi}.}
\renewcommand{\labelenumii}{\arabic{enumi}.\arabic{enumii}}
\renewcommand{\labelenumiii}{\arabic{enumi}.\arabic{enumii}.\arabic{enumiii}}

\setlength{\topmargin}{-0.75 in} \setlength{\textheight}{9.5 in}

\parindent0in

\newenvironment{packed_enum}{
\begin{enumerate}
  \setlength{\itemsep}{12pt}
  \setlength{\parskip}{0pt}
  \setlength{\parsep}{0pt}
  \setlength{\topsep}{0pt}
}{\end{enumerate}}

\renewcommand{\labelitemii}{$\blacktriangleright$}

\def\ctitle{Math 203: Principles of Statistics 1}
\def\ttitle{Fall 2024}
\def\stitle{t-Distribution Tables}

\makeatletter
\def\@maketitle{%
  \newpage
  \null
  \begin{center}%
    {\textsclarge{\ctitle} \par}%
    \medskip
    {\textsclarge{\ttitle} \par}%
    \medskip
    {\textsc{\stitle} \par}
  \end{center}%
  \par
  \vskip 1.5em}
\makeatother

\begin{document}

<<funcs,echo=FALSE>>=
myrnd <- function(x,d) {formatC(x, format="f", digits=d)}
library(shape)
library(diagram)
@

\maketitle
The table on page 2 displays upper $a$ points for the t-distribution, that is, the values $t_{a,\nu}$ such that
\[
P(T < t_{a,\nu}) = 1 - a
\]
where $T$ is a random variable having a t-distribution with $\nu$ degrees of freedom.

<<chunk1,fig.height=5, fig.width=8,echo=FALSE,size='small'>>=
xv<-seq(-4,4,by=0.01)
yv<-dt(xv,5)
par(mar=c(4,4,4,2))
plot(xv,yv,type='l',main='t-distribution',xlab='x',ylab='f(x)')
polygon(c(xv[600:801],rev(xv[600:801])),c(0*xv[600:801],rev(yv[600:801])),col='gray')
arrows(2.5,0.2,2.2,0.025,angle=10)
text(2.5,0.21,'a')
arrows(0,0.1,2,0.0,angle=10)
text(0,0.12, expression(t[paste(a, ",", nu)]))
@

That is, we fix $a$, and solve the equation
\[
\int_{x}^\infty f(t) \  dt = a
\]
for $x$: the solution is $x=t_{a,\nu}$.

\bigskip

For a $100(1-\alpha)\%$ confidence interval, we look for the values that put a total amount of probability $\alpha$ in the two tails, that is
\[
P(l < T < r) = 1-\alpha
\]
so that by symmetry
\[
P(T < l) = P(T > r) = \alpha/2.
\]
So for a $100(1-\alpha)\%$ confidence interval, we must look up the $\alpha/2$ upper point 



<<chunk2,fig.height=5, fig.width=8,echo=FALSE,eval=FALSE,size='small'>>=
qv<-c(0.1,0.05,0.025, 0.02, 0.01, 0.005, 0.0025, 0.001)
nu<-c(4:30,Inf)
p.mat<-matrix(0,nrow=length(nu),ncol=length(qv))
for(i in 1:length(nu)){
    p.mat[i,]<-round(qt(1-qv,nu[i]),4)
}
rownames(p.mat)<-nu
colnames(p.mat)<-myrnd(qv,4)
p.mat
@

<<chunk3,echo=FALSE>>=
nu<-c(4:30,Inf)
pv<-c(0.1,0.05,0.025, 0.02, 0.01, 0.005, 0.0025, 0.001)
amat<-matrix(0,nrow=length(nu),ncol=length(pv))
for(i in 1:length(nu)){
    amat[i,]<-round(qt(1-pv,nu[i]),4)
}
library(kableExtra)
atab<-cbind(nu,amat)
colnames(atab)<-c(" ",as.character(pv))
kbl(atab, "latex", booktabs = T, caption = "Upper $a$ points of $t_{\\nu}$ distribution") %>%
add_header_above(c("$\\\\nu$" = 1, "$a$" = 8), escape=FALSE) %>%
kable_styling(latex_options = c("repeat_header","hold_position")) %>%
row_spec(27,hline_after=T)
@

\pagebreak
The final row, where $\nu$ is infinite, corresponds to the Normal case, and we may use this approximation when $\nu$ is large.  So for example, we may compute

\begin{itemize}
  \item $\nu = 18$:  $P( T > 2.1009) = 0.025$.
  \item $\nu = 26$:  $P( T > 2.7787) = 0.005$
  \item $\nu = 50$:  $P( T > 2.0537) \approx 0.02$.
\end{itemize}

\end{document} 