# Create a sample data frame
set.seed(123) # for reproducibility
cohort_data <- data.frame(
patient_id = 1:150,
age = sample(20:85, 150, replace = TRUE),
gender = sample(c("F", "M"), 150, replace = TRUE, prob = c(0.6, 0.4))
)
# View the first few rows
head(cohort_data)
#> patient_id age gender
#> 1 1 50 M
#> 2 2 70 F
#> 3 3 33 F
#> 4 4 61 F
#> 5 5 69 F
#> 6 6 62 F
# 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(ClinicoPath)
#> Registered S3 method overwritten by 'future':
#> method from
#> all.equal.connection parallelly
#> Warning: replacing previous import 'dplyr::select' by 'jmvcore::select' when
#> loading 'ClinicoPath'
#> Warning: replacing previous import 'cutpointr::roc' by 'pROC::roc' when loading
#> 'ClinicoPath'
#> Warning: replacing previous import 'cutpointr::auc' by 'pROC::auc' when loading
#> 'ClinicoPath'
#> Warning: replacing previous import 'magrittr::extract' by 'tidyr::extract' when
#> loading 'ClinicoPath'
#> Warning in check_dep_version(): ABI version mismatch:
#> lme4 was built with Matrix ABI version 1
#> Current Matrix ABI version is 0
#> Please re-install lme4 from source or restore original 'Matrix' package
#> Warning: replacing previous import 'jmvcore::select' by 'dplyr::select' when
#> loading 'ClinicoPath'
#> Registered S3 methods overwritten by 'ggpp':
#> method from
#> heightDetails.titleGrob ggplot2
#> widthDetails.titleGrob ggplot2
#> Warning: replacing previous import 'DataExplorer::plot_histogram' by
#> 'grafify::plot_histogram' when loading 'ClinicoPath'
#> Warning: replacing previous import 'ROCR::plot' by 'graphics::plot' when
#> loading 'ClinicoPath'
#> Warning: replacing previous import 'dplyr::select' by 'jmvcore::select' when
#> loading 'ClinicoPath'
#> Warning: replacing previous import 'tibble::view' by 'summarytools::view' when
#> loading 'ClinicoPath'
# Run the age pyramid analysis
results <- agepyramid(
data = cohort_data,
age = "age",
gender = "gender",
female = "F", # Specify that 'F' represents females
bin_width = 10, # Use 10-year age bins
plot_title = "Age Distribution of Study Cohort"
)
# To view the results:
# View the summary table
print(results$pyramidTable)
#>
#> Population Data
#> ────────────────────────────────
#> Population Female Male
#> ────────────────────────────────
#> (80,85] 4 1
#> (70,80] 13 10
#> (60,70] 13 8
#> (50,60] 17 11
#> (40,50] 21 10
#> (30,40] 12 5
#> (20,30] 14 9
#> (10,20] 2 0
#> ────────────────────────────────
# View the plot
print(results$plot)
