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

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)

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)

Plotting

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

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

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

Logging

You can look at the logs using cat():

cat(jp$run_summary)


DanChaltiel/nih.joinpoint documentation built on Sept. 9, 2024, 4:23 a.m.