Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Test for trends in proportions, based on scores
- score.prop.test <- function(x) {
- colsum <- apply(x,2,sum)
- rowsum <- apply(x,1,sum)
- propcol <- x[1,]/colsum
- frate <- rowsum[1]/sum(rowsum)
- if(ncol(x)%%2 == 0) {
- scores <- seq(2,ncol(x)*2,by=2)-(ncol(x)+1)
- } else {
- scores <- 1:ncol(x)-ceiling(ncol(x)/2)
- }
- scoresMean <- sum(colsum*scores)/sum(colsum)
- Npxx <- sum(colsum*propcol*(scores-scoresMean))
- Nxx2 <- sum(colsum*(scores-scoresMean)^2)
- b <- Npxx/Nxx2
- Vb <- (frate*(1-frate))/Nxx2
- X2 <- (b^2)/Vb
- df <- ifelse(ncol(x) <= 2, 1, ncol(x)-2)
- pvalue <- 1-pchisq(X2,df)
- structure(list("b"=b, "V(b)"=Vb, "X squared"=X2, "df"=df, "p-value"=pvalue))
- }
- # TEST
- # Relationship between nasal carrier rate for Streptococcus pyogenes and size of tonsils.
- stcarriers <- matrix(c( 19, 29, 24,
- 497,560,269),
- ncol=3, byrow=TRUE)
- score.prop.test(stcarriers)
- # Armitage, P. (1955). Tests for Linear Trends in Proportions and Frequencies.
- # Biometrics, Vol. 11, No. 3 (Sep., 1955), pp. 375-386
- # URL: http://www.jstor.org/stable/3001775
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement