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

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Tue Sep 26 10:49:14 CEST 2000


Mark Myatt <mark at myatt.demon.co.uk> writes:

> Peter,
> 
> I wrote:
> 
> >> Is there a function to do a chi-square test for trend or equivalent in
> >> R. I can write one myself but I was wondering, before I get down to it,
> >> if I need to re-invent the wheel.
> 
> You replied:
> 
> >Will prop.trend.test do what you want? 
> 
> The name sounds right. Where do I find this function? I am running RWin
> 1.1.0.

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)
}

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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