The file got a bit garbled in the email, so I’ve submitted it to RPubs:  
http://rpubs.com/rpruim/normal-prob-table

I thought that would give access to the source as well, but it doesn’t seem to, 
so I’ve posted the RMarkdown, HTML, and PDF here:

http://www.calvin.edu/~rpruim/R/misc/ProbabilityTable/

As a side effect of wanting to put the doc on Rpubs, I created a version that 
can switch hit between HTML and PDF.  RPubs shows the HTML version, but if you 
grab the Rmd file and knitPDF it, you will get a PDF version.  (If you are 
curious to see how to have the document detect which format is being produced, 
look at the markdown and search for “target".)

—rjp

PS.  I haven’t used tables like this in a quite awhile.  I generally have my 
students using RStudio during exams if they need access to this sort of 
calculation.  Else I simply write an exam about different things.  But there 
are standardized exams for which various sorts of tables are provided, and you 
should be able to tweak my example to create tables in the desired format.  
(The Fundamentals of Engineering Exam, for example, provides lower tail, upper 
tail, central and 2-tailed probabilities in the table they provide, IIRC.)


On Feb 23, 2015, at 7:15 PM, Randall Pruim 
<[email protected]<mailto:[email protected]>> wrote:

I�m not a fan of probability tables.  I don�t use trig or log tables when for 
calculus, why should I use normal probability tables when I teach statistics.

But I am a fan of good R coding and of knitr, and since Arthur wished for an 
RMarkdown version of his table and I think there are ways to improve the R used 
to generate the table (note the use of outer(), the avoidance of all loops, and 
letting the computer calculate sequences), I�ll offer the following RMarkdown 
file.  It is more complicated than necessary to show how to include a plot and 
how to control the table format a bit.  A minimalist version with just the 
table and no custom formatting would be shorter.

Anyway, here goes:


```{r include=FALSE} # execute this code, but don�t put anything into the output
require(xtable)
require(grid)        # for the plot
require(mosaic)      # for the plot
trellis.par.set(theme=theme.mosaic())   # change default colors for plot
big <- seq(0, 3.5, by = 0.1)
little <- seq(0, 0.09, by = 0.01)
norm_table <- outer(big, little, function(x,y) pnorm(x+y))
row.names(norm_table) <- format(big, digits=1)
colnames(norm_table)  <- format(little, digits=2)
```

The table gives values for $P(Z \le z)$ where $z$ is the sum of the left and 
right headers.

```{r echo=FALSE, fig.width = 7.0, fig.height = 2, fig.keep="last"}
plotDist("norm", groups = x >= 1, type="h")
ladd(grid.text(label=expression(P(Z <= z)), x = .2, y = .7))
```


```{r results="asis", echo=FALSE}
print(
 xtable(
   norm_table,
   digits=4,                          # display 4 digits
   align="|r|rrrrrrrrrr|"             # additional vertical lines
 ),
 hline.after = c(-1, seq(0, nrow(norm_table), by=4)),  # additional horizontal 
lines
 comment=FALSE)                       # avoid latex comment about table 
generation
```

On Feb 22, 2015, at 12:02 AM, Arthur Charpentier 
<[email protected]<mailto:[email protected]><mailto:[email protected]>>
 wrote:

Hi Steven
it might be out of scope but a few months ago, I published some codes to
generate such a table
see http://freakonometrics.hypotheses.org/9404
Arthur



2015-02-21 11:49 GMT+01:00 Steven Stoline 
<[email protected]<mailto:[email protected]><mailto:[email protected]>>:

One more thing;

3- how to force all output to be in a 4 decimal format. e.g. 1 should look
like 1.0000.

thanks
steve
---------- Forwarded message ----------
From: Steven Stoline 
<[email protected]<mailto:[email protected]><mailto:[email protected]>>
Date: Sat, Feb 21, 2015 at 5:37 AM
Subject: Normal Distribution Table
To: R-sig-teaching 
<[email protected]<mailto:[email protected]><mailto:[email protected]>>


Dear All:

I am trying to use the below R code to create the standard normal
distribution table. But I need some helps on the output:

1- how I can insert one line-space between each two rows.

2- there is  one "<NA>" in the output, how to remove it from the output.

Simply copy-paste the below code into R.


Here is the Code:
============


columnz<-c(0.00, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09)



rowz<-c(0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,


2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3.0,3.1,3.2,3.3,3.4,3.5,3.6,3.7,3.8,3.9,4.0)


normal.table<-function(columnz,rowz){


m<-length(rowz)

n<-length(columnz)


A<-matrix(NA, nrow = m+1 , ncol = n+1)


for (i in (1:m+1)) {

  A[i,1]<-"   "

}


for (j in (1:n+1)) {

  A[1,j]<-"------"

}


for (i in (1:m)) {
for (j in (1:n)){

####    A[i,j]<-round(pnorm(rowz[i]+columnz[j]),4)

 A[i+1,j+1]<-round(pnorm(rowz[i]+columnz[j]),4)


}

}



dimnames(A)<-list(c("  ",
"0.0","0.1","0.2","0.3","0.4","0.5","0.6","0.7","0.8","0.9",

"1.0","1.1","1.2","1.3","1.4","1.5","1.6","1.7","1.8","1.9",

"2.0","2.1","2.2","2.3","2.4","2.5","2.6","2.7","2.8","2.9",

"3.0","3.1","3.2","3.3","3.4","3.5","3.6","3.7","3.8","3.9","4.0"),
                  c("  ", " 0.00", " 0.01", " 0.02", " 0.03", " 0.04", "
0.05", " 0.06", " 0.07", " 0.08", " 0.09"))

print(A,quote=F)

invisible()

}

normal.table(columnz,rowz)


with many thanks
Steve

--
Steven M. Stoline
1123 Forest Avenue
Portland, ME 04112
[email protected]<mailto:[email protected]><mailto:[email protected]>



--
Steven M. Stoline
1123 Forest Avenue
Portland, ME 04112
[email protected]<mailto:[email protected]>

      [[alternative HTML version deleted]]

_______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-teaching


[[alternative HTML version deleted]]

_______________________________________________
[email protected]<mailto:[email protected]> mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-teaching


[[alternative HTML version deleted]]

_______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-teaching


        [[alternative HTML version deleted]]

_______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-teaching

Reply via email to