[R] Chi-square test for trend - where is prop.trend.test?

Mark Myatt mark at myatt.demon.co.uk
Tue Sep 26 14:17:48 CEST 2000


Peter,

Thanks. That did the trick.

Mark

>That'll be 0.0.1 too little. It slipped throught the cracks for 1.1.0
>and got inserted in 1.1.1
>
>However, it is hardly rocket science:
>
>prop.trend.test <-
>function (x, n, score = 1:length(x)) 
>{
>    method <- "Chi Square Test for Trend in Proportions"
>    dname <- paste(deparse(substitute(x)), "out of", deparse(substitute(n)))
>    dname <- paste(dname, ",\n using scores:", paste(score, collapse = " "))
>    freq <- x/n
>    p <- sum(x)/sum(n)
>    w <- n/p/(1 - p)
>    a <- anova(lm(freq ~ score, weight = w))
>    chisq <- a["score", "Sum Sq"]
>    names(chisq) <- "X-squared"
>    df <- 1
>    names(df) <- "df"
>    pval <- 1 - pchisq(chisq, 1)
>    rval <- list(statistic = chisq, parameter = df, p.value = pval, 
>        method = method, data.name = dname)
>    class(rval) <- "htest"
>    return(rval)
>}
>


--
Mark Myatt


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list