[R] Mantel Haenszel test
Colleagues, I am trying to write a script for the Mantel Haenszel test. For the MH test, the test statistic is chi-square (MH) = (W-1) * r^2 Where W = sum of the case weights. This is straight forward. I'm having difficulty with r^2. The r^2 is the squared Pearson correlation between row and column variables. Can anyone give me an example of the code which calculates the squared Pearson correlation between row and column variables? I am at a loss on how to do this. All the best, 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.
[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.
[R] Discriminant of a cubic polynomial
Colleagues Given the coefficients of a cubic polynomial, a,b,c,d and using discriminant_cubic <- function(a, b, c, d) { D <- 18 * a * b * c * d - 4 * b^3 * d + b^2 * c^2 - 4 * a * c^2 - 27 * a^2 * d^2 return(D) } I can find the discriminant of a cubic polynomial. Is there an R package which can do this? 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 https://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] JASP vs R
Colleagues, Many of my colleagues come to me for a recommendation for statistical software. Since I am an R user, that's my typical answer. Some colleagues of mine refuse to use it because of its steep learning curve and lack of a GUI. They wanted a statistical software that's free and that had a GUI. I recently learned about JASP. See https://jasp-stats.org/ for more details This may be an answer to their needs. Does anyone out their have any experience with this? 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 https://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] dplyr summarize by groups
# Get mean, min, max sigma and skew by group options (digits = 3) library (ISwR data(energy) data %>% group_by(stature) %>% summarize( Mean = mean(expend), Min = min(expend), Max = max(expend), Sigma = sd(expend), Skew = skew(expend)) # Output stature Mean Min Max Sigma Skew 1 lean 8.07 6.13 10.9 1.24 0.907 2 obese 10.3 8.79 12.8 1.40 0.587 Why does output stats vary in decimal places even when options (digits=3) were set? All the best Thomas S. [[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 https://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.