-
Notifications
You must be signed in to change notification settings - Fork 4
/
a4criticalchi2values.Rmd
49 lines (44 loc) · 2.11 KB
/
a4criticalchi2values.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Critical values for $\chi^2$-distribution {#app-criticalchi2values}
```{r criticalchi2values-auxiliaryfigure, echo=FALSE, fig.height=2}
# adapted from `kritieketwaarden_hulpfiguur.R`
# HQ 20140320 en 20200916
# everything with df=6
op <- par(mar=c(3,1,1,1)+0.1)
xmax=20
df=6
xx <- seq(df+1,xmax,by=.01)
yy <- dchisq(xx,df=df)
curve( dchisq(x,df=df), from=0, to=xmax, xaxt="n", yaxt="n", xlab="", ylab="", bty="n", lwd=3, n=501 )
polygon( x=c(df+1,xx), y=c(0,yy), col="lavender", border="lavender" )
curve( dchisq(x,df=df), from=0, to=xmax, xaxt="n", yaxt="n", xlab="", ylab="", bty="n", lwd=3,
n=501, add=TRUE )
text( df+3, dchisq(df+3,df=df)*.4, "p", adj=.5, cex=1 )
axis( side=1, at=c(0,df+1), labels=c("0",expression(chi^2)), cex=1, tick=F, line=-1 ) # cex is ignored
# abline( h=0, lty=1, col="grey70" )
# segments( x0=df, x1=df, y0=0, y1=dchisq(0,df=df), col="grey70" )
segments( x0=xx[1], x1=xx[1], y0=0, y1=yy[1], col="grey70" )
curve( dchisq(x,df=df), from=0, to=xmax, xaxt="n", yaxt="n", xlab="", ylab="", bty="n", lwd=3,
n=501, add=TRUE )
```
The critical value $(\chi^2)^*$ given below has a critical probability $p$ under
$H_0$, i.e. $P(\chi^2 \geq (\chi^2)^*|H_0)=p$.
The table below provides the critical boundary values $(\chi^2)^*$ for much used critical probabilities $p$, for the degrees of freedom indicated in the first column.
```{r A4.1, echo=FALSE}
pvals <- c(.2,.1,.05,.025,.01,.005,.0025,.001)
df <- c( seq(1,25,by=1),30,40,50,100,200,400 )
## # add extra row for infinity d.f. (using normal distro)
# add extra columns, one for d.f. values and one for spacing
appendixchi2 <- matrix("",nrow=length(df),ncol=2+length(pvals)) # matrix of char strings
for (i in 1:length(df))
for (j in 1:length(pvals))
appendixchi2[i,j+2] <- format( qchisq( p=pvals[j], lower.tail=FALSE, df=df[i] ),
digits=3, nsmall=2 )
appendixchi2[,1] <- format(df) # df in first column
appendixchi2 <- rbind(
c( "", "p", as.character(pvals) ),
appendixchi2
)
# suppress first row, and use as column names
knitr::kable(
appendixchi2[-1,], booktabs=TRUE, col.names=appendixchi2[1,], align="c" )
```