Is it possible to run the Jonckheere trend test (called also Jonckheere–Terpstra test) in Jamovi? If so, what package should I install?
Kindly thank you in advance for helping me

Code: Select all
JT_test <- function(groups, values) {
x <- table(groups, values)
n_col <- ncol(x)
n_row <- nrow(x)
jt_sum <- 0
for(j in 1:(n_col - 1))
for(i in 1:(n_row - 1))
jt_sum <- jt_sum + x[i, j] * (0.5 * sum(x[(i + 1):n_row, j]) +
sum(x[(i + 1):n_row, (j + 1):n_col]))
for(k in 1:(n_row - 1))
jt_sum <- jt_sum + x[k, n_col] * 0.5 * sum(x[(k + 1):n_row, n_col])
n <- sum(x)
nip <- apply(x, 1, sum)
npj <- apply(x, 2, sum )
expect <- (n^2 - sum(nip ^2))/4
u1 <- n * (n - 1) * (2 * n + 5) -
sum(nip * (nip - 1) * (2 * nip + 5)) -
sum(npj * (npj - 1) * (2 * npj + 5))
u2 <- sum(nip * (nip-1) * (nip-2)) * sum(npj * (npj-1) * (npj-2))
u3 <- sum(nip * (nip-1)) * sum(npj * (npj-1))
jt_var <- u1 / 72 + u2 / (36 * n * (n-1) * (n-2)) + u3 / (8 * n * (n-1))
jt_z <- (jt_sum - expect) / sqrt(jt_var)
## Alternative hypothesis
d_pval <- pnorm(jt_z) # decreasing
i_pval <- 1-d_pval # increasing
t_pval <- 2*min(d_pval, 1-d_pval, 0.5) # two.sided
cat("Jonckheere-Terpstra Test:\n",
" JT-test =", jt_sum,
" z-value =", jt_z, "\n",
"\nAlternative hypothesis:",
"\n (two.sided) p-value =", + round(t_pval, 5),
"\n (increasing) p-value =", + round(i_pval, 5),
"\n (decreasing) p-value =", + round(d_pval, 5), "\n"
)
}
### --- Using the JT_test function with sheet data
JT_test(as.character(data$A), data$B)
JT_test(groups = as.character(data$C), values = data$D)