## Table 4.1 of Read and Cressie (1988).
# Goodness-of-fit test
dograce <- data.frame( dog = 1:8,
obs = c( 104, 95, 66, 63, 62, 58, 60, 87 ),
mod = rep( 74.375, 8 ) )
(res <- powerdiverger( x = dograce$obs, p = dograce$mod/(8*74.375) ) )
# Chi-square test.
res$results[[6]]
# cf. with 'chisq.test'
chisq.test( x = dograce$obs, p = dograce$mod/(8*74.375), correct = FALSE )
# Test for independence (contingency table).
# From 'chisq.test' help file
M <- as.table(rbind(c(762, 327, 468), c(484, 239, 477)))
dimnames(M) <- list(gender = c("F", "M"),
party = c("Democrat","Independent", "Republican"))
(Xsq <- chisq.test(M))
(powerdiverger( M ))
# cf. with
(chisq.test(M))
Run the code above in your browser using DataLab