In a word: Yes.

We discussed this about 2w ago. Basically, the lm() fits a local Linear 
Probability Model and the coef to "score" gives you the direction of the effect.

In the same thread it was discussed (well, readable between the lines, maybe) 
that if you change the lm() to a Gaussian glm() and use summary(..., 
dispersion=1), you can extract the z-test version of the trend test. (I think 
that the reason for using the chisquare version was to match the example in 
Altman: Practical Statistics for Medical Research.)

Arguably the code should be updated to use the z and at the same time include 
alternative=c("two.sided", "less", "greater") like other 1df tests have. Just a 
matter of these darn little round tuits that you seem never to be able to 
get... Also slightly tricky whether/how to make it backwards compatible.

- pd

> On 25 Sep 2023, at 04:10 , tgs77m--- via R-help <r-help@r-project.org> wrote:
> 
> 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
> 
> ______________________________________________
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd....@cbs.dk  Priv: pda...@gmail.com

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to