< a quantity that can be divided into another a whole number of time />

Pretty printing statistical distribution tables

April 30, 2011

Before using statistical software, we learned to use standard tables for finding the quantile of a standard normal or a Student’s t distribution, given a type 1 risk. Here is a way to quickly print them on a PDF file using R and $\LaTeX$.

The R part

I’m considering this Table as an example of what I want to achieve.

pp <- c(.10, .05, .025, .01, .005, .001, .0005)
dof <- c(1:30, seq(32, 50, by=2), 55, 60, 65, 70, 80, 100, 150, 200)
res <- matrix(nc=length(pp), nr=length(dof), dimnames=list(dof, pp))
for (i in seq_along(pp))
  res[,i] <- qt(p=pp[i], df=dof, lower.tail=F)

Then, we just have to export this table as a standalone tex file:

res.tex <- xtable(res, digits=3)
print(res.tex, floating=FALSE, file="t-dist.tex",, length(dof), by=2)), "\\rowcolor[gray]{.9} "))

The TeX part

Using $\LaTeX$, I just wrote a wrapper file like this:


The result is shown below:


rstats tex

See Also

» Weaving scientific documents » Computing intraclass correlation with R » Fitting Rasch model with R lme4 » Visualizing What Random Forests Really Do » Psychoco 2011