-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_groomecompare_example.R
More file actions
executable file
·134 lines (114 loc) · 4.12 KB
/
test_groomecompare_example.R
File metadata and controls
executable file
·134 lines (114 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env Rscript
# Test Script for groomecompare Example Code
# Date: 2026-01-31
# Purpose: Verify the example from groomecompare.a.yaml works correctly
cat("Testing groomecompare example code...\n\n")
# Load package from source (development mode)
cat("Loading ClinicoPath from source...\n")
tryCatch({
suppressMessages(devtools::load_all(quiet = TRUE))
cat("✅ ClinicoPath package loaded from source\n\n")
}, error = function(e) {
cat("❌ Error loading ClinicoPath package:\n")
cat(" ", e$message, "\n")
cat("\n")
cat(" Troubleshooting:\n")
cat(" 1. Make sure you're in the package root directory:\n")
cat(" cd /Users/serdarbalci/Documents/GitHub/ClinicoPathJamoviModule\n")
cat(" 2. Install devtools if needed: install.packages('devtools')\n")
cat(" 3. Run: devtools::load_all()\n\n")
quit(save = "no", status = 1)
})
cat("Generating sample survival data...\n")
# Example: Compare ypTNM vs RPA staging systems
# Generate sample survival data with two staging systems
set.seed(12345)
n <- 150
survData <- data.frame(
time = rexp(n, 0.05),
event = rbinom(n, 1, 0.6),
ypTNM = factor(sample(c("Stage I", "Stage II", "Stage III", "Stage IV"),
n, replace = TRUE, prob = c(0.3, 0.3, 0.25, 0.15))),
RPA = factor(sample(c("Low Risk", "Intermediate", "High Risk"),
n, replace = TRUE, prob = c(0.4, 0.35, 0.25)))
)
cat("✅ Data generated:\n")
cat(" - Observations:", n, "\n")
cat(" - Events:", sum(survData$event), "\n")
cat(" - ypTNM stages:", nlevels(survData$ypTNM), "\n")
cat(" - RPA groups:", nlevels(survData$RPA), "\n\n")
cat("Running groomecompare (basic example, no bootstrap)...\n")
# Compare staging systems using Groome criteria
tryCatch({
result <- groomecompare(
data = survData,
time = "time",
event = "event",
stage1 = "ypTNM",
stage2 = "RPA",
stage1name = "ypTNM Staging",
stage2name = "RPA Classification",
eventValue = "1",
radarplot = TRUE,
kmplots = TRUE,
detailedmetrics = TRUE,
cindexcompare = TRUE,
bootstrap = FALSE
)
cat("✅ Basic comparison completed successfully\n\n")
# Check that results exist
if (!is.null(result$summary)) {
cat("✅ Summary table populated\n")
}
if (!is.null(result$cindexcompare)) {
cat("✅ C-index comparison populated\n")
}
if (!is.null(result$detailedmetrics)) {
cat("✅ Detailed metrics populated\n")
}
}, error = function(e) {
cat("❌ Error in basic comparison:\n")
cat(" ", e$message, "\n\n")
quit(save = "no", status = 1)
})
cat("\nRunning groomecompare with bootstrap (nboot=50 for speed)...\n")
# With bootstrap validation (smaller nboot for speed)
tryCatch({
result_boot <- groomecompare(
data = survData,
time = "time",
event = "event",
stage1 = "ypTNM",
stage2 = "RPA",
stage1name = "ypTNM Staging",
stage2name = "RPA Classification",
bootstrap = TRUE,
nboot = 50, # Reduced from 100 for faster testing
seed = 12345
)
cat("✅ Bootstrap validation completed successfully\n\n")
# Check that bootstrap results exist
if (!is.null(result_boot$bootstrap)) {
cat("✅ Bootstrap table populated\n")
cat(" - Bootstrap samples: 50\n")
}
}, error = function(e) {
cat("❌ Error in bootstrap validation:\n")
cat(" ", e$message, "\n\n")
quit(save = "no", status = 1)
})
cat("\n" , paste(rep("=", 60), collapse = ""), "\n")
cat("✅ ALL TESTS PASSED!\n")
cat(paste(rep("=", 60), collapse = ""), "\n\n")
cat("Summary:\n")
cat(" ✅ Package loads correctly\n")
cat(" ✅ Data generation works\n")
cat(" ✅ Basic comparison runs without errors\n")
cat(" ✅ Bootstrap validation runs without errors\n")
cat(" ✅ All outputs populated as expected\n\n")
cat("Next steps:\n")
cat(" 1. Test in jamovi UI\n")
cat(" 2. Test with real clinical data\n")
cat(" 3. Verify all plots render correctly\n")
cat(" 4. Check notice messages display properly\n\n")
cat("Test completed successfully!\n")