How to perform Jonckheere-Terpstra Test?

When you choose to analyse your data using a Jonckheere-Terpstra test, part of the process involves checking to make sure that the data you want to analyse can actually be analysed using a Jonckheere-Terpstra test. You need to do this because it is only appropriate to use a Jonckheere-Terpstra test if your data "passes" six assumptions that are required for a Jonckheere-Terpstra test to give you a valid result.
Before we introduce you to these six assumptions, do not be surprised if, when analysing your own data using SPSS Statistics, one or more of these assumptions is violated (i.e., is not met). This is not uncommon when working with real-world data rather than textbook examples, which often only show you how to carry out a Jonckheere-Terpstra test when everything goes well! However, don’t worry. Even when your data fails certain assumptions, there is often a solution to overcome this. 

1. Check Assumption

2. Run in R

jonckheere.test(x, g, alternative = c("two.sided", "increasing", "decreasing"), nperm=NULL)
Calculation of p-value: There are three methods to calculate the p-values- exact method, permutation test and asymptotic test. ref: https://www.quantics.co.uk/blog/jonckheere-terpstra-test-ordered-differences/
The exact calculation of p-value requires that there be no ties and that the sample size is less than 100. When data are tied and sample size is at most 100 permutation p-value (approximate) is returned.
nperm: number of permutations for the reference distribution (# of sample times to get the approximate p-value). The default is null in which case the permutation p-value is not computed. Recommend that the user set nperm to be 1000 or higher if permutation p-value is desired.
(Permutation test: Permutation tests (also called randomization tests) are non-parametric procedures for determining statistical significance based on rearrangements of the labels of a dataset. ref: https://academic.oup.com/bioinformatics/article/25/12/i161/189924/Fewer-permutations-more-accurate-P-values
Permutation tests take advantage of the fact that if we randomly shuffle the cases and control labels, then the null is true. So we shuffle the cases and control labels and assume that the ensuing distribution approximates the null distribution. ref: http://genomicsclass.github.io/book/pages/permutation_tests.html)
(Permutation is a group of things, which the order of things matters. 'abc' != 'cba')
ref: https://www.rdocumentation.org/packages/clinfun/versions/1.0.14/topics/jonckheere.test
JT statistics:
mu <- (N^2 - (n1^2 + n2^2 + n3^2 + n4^2))/4
s
rcode