Coder Social home page Coder Social logo

nih.joinpoint's Introduction

{nih.joinpoint}

Package-License Lifecycle: maturing Last Commit CRAN status

Joinpoint Regression Software

The package {nih.joinpoint} is an R interface to easily use National Institute of Health (NIH)'s 'Joinpoint Regression Software' v4.9.0.0.

You will need the Command-Line version (available here). This package will not work on the graphical version (Joinpoint Desktop Software).

Disclaimer:
According to the Terms of Use Agreement from NIH, I am not allowed to share a copy of the software
You need to apply at https://surveillance.cancer.gov/joinpoint/callable/ to get your own copy. This package will NOT work otherwise.
If you want to cite this package in a publication, you will have to cite NIH as well.

The NIH software will come as a Windows installer that needs to be installed. If you cannot or don't want to install it in the default location ("C:/Program Files (x86)/Joinpoint Command/jpCommand.exe"), you should use options(joinpoint_path="my/path/to/jp.exe").

This package comes with no guarantee that it will work for any other version than v4.9.0.0.

Package Installation

As for now, you can only install the development version of this package from GitHub:

devtools::install_github("DanChaltiel/nih.joinpoint")

Lifecycle: experimental

This package is still in its experimental phase, so breaking changes might happen in the future.

Therefore, you should probably use renv in your project so that your old code will run even if you update this package.

When the interface is mature enough, this package will be released on CRAN.

Dataset

This package includes a part of the sample dataset provided with the software:

library(tidyverse)
library(nih.joinpoint)

nih_sample_data %>% group_by(sex) %>% slice(1, 2, n()-1, n()) #first 2 and last 2 of each group
#> # A tibble: 12 x 4
#> # Groups:   sex [3]
#>    sex     year  rate    se
#>    <fct>  <dbl> <dbl> <dbl>
#>  1 Both    1975  59.5 0.622
#>  2 Both    1976  61.4 0.626
#>  3 Both    2008  44.7 0.395
#>  4 Both    2009  42.6 0.382
#>  5 Male    1975  68.4 1.07 
#>  6 Male    1976  71.7 1.08 
#>  7 Male    2008  51.0 0.639
#>  8 Male    2009  48.2 0.614
#>  9 Female  1975  53.6 0.770
#> 10 Female  1976  54.1 0.767
#> 11 Female  2008  39.5 0.500
#> 12 Female  2009  38.1 0.488

ggplot(nih_sample_data, aes(x=year, y=rate, color=sex)) + geom_point() + geom_line()

Parameters

You can use run_options() and export_options() to setup parameters for the joinpoint analysis:

run_opt = run_options(model="ln", max_joinpoints=3, n_cores=3)
export_opt = export_options()

In this example, we ask for a log-linear model, with a maximum of 3 joinpoints to be found, using 3 cores of your processor to parallelize to computing. See ?run_options() for more options.
Export options are left as default as they often mess with the output, change them if you know what you are doing.

Note that the computing time will increase exponentially with max_joinpoints and will decrease with n_cores.

Run

To run the analysis, you then call joinpoint() with arguments: your dataset, the variables you want to consider, and the above-mentioned options.

jp = joinpoint(nih_sample_data, x=year, y=rate, by=sex, se=se,
               run_opts=run_opt, export_opts=export_opt)
names(jp)
#> [1] "aapc"           "apc"            "data_export"    "selected_model"
#> [5] "perm_test"      "report"         "run_summary"

Note that you can leave the options as default, and that the standard error can be left unfilled:

jp2 = joinpoint(nih_sample_data, x=year, y=rate, 
                run_opts=run_opt)

Note though that by default this latter example used a single core to find a max of 4 joinpoints. It took 20 minutes to run on my computer, compared to 4 seconds for the first example.

Plotting

You can use jp_plot() to plot the joinpoint lines along the scatter points:

jp_plot(jp)

The result is a patchwork of ggplots, as the legend must be different for every level.

Note that you can use by_level to filter specific groups:

jp_plot(jp, by_level=c("Male", "Female"))

Logging

You can look at the logs using cat():

