[R] prop.trend.test question

tgs77m m@iii@g oii y@hoo@com tgs77m m@iii@g oii y@hoo@com
Mon Sep 25 04:10:37 CEST 2023


Colleagues,

The code for prop.trend.test is given by:

function (x, n, score = seq_along(x)) 
{
    method <- "Chi-squared Test for Trend in Proportions"
    dname <- paste(deparse1(substitute(x)), "out of",
deparse1(substitute(n)), 
        ",\n using scores:", paste(score, collapse = " "))
    x <- as.vector(x)
    n <- as.vector(n)
    p <- sum(x)/sum(n)
    w <- n/p/(1 - p)
    a <- anova(lm(freq ~ score, data = list(freq = x/n, score =
as.vector(score)), 
        weights = w))
    chisq <- c(`X-squared` = a["score", "Sum Sq"])
    structure(list(statistic = chisq, parameter = c(df = 1), 
        p.value = pchisq(as.numeric(chisq), 1, lower.tail = FALSE), 
        method = method, data.name = dname), class = "htest")
}

It seems to me that the direction of the trend is found using the weighted
regression lm(freq ~ score, data = list(freq = x/n, score =
as.vector(score)), 
        weights = w))

Am I on the right track here?

Thomas Subia



More information about the R-help mailing list