-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #285 from Tsumiyama-Isao/jonckheere
Jonckheere
- Loading branch information
Showing
10 changed files
with
298 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
title: "R vs SAS on the Jonckheere-Terpstra test" | ||
--- | ||
|
||
## Comparison | ||
|
||
+----------------------------------------------------------------------------+----------------+------------------+--------------------+------------------------------------------------------------+ | ||
| Analysis | Supported in R | Supported in SAS | Results Match | Notes | | ||
+============================================================================+================+==================+====================+============================================================+ | ||
| Jonckheere-Terpstra test using normal approximation | Yes | Yes | Partial match | The test statistics was 184.5 from both languages. | | ||
| | | | | | | ||
| | | | | Regarding the p-value, R yields 0.002655, and SAS 0.002649 | | ||
+----------------------------------------------------------------------------+----------------+------------------+--------------------+------------------------------------------------------------+ | ||
| Jonckheere-Terpstra test using Monte Carlo approximation for an exact test | Yes | Yes | Partially matching | The resampling number is 10000. | | ||
| | | | | | | ||
| | | | | The test statistics was 184.5 from both languages. | | ||
| | | | | | | ||
| | | | | Regarding the p-value, R yields 0.0023, and SAS 0.0016 | | ||
+----------------------------------------------------------------------------+----------------+------------------+--------------------+------------------------------------------------------------+ | ||
|
||
## Conclusion | ||
### Results from normal approximation | ||
For the test using normal approximation, the results look slightly different. | ||
The reason for this gap may be either of the following. | ||
|
||
- Continuity correction | ||
- Handling of ties in calculating the variance of the test statistics | ||
- Numerical integration for normal distribution | ||
|
||
Regarding continuity correction, the SAS manual mentions that PROC FREQ does not | ||
apply it. The DescTools manual does not mention anything about this point. | ||
|
||
Regarding variance of the test statistics, it depends only on the "cell counts" | ||
in the context of cross tabulation analysis. From the viewpoint of rank tests, | ||
it depends on the frequencies of each tie values. However, since the same test | ||
statistics value was given by both R and SAS, it is less likely that a gap exists | ||
in calculation variance between languages. | ||
|
||
Based on consideration above, the gap looks acceptable. However, it should | ||
kept in mind that R and SAS may take different approaches in continuity | ||
correction. | ||
|
||
### Results from Monte Carlo approximation of an exact test | ||
For the test using simulation, the results also look slightly different. | ||
|
||
As mentioned above, R and SAS may take different approaches in continuity | ||
correction and calculation of variance for the test statistics. In addition, | ||
simulation-based results generally differ between different environments. | ||
|
||
The $95 \%$ CI for the approximate p-value given by SAS was $[0.0008, 0.0024]$. | ||
Since the p-value from R, 0.0023, locates within the CI, this result looks | ||
comparable. | ||
|
||
### Overall conclusion | ||
Overall, the gap between R and SAS is accaptable regarding the Jonckheere-Terpstra | ||
test. However, users should know that R and SAS may take different approaches | ||
for the following aspects: | ||
|
||
- Continuity correction | ||
- Handling of ties in calculating the variance of the test statistics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
title: "Jonckheere-Terpstra test" | ||
--- | ||
|
||
## Available R packages | ||
|
||
As far as I know, the following packages are available: | ||
|
||
- DescTools | ||
- clinfun | ||
- PMCMRplus | ||
- fastJT | ||
|
||
Due to availability in the company, DescTools version 0.99.55 is used to compare the results with SAS. Of these packages DescTools is the most common. | ||
|
||
## Data used | ||
|
||
The data for testing is a sample dataset on a dose-response study. | ||
|
||
![](/images/jonckheere/jonck_bp.png) | ||
|
||
The Group indicates a dose of a drug. The scores for Group represent ordering of dose arms. Then the boxplot implies a declining dose-response relationship. | ||
|
||
## Example Code | ||
|
||
```{r} | ||
library(DescTools) | ||
library(ggplot2) | ||
library(readr) | ||
# | ||
# Constants | ||
k_n_samp <- 10000 | ||
set.seed(4989) | ||
# | ||
# The input dataset is imported. | ||
# | ||
inds <- read_csv("../data/jonck.csv", col_select = c(DOSE, value)) | ||
# | ||
# Analysis | ||
# | ||
jt_norm <- DescTools::JonckheereTerpstraTest( | ||
value ~ DOSE, | ||
alternative = "decreasing", | ||
data = inds | ||
) | ||
jt_resamp <- DescTools::JonckheereTerpstraTest( | ||
value ~ DOSE, | ||
alternative = "decreasing", | ||
data = inds, | ||
nperm = k_n_samp | ||
) | ||
jt_norm | ||
jt_resamp | ||
``` | ||
|
||
|
||
|
||
## Reference | ||
|
||
Signorell A (2024). DescTools: Tools for Descriptive Statistics. R package version 0.99.55, https://github.com/AndriSignorell/DescTools/, https://andrisignorell.github.io/DescTools/. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"","DOSE","value" | ||
"1",0,153 | ||
"2",0,134.2 | ||
"3",0,139 | ||
"4",0,124.2 | ||
"5",0,157.4 | ||
"6",0,128.8 | ||
"7",0,140.1 | ||
"8",0,134.1 | ||
"9",0,129.1 | ||
"10",0,135.3 | ||
"11",1,124.6 | ||
"12",1,129.5 | ||
"13",1,138.9 | ||
"14",1,124 | ||
"15",1,124.6 | ||
"16",1,124 | ||
"17",1,135.4 | ||
"18",1,129 | ||
"19",1,118.5 | ||
"20",1,136.3 | ||
"21",2,140.1 | ||
"22",2,141.3 | ||
"23",2,122.8 | ||
"24",2,143.1 | ||
"25",2,116.4 | ||
"26",2,117.5 | ||
"27",2,136.5 | ||
"28",2,130.9 | ||
"29",2,126.2 | ||
"30",2,139.2 | ||
"31",3,115.7 | ||
"32",3,115.6 | ||
"33",3,118.6 | ||
"34",3,121.2 | ||
"35",3,131.7 | ||
"36",3,109.8 | ||
"37",3,133.8 | ||
"38",3,118.6 | ||
"39",3,132.9 | ||
"40",3,120.6 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.