cat(jp$run_summary)
#> ----------------------
#> Joinpoint Version Info
#> ----------------------
#> Program Name = C:\PROGRA~2\JOINPO~2\JPCOMM~1.EXE
#> Program Version = V4.9.0.0.1
#> Execution Time = 3 seconds
#> 
#> -------------------
#> Joinpoint Run Files
#> -------------------
#> Run File = session_run.ini
#> Session File = ini/session_ini.ini
#> Data File = session_run.ini
#> Session Options File = ini/run_opt_ini.ini
#> Output Options File = ini/export_opt_ini.ini
#> Joinpoint Output File = session_run.jpo
#> 
#> -------------------------
#> Joinpoint Session Options
#> -------------------------
#>  Model Specifications:
#> 
#>     Independent Variable                             =  year
#>     Shift Data Points by                             =  0.000000
#> 
#>     Dependent Variable:
#>       Calculated or Provided                        =  Provided
#>       Type                                          =  Age-Adjusted Rate
#> 
#>     Type of Change Point Model                       =  Joinpoint
#>     Loglinear Model                                  =  Yes {ln(y) = xb}
#>     Heteroscedastic Errors Model                     =  Standard Error (Provided)
#> 
#>     By Variables:
#>       sex
#> 
#>     Method                                           =  Grid Search
#>     Autocorrelation Errors                           =  Uncorrelated
#> 
#>     Minimum Number of Joinpoints                     =  0
#>     Maximum Number of Joinpoints                     =  3
#> 
#>     Minimum Number Obs Before First Joinpoint        =  2
#>     Minimum Number Obs Between Two Joinpoints        =  2
#>     Number of Grid Points Between Data Points        =  0
#> 
#>     Model Selection Method                           =  Permutation Test
#>     Overall Significance Level of Permutation Tests  =  0.0500
#>     Number of Permutations to Perform for Each Test  =  4499
#>     Seed for Randomly Permuting Data                 =  7160
#>     Joinpoint Significance Level                     =  0.0500
#>     APC Significance Level                           =  0.0500
#>     AAPC Significance Level                          =  0.0500
#>     Jump Value and CR Significance Level             =  Not Applicable
#> 
#>     AAPC Confidence Interval Method                  =  Parametric
#> 
#>     Jump Model / Comparability Ratio                 =  Disable
#>       Jump Location                                  =  Not Applicable
#>       Comparability Ratio                            =  Not Applicable
#>       Variance of CR                                 =  Not Applicable
#> 
#>     Comparison Type                                  =  None
#>       Pairwise Comparison                            =  Not Applicable

nih.joinpoint's People

Contributors

danchaltiel avatar github-actions[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nih.joinpoint's Issues

export_options() broken with version 5.0

export_options() throws error as shown below. Running under Joinpoint 5.0.2, downloaded 2024-03-11.

Thanks!

library(nih.joinpoint)
export_opt = export_options()
#> Error in eval(call("force", as.symbol(paste0("..", x)))): argument "..40" is missing, with no default

Created on 2024-03-12 with reprex v2.1.0

Session info

``` r

R version 4.3.3 (2024-02-29 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22000)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] reprex_2.1.0 nih.joinpoint_0.1.0.9001

loaded via a namespace (and not attached):
[1] utf8_1.2.4 generics_0.1.3 stringi_1.8.3 lattice_0.22-5 hms_1.1.3
[6] digest_0.6.35 magrittr_2.0.3 evaluate_0.23 grid_4.3.3 timechange_0.3.0
[11] fastmap_1.1.1 processx_3.8.3 ps_1.7.6 purrr_1.0.2 fansi_1.0.6
[16] scales_1.3.0 cli_3.6.2 rlang_1.1.3 munsell_0.5.0 withr_3.0.0
[21] yaml_2.3.8 tools_4.3.3 tzdb_0.4.0 dplyr_1.1.4 colorspace_2.1-0
[26] ggplot2_3.5.0 forcats_1.0.0 vctrs_0.6.5 R6_2.5.1 zoo_1.8-12
[31] lifecycle_1.0.4 lubridate_1.9.3 snakecase_0.11.1 stringr_1.5.1 fs_1.6.3
[36] janitor_2.2.0 pkgconfig_2.0.3 callr_3.7.5 clipr_0.8.0 pillar_1.9.0
[41] gtable_0.3.4 glue_1.7.0 xfun_0.42 tibble_3.2.1 tidyselect_1.2.1
[46] rstudioapi_0.15.0 knitr_1.45 htmltools_0.5.7 patchwork_1.2.0 rmarkdown_2.26
[51] readr_2.1.5 compiler_4.3.3

</details>

about the file "session_run.RunSummary.txt" , it looks like that the file was created by the code,but it was never been found, i checked the R code and found it no where but a line where it serves as a inut file, could you please check this? thank you very much, best regards

Describe the bug
Please be as clear and thorough as possible. If possible include the version of JoinPoint you are using.

Reproducible example
Share the code that caused the bug, along with all error and warning messages.
Please also use dput(df) to provide a sample dataset so I can reproduce the error. If your dataset is too large, select a minimal number of columns and rows, or use https://pastebin.com/.

Session info

``` r #Paste here the output of `sessionInfo()` here ```

run_opt creates an empty file and the run_options()'s default has not valid values.

Hi, Dan.
Thank you for your effort and for sharing your code with the community.
I am trying to use your package, but I got an error as a return for the run_options function. Would you mind helping me out?

Some important information for your reference:

  • Not using the graphic interface of the joinpoint software. I installed the command-line version.
  • The version number in the ReadMe.txt file that lies beside the software .exe is Joinpoint 4.9.0.0 Command.
  • I ran the example you provided on the README file as it is.

1st try: run_opt creates an empty file

Running your code as it is, the run_opt object return as an empty character representation. The same thing happens with export_opt.

image

image

2nd try: default has non-valid values

Based on R Help Window, I edited the run_options() function to run the code with default options. The run_opt object is not empty anymore, but it gets not valid values.

run_opt = run_options( model = "ln", data_shift = 0, min_joinpoints = 0, max_joinpoints = 3, pairwise = NULL, pairwise_signif_lvl = 0.05, pairwise_n_permut = 4499, method = "grid", min_obs_end = 2, min_obs_between = 2, n_obs_between = 0, model_selection_method = "permutation test", permutation_signif_lvl = 0.05, n_permutations = 4499, early_stopping = "b-value", run_type = "provided", rates_per_n = 1e+05, dependent_variable_type = "percent", het_error = "standard error", het_error_var_location = NULL, ci_method = "parametric", n_cores = 3, delay_type = "non-delay", autocorr_errors = "number", jump_model = FALSE, comparability_ratio = FALSE, include_std_analysis = FALSE, jump_location = 9999, comparability_ratio_value = 0, cr_variance = 0, joinpoint_alpha_lvl = 0.05, apc_alpha_lvl = 0.05, aapc_alpha_lvl = 0.05, jump_cr_alpha_lvl = 0.05, random_seed = 7160, empirical_quantile_seed = 10000, empirical_quantile_seed_type = "constant", n_resample = 1000, madwd = FALSE, madwd_psi = 0 )

image

image

Could you please give me an advice on exporting jp result as table?

Hi, Dan!

It's me again. Thanks for the constant support you provide for the users of your great package.

This time, I am writing to ask your advice and to ask for more information about the info in name(jp).

Important info about my dataset and joinpoint settings:

  • I am using years as the x variable, ranging from 2000 to 2020.
  • I have 100 clusters which I am using as the "by" argument.

Therefore, as you may imagine, I cannot display all plots at once to assess the result. I want to export it as a table and then only plot significant clusters. Any suggestions? Anything is welcome :)

