Skip to contents
# Create a sample data frame for a cancer trial
set.seed(123)
n_patients <- 200
cancer_trial <- data.frame(
  Age = rnorm(n_patients, mean = 65, sd = 10),
  Gender = factor(sample(c("Male", "Female"), n_patients, replace = TRUE)),
  Tumor_Grade = factor(sample(c("I", "II", "III"), n_patients, replace = TRUE, 
                              prob = c(0.3, 0.5, 0.2)), ordered = TRUE),
  Biomarker_X = rnorm(n_patients, mean = 100, sd = 25),
  Treatment_Group = factor(sample(c("Therapy", "Placebo"), n_patients, replace = TRUE))
)

# Ensure Age is numeric and integer
cancer_trial$Age <- as.integer(cancer_trial$Age)

head(cancer_trial)
##   Age Gender Tumor_Grade Biomarker_X Treatment_Group
## 1  59   Male          II    98.16110         Therapy
## 2  62   Male           I    70.78371         Placebo
## 3  80   Male          II    84.13129         Placebo
## 4  65   Male          II    99.27896         Therapy
## 5  66   Male          II   116.76740         Therapy
## 6  82   Male         III    58.73634         Therapy
# This code simulates how the jamovi module would be called in an R environment.
# You would need the ClinicoPathDescriptives package installed.

# Load the library
library(ClinicoPathDescriptives)
## Registered S3 method overwritten by 'future':
##   method               from      
##   all.equal.connection parallelly
## Warning: replacing previous import 'dplyr::select' by 'jmvcore::select' when
## loading 'ClinicoPathDescriptives'

# Run the crosstable analysis with NEJM style
results <- crosstable(
    data = cancer_trial,
    vars = c("Age", "Gender", "Tumor_Grade", "Biomarker_X"),
    group = "Treatment_Group",
    sty = "nejm" # Specify the New England Journal of Medicine style
)
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |......................................................................| 100%
                                                                                          
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |......................................................................| 100%
                                                                                          
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |......................................................................| 100%

# The result is an HTML table, which would render directly in jamovi.
# In R, you would access it like this:
# results$tablestyle4
htmltools::HTML(results$tablestyle4$content)
Cross Table for Dependent treatment_group
N Placebo Therapy Test Statistic
(N=93) (N=107)
Age 200 58.0 64.0 71.0 58.0 64.0 70.0 F1,198=0.01, P=0.923
Gender : Male 200 0.5  42/93 0.5   51/107 Χ2
1
=0.13, P=0.722
Tumor_Grade 200 Χ2
2
=0.88, P=0.652
        I 0.3  29/93 0.3   27/107
        II 0.5  45/93 0.5   56/107
        III 0.2  19/93 0.2   24/107
Biomarker_X 200 91.7 104.1 118.2 83.9 98.2 114.9 F1,198=3.22, P=0.073
N is the number of non-missing value. 1Kruskal-Wallis. 2Pearson. 3Wilcoxon.