Re: [R] prop.trend.test question
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 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.
[R] prop.trend.test question
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.
Re: [R] prop.trend.test
Argh, yes, drats, thanks. There will be a matter of an estimated residual error. So > coef(summary(ht$lmfit))["score","t value"]*sigma(ht$lmfit) [1] -2.867913 matches the signes square root of the Chi-square. Or, likely better (avoid 0 df cases), switch to a Gaussian glm fit and use the z stat > coef(summary(ht$glmfit, dispersion = 1)) Estimate Std. Error z value Pr(>|z|) (Intercept) 1.02187141 0.03199737 31.936102 8.425506e-224 score -0.03341563 0.01165155 -2.867913 4.131897e-03 The Estimate (-0.0334) should still make sense as the LPM estimate of the regression slope. - Peter D. > On 8 Sep 2023, at 12:53 , Rui Barradas wrote: > > Às 10:06 de 08/09/2023, peter dalgaard escreveu: >> Yes, this was written a bit bone-headed (as I am allowed to say...) >> If you look at the code, you will see inside: >> a <- anova(lm(freq ~ score, data = list(freq = x/n, score = >> as.vector(score)), >> weights = w)) >> and the lm() inside should give you the direction via the sign of the >> regression coefficient on "score". >> So, at least for now, you could just doctor a copy of the code for your own >> purposes, as in >> fit <- lm(freq ~ score, data = list(freq = x/n, score = as.vector(score)), >> weights = w) >> a <- anova(fit) >> and arrange to return coef(fit)["score"] at the end. Something like >> structure(... estimate=c(lpm.slope=coef(fit)["score"]) ) >> (I expect that you might also extract the t-statistic from >> coef(summary(fit)) and find that it is the signed square root of the >> Chi-square, but I won't have time to test that just now.) >> -pd >>> On 8 Sep 2023, at 07:22 , Thomas Subia via R-help >>> wrote: >>> >>> Colleagues, >>> >>> Thanks all for the responses. >>> >>> I am monitoring the daily total number of defects per sample unit. >>> I need to know whether this daily defect proportion is trending upward (a >>> bad thing for a manufacturing process). >>> >>> My first thought was to use either a u or a u' control chart for this. >>> As far as I know, u or u' charts are poor to detect drifts. >>> >>> This is why I chose to use prop.trend.test to detect trends in proportions. >>> >>> While prop.trend.test can confirm the existence of a trend, as far as I >>> know, it is left to the user >>> to determine what direction that trend is. >>> >>> One way to illustrate trending is of course to plot the data and use >>> geom_smooth and method lm >>> For the non-statisticians in my group, I've found that using this method >>> along with the p-value of prop.trend.test, makes it easier for the users to >>> determine the existence of trending and its direction. >>> >>> If there are any other ways to do this, please let me know. >>> >>> Thomas Subia >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> On Thursday, September 7, 2023 at 10:31:27 AM PDT, Rui Barradas >>> wrote: >>> >>> >>> >>> >>> >>> Às 14:23 de 07/09/2023, Thomas Subia via R-help escreveu: Colleagues Consider smokers <- c( 83, 90, 129, 70 ) patients <- c( 86, 93, 136, 82 ) prop.trend.test(smokers, patients) Output: Chi-squared Test for Trend inProportions data: smokers out of patients , using scores: 1 2 3 4 X-squared = 8.2249, df = 1, p-value = 0.004132 # trend test for proportions indicates proportions aretrending. How does one identify the direction of trending? # prop.test indicates that the proportions are unequal but doeslittle to indicate trend direction. All the best, Thomas Subia [[alternative HTML version deleted]] __ 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. >>> Hello, >>> >>> By visual inspection it seems that there is a decreasing trend. >>> Note that the sample estimates of prop.test and smokers/patients are equal. >>> >>> >>> smokers <- c( 83, 90, 129, 70 ) >>> patients <- c( 86, 93, 136, 82 ) >>> >>> prop.test(smokers, patients)$estimate >>> #>prop 1prop 2prop 3prop 4 >>> #> 0.9651163 0.9677419 0.9485294 0.8536585 >>> >>> smokers/patients >>> >>> #> [1] 0.9651163 0.9677419 0.9485294 0.8536585 >>> >>> plot(smokers/patients, type = "b") >>> >>> >>> >>> Hope this helps, >>> >>> Rui Barradas >>> >>> __ >>> 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. > Hello, > >
Re: [R] prop.trend.test
Say I have one machine that produces 15 million widgets per day. Every day a few widgets are defective. Is the proportion increasing? The data analyst needs to know what time span is of interest. I assume that there is some day-to-day variability. Is today's defect rate greater or less than yesterday's rate is not a trend. However, there might also be other trends. 4th shift might have a higher rate than 2nd shift, or within a shift the rate may change as workers tire or get breaks. I might try the PooledInfRate package. It calculates a proportion defective and a 95% confidence interval. Do the intervals overlap? I might try being selective. If the rate changes over the week, then the weekly cycle may obscure an underlying trend. For the last year, has the rate increased using only data from Monday? The question gets more complicated if there are multiple production lines and locations. High worker turnover may also be an issue. Tim -Original Message- From: R-help On Behalf Of Rui Barradas Sent: Friday, September 8, 2023 6:53 AM To: peter dalgaard ; Thomas Subia Cc: R. Mailing List Subject: Re: [R] prop.trend.test [External Email] Às 10:06 de 08/09/2023, peter dalgaard escreveu: > Yes, this was written a bit bone-headed (as I am allowed to say...) > > If you look at the code, you will see inside: > > a <- anova(lm(freq ~ score, data = list(freq = x/n, score = > as.vector(score)), > weights = w)) > > and the lm() inside should give you the direction via the sign of the > regression coefficient on "score". > > So, at least for now, you could just doctor a copy of the code for > your own purposes, as in > > fit <- lm(freq ~ score, data = list(freq = x/n, score = as.vector(score)), > weights = w) > a <- anova(fit) > > and arrange to return coef(fit)["score"] at the end. Something like > structure(... estimate=c(lpm.slope=coef(fit)["score"]) ) > > (I expect that you might also extract the t-statistic from > coef(summary(fit)) and find that it is the signed square root of the > Chi-square, but I won't have time to test that just now.) > > -pd > >> On 8 Sep 2023, at 07:22 , Thomas Subia via R-help >> wrote: >> >> Colleagues, >> >> Thanks all for the responses. >> >> I am monitoring the daily total number of defects per sample unit. >> I need to know whether this daily defect proportion is trending upward (a >> bad thing for a manufacturing process). >> >> My first thought was to use either a u or a u' control chart for this. >> As far as I know, u or u' charts are poor to detect drifts. >> >> This is why I chose to use prop.trend.test to detect trends in proportions. >> >> While prop.trend.test can confirm the existence of a trend, as far as >> I know, it is left to the user to determine what direction that trend is. >> >> One way to illustrate trending is of course to plot the data and use >> geom_smooth and method lm For the non-statisticians in my group, I've found >> that using this method along with the p-value of prop.trend.test, makes it >> easier for the users to determine the existence of trending and its >> direction. >> >> If there are any other ways to do this, please let me know. >> >> Thomas Subia >> >> >> >> >> >> >> >> >> >> >> >> >> On Thursday, September 7, 2023 at 10:31:27 AM PDT, Rui Barradas >> wrote: >> >> >> >> >> >> Às 14:23 de 07/09/2023, Thomas Subia via R-help escreveu: >>> >>> Colleagues >>> >>> Consider >>> smokers <- c( 83, 90, 129, 70 ) >>> patients <- c( 86, 93, 136, 82 ) >>> >>> prop.trend.test(smokers, patients) >>> >>> Output: >>> >>> Chi-squared Test for Trend inProportions >>> >>> data: smokers out of patients , >>> >>> using scores: 1 2 3 4 >>> >>> X-squared = 8.2249, df = 1, p-value = 0.004132 >>> >>> # trend test for proportions indicates proportions aretrending. >>> >>> How does one identify the direction of trending? >>> # prop.test indicates that the proportions are unequal but doeslittle >>> to indicate trend direction. >>> All the best, >>> Thomas Subia >>> >>> >>> [[alternative HTML version deleted]] >>> >>> __ >>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>
Re: [R] prop.trend.test
Às 10:06 de 08/09/2023, peter dalgaard escreveu: Yes, this was written a bit bone-headed (as I am allowed to say...) If you look at the code, you will see inside: a <- anova(lm(freq ~ score, data = list(freq = x/n, score = as.vector(score)), weights = w)) and the lm() inside should give you the direction via the sign of the regression coefficient on "score". So, at least for now, you could just doctor a copy of the code for your own purposes, as in fit <- lm(freq ~ score, data = list(freq = x/n, score = as.vector(score)), weights = w) a <- anova(fit) and arrange to return coef(fit)["score"] at the end. Something like structure(... estimate=c(lpm.slope=coef(fit)["score"]) ) (I expect that you might also extract the t-statistic from coef(summary(fit)) and find that it is the signed square root of the Chi-square, but I won't have time to test that just now.) -pd On 8 Sep 2023, at 07:22 , Thomas Subia via R-help wrote: Colleagues, Thanks all for the responses. I am monitoring the daily total number of defects per sample unit. I need to know whether this daily defect proportion is trending upward (a bad thing for a manufacturing process). My first thought was to use either a u or a u' control chart for this. As far as I know, u or u' charts are poor to detect drifts. This is why I chose to use prop.trend.test to detect trends in proportions. While prop.trend.test can confirm the existence of a trend, as far as I know, it is left to the user to determine what direction that trend is. One way to illustrate trending is of course to plot the data and use geom_smooth and method lm For the non-statisticians in my group, I've found that using this method along with the p-value of prop.trend.test, makes it easier for the users to determine the existence of trending and its direction. If there are any other ways to do this, please let me know. Thomas Subia On Thursday, September 7, 2023 at 10:31:27 AM PDT, Rui Barradas wrote: Às 14:23 de 07/09/2023, Thomas Subia via R-help escreveu: Colleagues Consider smokers <- c( 83, 90, 129, 70 ) patients <- c( 86, 93, 136, 82 ) prop.trend.test(smokers, patients) Output: Chi-squared Test for Trend inProportions data: smokers out of patients , using scores: 1 2 3 4 X-squared = 8.2249, df = 1, p-value = 0.004132 # trend test for proportions indicates proportions aretrending. How does one identify the direction of trending? # prop.test indicates that the proportions are unequal but doeslittle to indicate trend direction. All the best, Thomas Subia [[alternative HTML version deleted]] __ 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. Hello, By visual inspection it seems that there is a decreasing trend. Note that the sample estimates of prop.test and smokers/patients are equal. smokers <- c( 83, 90, 129, 70 ) patients <- c( 86, 93, 136, 82 ) prop.test(smokers, patients)$estimate #>prop 1prop 2prop 3prop 4 #> 0.9651163 0.9677419 0.9485294 0.8536585 smokers/patients #> [1] 0.9651163 0.9677419 0.9485294 0.8536585 plot(smokers/patients, type = "b") Hope this helps, Rui Barradas __ 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. Hello, Actually, the t-statistic is not the signed square root of the X-squared test statistic. I have edited the function, assigned the lm fit and returned it as is. (print.htest won't print this new list member so the output is not cluttered with irrelevant noise.) smokers <- c( 83, 90, 129, 70 ) patients <- c( 86, 93, 136, 82 ) edit(prop.trend.test, file = "ptt.R") source("ptt.R") # stats::prop.trend.test edited to include the results # of the lm fit and saved under a new name ptt <- 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(fit <- 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 , lmfit =
Re: [R] prop.trend.test
Yes, this was written a bit bone-headed (as I am allowed to say...) If you look at the code, you will see inside: a <- anova(lm(freq ~ score, data = list(freq = x/n, score = as.vector(score)), weights = w)) and the lm() inside should give you the direction via the sign of the regression coefficient on "score". So, at least for now, you could just doctor a copy of the code for your own purposes, as in fit <- lm(freq ~ score, data = list(freq = x/n, score = as.vector(score)), weights = w) a <- anova(fit) and arrange to return coef(fit)["score"] at the end. Something like structure(... estimate=c(lpm.slope=coef(fit)["score"]) ) (I expect that you might also extract the t-statistic from coef(summary(fit)) and find that it is the signed square root of the Chi-square, but I won't have time to test that just now.) -pd > On 8 Sep 2023, at 07:22 , Thomas Subia via R-help > wrote: > > Colleagues, > > Thanks all for the responses. > > I am monitoring the daily total number of defects per sample unit. > I need to know whether this daily defect proportion is trending upward (a bad > thing for a manufacturing process). > > My first thought was to use either a u or a u' control chart for this. > As far as I know, u or u' charts are poor to detect drifts. > > This is why I chose to use prop.trend.test to detect trends in proportions. > > While prop.trend.test can confirm the existence of a trend, as far as I know, > it is left to the user > to determine what direction that trend is. > > One way to illustrate trending is of course to plot the data and use > geom_smooth and method lm > For the non-statisticians in my group, I've found that using this method > along with the p-value of prop.trend.test, makes it easier for the users to > determine the existence of trending and its direction. > > If there are any other ways to do this, please let me know. > > Thomas Subia > > > > > > > > > > > > > On Thursday, September 7, 2023 at 10:31:27 AM PDT, Rui Barradas > wrote: > > > > > > Às 14:23 de 07/09/2023, Thomas Subia via R-help escreveu: >> >> Colleagues >> >>Consider >> smokers <- c( 83, 90, 129, 70 ) >> patients <- c( 86, 93, 136, 82 ) >> >>prop.trend.test(smokers, patients) >> >>Output: >> >>Chi-squared Test for Trend inProportions >> >>data: smokers out of patients , >> >> using scores: 1 2 3 4 >> >> X-squared = 8.2249, df = 1, p-value = 0.004132 >> >># trend test for proportions indicates proportions aretrending. >> >>How does one identify the direction of trending? >># prop.test indicates that the proportions are unequal but doeslittle to >> indicate trend direction. >> All the best, >> Thomas Subia >> >> >> [[alternative HTML version deleted]] >> >> __ >> 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. > Hello, > > By visual inspection it seems that there is a decreasing trend. > Note that the sample estimates of prop.test and smokers/patients are equal. > > > smokers <- c( 83, 90, 129, 70 ) > patients <- c( 86, 93, 136, 82 ) > > prop.test(smokers, patients)$estimate > #>prop 1prop 2prop 3prop 4 > #> 0.9651163 0.9677419 0.9485294 0.8536585 > > smokers/patients > > #> [1] 0.9651163 0.9677419 0.9485294 0.8536585 > > plot(smokers/patients, type = "b") > > > > Hope this helps, > > Rui Barradas > > __ > 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.
Re: [R] prop.trend.test
You might want to consider exponential smoothing models such as Holt's (Double Exponential Smoothing). This method continually updates the trend parameter, and you can monitor the most recent value (for sign, or magnitude, or both). In R, some choices to fit the Holt model: 1. stats::HoltWinters() and set the gamma argument to FALSE for a non-seasonal model 2. forecast::holt() HTH, Eric On Fri, Sep 8, 2023 at 8:23 AM Thomas Subia via R-help wrote: > > Colleagues, > > Thanks all for the responses. > > I am monitoring the daily total number of defects per sample unit. > I need to know whether this daily defect proportion is trending upward (a bad > thing for a manufacturing process). > > My first thought was to use either a u or a u' control chart for this. > As far as I know, u or u' charts are poor to detect drifts. > > This is why I chose to use prop.trend.test to detect trends in proportions. > > While prop.trend.test can confirm the existence of a trend, as far as I know, > it is left to the user > to determine what direction that trend is. > > One way to illustrate trending is of course to plot the data and use > geom_smooth and method lm > For the non-statisticians in my group, I've found that using this method > along with the p-value of prop.trend.test, makes it easier for the users to > determine the existence of trending and its direction. > > If there are any other ways to do this, please let me know. > > Thomas Subia > > > > > > > > > > > > > On Thursday, September 7, 2023 at 10:31:27 AM PDT, Rui Barradas > wrote: > > > > > > Às 14:23 de 07/09/2023, Thomas Subia via R-help escreveu: > > > > Colleagues > > > > Consider > > smokers <- c( 83, 90, 129, 70 ) > > patients <- c( 86, 93, 136, 82 ) > > > > prop.trend.test(smokers, patients) > > > > Output: > > > > Chi-squared Test for Trend inProportions > > > > data: smokers out of patients , > > > > using scores: 1 2 3 4 > > > > X-squared = 8.2249, df = 1, p-value = 0.004132 > > > > # trend test for proportions indicates proportions aretrending. > > > > How does one identify the direction of trending? > > # prop.test indicates that the proportions are unequal but doeslittle to > > indicate trend direction. > > All the best, > > Thomas Subia > > > > > > [[alternative HTML version deleted]] > > > > __ > > 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. > Hello, > > By visual inspection it seems that there is a decreasing trend. > Note that the sample estimates of prop.test and smokers/patients are equal. > > > smokers <- c( 83, 90, 129, 70 ) > patients <- c( 86, 93, 136, 82 ) > > prop.test(smokers, patients)$estimate > #>prop 1prop 2prop 3prop 4 > #> 0.9651163 0.9677419 0.9485294 0.8536585 > > smokers/patients > > #> [1] 0.9651163 0.9677419 0.9485294 0.8536585 > > plot(smokers/patients, type = "b") > > > > Hope this helps, > > Rui Barradas > > __ > 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. __ 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.
Re: [R] prop.trend.test
Colleagues, Thanks all for the responses. I am monitoring the daily total number of defects per sample unit. I need to know whether this daily defect proportion is trending upward (a bad thing for a manufacturing process). My first thought was to use either a u or a u' control chart for this. As far as I know, u or u' charts are poor to detect drifts. This is why I chose to use prop.trend.test to detect trends in proportions. While prop.trend.test can confirm the existence of a trend, as far as I know, it is left to the user to determine what direction that trend is. One way to illustrate trending is of course to plot the data and use geom_smooth and method lm For the non-statisticians in my group, I've found that using this method along with the p-value of prop.trend.test, makes it easier for the users to determine the existence of trending and its direction. If there are any other ways to do this, please let me know. Thomas Subia On Thursday, September 7, 2023 at 10:31:27 AM PDT, Rui Barradas wrote: Às 14:23 de 07/09/2023, Thomas Subia via R-help escreveu: > > Colleagues > > Consider > smokers <- c( 83, 90, 129, 70 ) > patients <- c( 86, 93, 136, 82 ) > > prop.trend.test(smokers, patients) > > Output: > > Chi-squared Test for Trend inProportions > > data: smokers out of patients , > > using scores: 1 2 3 4 > > X-squared = 8.2249, df = 1, p-value = 0.004132 > > # trend test for proportions indicates proportions aretrending. > > How does one identify the direction of trending? > # prop.test indicates that the proportions are unequal but doeslittle to >indicate trend direction. > All the best, > Thomas Subia > > > [[alternative HTML version deleted]] > > __ > 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. Hello, By visual inspection it seems that there is a decreasing trend. Note that the sample estimates of prop.test and smokers/patients are equal. smokers <- c( 83, 90, 129, 70 ) patients <- c( 86, 93, 136, 82 ) prop.test(smokers, patients)$estimate #> prop 1 prop 2 prop 3 prop 4 #> 0.9651163 0.9677419 0.9485294 0.8536585 smokers/patients #> [1] 0.9651163 0.9677419 0.9485294 0.8536585 plot(smokers/patients, type = "b") Hope this helps, Rui Barradas __ 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.
Re: [R] prop.trend.test
Às 14:23 de 07/09/2023, Thomas Subia via R-help escreveu: Colleagues Consider smokers <- c( 83, 90, 129, 70 ) patients <- c( 86, 93, 136, 82 ) prop.trend.test(smokers, patients) Output: Chi-squared Test for Trend inProportions data: smokers out of patients , using scores: 1 2 3 4 X-squared = 8.2249, df = 1, p-value = 0.004132 # trend test for proportions indicates proportions aretrending. How does one identify the direction of trending? # prop.test indicates that the proportions are unequal but doeslittle to indicate trend direction. All the best, Thomas Subia [[alternative HTML version deleted]] __ 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. Hello, By visual inspection it seems that there is a decreasing trend. Note that the sample estimates of prop.test and smokers/patients are equal. smokers <- c( 83, 90, 129, 70 ) patients <- c( 86, 93, 136, 82 ) prop.test(smokers, patients)$estimate #>prop 1prop 2prop 3prop 4 #> 0.9651163 0.9677419 0.9485294 0.8536585 smokers/patients #> [1] 0.9651163 0.9677419 0.9485294 0.8536585 plot(smokers/patients, type = "b") Hope this helps, Rui Barradas __ 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.
Re: [R] prop.trend.test
The example is the example in the documentation for the method. There were no details. https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/prop.trend.test More documentation would be useful. Answering questions like what are these numbers? As shown, I see a cluster of three values in the 70-90 and an outlier at 129. The pattern repeats for patients, with very slightly different numbers. Is the outlier real or a data error? Are these values real or just some values stuffed into an example to show that I can get numbers back out? Tim -Original Message- From: R-help On Behalf Of Michael Dewey Sent: Thursday, September 7, 2023 11:52 AM To: Thomas Subia ; R. Mailing List Subject: Re: [R] prop.trend.test [External Email] Dear Thomas Are you looking for more than smokers / patients Michael On 07/09/2023 14:23, Thomas Subia via R-help wrote: > > Colleagues > > Consider > smokers <- c( 83, 90, 129, 70 ) > patients <- c( 86, 93, 136, 82 ) > > prop.trend.test(smokers, patients) > > Output: > > Chi-squared Test for Trend inProportions > > data: smokers out of patients , > > using scores: 1 2 3 4 > > X-squared = 8.2249, df = 1, p-value = 0.004132 > > # trend test for proportions indicates proportions aretrending. > > How does one identify the direction of trending? > # prop.test indicates that the proportions are unequal but doeslittle to > indicate trend direction. > All the best, > Thomas Subia > > > [[alternative HTML version deleted]] > > __ > 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. > -- Michael http://www.dewey.myzen.co.uk/home.html __ 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. __ 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.
Re: [R] prop.trend.test
Dear Thomas Are you looking for more than smokers / patients Michael On 07/09/2023 14:23, Thomas Subia via R-help wrote: Colleagues Consider smokers <- c( 83, 90, 129, 70 ) patients <- c( 86, 93, 136, 82 ) prop.trend.test(smokers, patients) Output: Chi-squared Test for Trend inProportions data: smokers out of patients , using scores: 1 2 3 4 X-squared = 8.2249, df = 1, p-value = 0.004132 # trend test for proportions indicates proportions aretrending. How does one identify the direction of trending? # prop.test indicates that the proportions are unequal but doeslittle to indicate trend direction. All the best, Thomas Subia [[alternative HTML version deleted]] __ 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. -- Michael http://www.dewey.myzen.co.uk/home.html __ 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.
[R] prop.trend.test
Colleagues Consider smokers <- c( 83, 90, 129, 70 ) patients <- c( 86, 93, 136, 82 ) prop.trend.test(smokers, patients) Output: Chi-squared Test for Trend inProportions data: smokers out of patients , using scores: 1 2 3 4 X-squared = 8.2249, df = 1, p-value = 0.004132 # trend test for proportions indicates proportions aretrending. How does one identify the direction of trending? # prop.test indicates that the proportions are unequal but doeslittle to indicate trend direction. All the best, Thomas Subia [[alternative HTML version deleted]] __ 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.
[R] prop.trend.test() and Cochran-Armitage Trend test
Hi, I was just wondering if prop.trend.test() is equivalent to the Cochran-Armitage Trend test? Thank you! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.