What I am thinking:

The most important information for me is the significance of the final selected model, the number and years of joinpoint and APC. A plus would be the significance of non-selected models, intercept value and MSE.

Therefore, my current idea is to create a sequence of unique values for the jp (not sure yet how to do this, tho). And then merge the jp$report and jp$apc based on the unique value and export the result as CSV. What would you think about that?

Bonus question!! ๐ŸŽ‰

Could you please recommend materials to understand better the outcomes of jp? For example: in jp$report, what the df mean? or the auto_corr? and the difference between joinpoin_95_lcl and _ucl?

Well, that's all. Thank you very much!!

Best,
C.

How to display different groups in the same chart

I am writing to seek your advice on a problem I am facing with a chart generating program from your source code library. My dataset has multiple groups and I would like to display them all in the same chart.

I have tried merging the data for each group into a single data frame and then using the plotting function in your code to create the chart. However, this approach is not suitable for my data as different groups have different attributes and proportions, and combining them would definitely result in loss of information.

Is there a feasible way to display the data for each group in the same chart while still retaining their unique characteristics? I would like to leverage your tool as it fits my requirements very well.

Thank you for your kind assistance.

Joinpoint function signals no error but produces non-sensical results

Hi Dan,

Thank you for maintaining a package to use NIH Joinpoint Regression Software from R.

We have installed the Command-Line version of Joinpoint for institutional use on our server and updated all the packages listed in imports in https://github.com/DanChaltiel/EDCimport/blob/main/DESCRIPTION .

I have tried to run the R code from the README.md Vignette. The joinpoint function runs for a couple of seconds without producing an error message, but the results from the analysis make no sense, i.e. it finds no joinpoints.

My problem appears similar to closed issues here but these threads did not help me resolve it.

I attach a PDF of the R Console output. Please find the R Code I used below. Your help is highly appreciated.

library(tidyverse)
library(nih.joinpoint)

nih_sample_data %>% group_by(sex) %>% slice(1, 2, n()-1, n())

run_opt = run_options(model="ln", max_joinpoints=3, n_cores=3)
export_opt = export_options()

run_opt
export_opt

reprex::reprex(session_info=TRUE)

jp = joinpoint(nih_sample_data, x=year, y=rate, by=sex, se=se,
               run_opts=run_opt, export_opts=export_opt)

names(jp)

jp_plot(jp) + patchwork::plot_layout(ncol=1)

summary(jp)

str(jp)

test.nih.joinpoint.pdf

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.