# Does anyone know about the principle of pnorm method in residual after chisq.test?

I found the website which explain about residuals after chisq. test. The website explain below the Method of calculation.

res$expected [,1] [,2] [,3] [,4] [1,] 1.8333333 4.4 4.033333 0.7333333 [2,] 2.3333333 5.6 5.133333 0.9333333 [3,] 0.8333333 2.0 1.833333 0.3333333 res$residuals
[,1]       [,2]       [,3]        [,4]
[1,]  1.6001894  0.2860388 -1.0124568 -0.85634884
[2,] -1.5275252  0.5916080  0.3825184  0.06900656
[3,]  0.1825742 -1.4142136  0.8616404  1.15470054

res$stdres [,1] [,2] [,3] [,4] [1,] 2.202652 0.4640162 -1.5986161 -1.1138229 [2,] -2.291288 1.0458250 0.6581681 0.0978076 [3,] 0.219089 -2.0000000 1.1860432 1.3093073 pnorm(abs(res$stdres), lower.tail=FALSE)*2
[,1]       [,2]      [,3]      [,4]
[1,] 0.02761930 0.64263616 0.1099059 0.2653552
[2,] 0.02194677 0.29564182 0.5104301 0.9220851
[3,] 0.82658070 0.04550026 0.2356052 0.1904303


I understand from res-expected to res-stdres, but I cannot understand why pnorm(abs(res$stdres), lower.tail=FALSE)*2 can calculate each residuals p-value. Does anyone know the principle, or reference that related this method? I'm not good at English, so I'm sorry if it is difficult for you to understand my English. • It might be helpful if you could link to &/or quote from the website in question. – gung - Reinstate Monica Aug 21 '16 at 19:44 • Thanks for your edited! it is the link→ aoki2.si.gunma-u.ac.jp/R/my-chisq-test.html It's in Japanese but I hope you can understand.. – kyk Aug 21 '16 at 19:47 • Unfortunately, I don't read Japanese, & Google translate doesn't seem to work on the page for some reason. Can you translate & paste in the explanation? I'm not sure if this will be answerable otherwise. – gung - Reinstate Monica Aug 21 '16 at 20:01 • Thanks for your reply! This website said that R can calculate chi-squared test and also can calculate residuals, but after that we have to calculate adjusted residuals ourselves. so this website explain how to do that. this website tell that res$expected=Expected value , res-residuals=Standardized residual, and res-stdres= adjusted residuals, pnorm(abs(res-stdres), lower.tail=FALSE)*2 = p-value. But only that this website don't explain why pnorm(abs(res-stdres), lower.tail=FALSE)*2 can calculate p-value. – kyk Aug 21 '16 at 20:14
• If possible, I'd like to use this method in my research, therefore I have to know the principle to use it because I have to explain about it on my paper. But I don't understand the meaning this code.. – kyk Aug 21 '16 at 20:16

## 1 Answer

From r documentation (try ?pnorm) we see that:

pnorm(q, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)

...

pnorm gives the distribution function

....

lower.tail logical; if TRUE (default), probabilities are P[X ≤ x] otherwise, P[X > x].

Putting it together

pnorm(abs(res$stdres), lower.tail=FALSE)*2 is computing$2 \times P(Z > |\text{stdres}|)$which is the$p\$-value computation if the standardized residuals are assumed to have a standard normal distribution and if the test is two-tailed.

• I see! Yes, I understand. Thank you for your reply! – kyk Aug 22 '16 at 11:53