knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(stRoke)
My own toolbox in my small workshop is a mix of some old, worn, well proven tools and some newcomers. This package should be seen as something like that.
I have tried to collect tools and functions from other packages that I use regularly in addition to functions that I have written myself to fill use cases, that I have not been able to find solutions to elsewhere.
Note that, if handled, CPR numbers (social security numbers) should be handled with care as they a considered highly sensitive data.
The CPR number is structured as DDMMYY-XXXX, with the 1st X designating decade of birth, the last X designate binary gender (not biological sex) dependent on even/uneven as female/male, and the last for digits are used in a modulus calculation to verify the validity of the CPR number. Foreigners and unidentified persons are given temporary CPR numbers including letters.
More information can be found on cpr.dk.
Note, that all CPR numbers used in examples are publicly known or non-organic.
The age_calc() function was created as a learning exercise and functions similarly to lubridate::time_length()
.
(age <- age_calc(as.Date("1945-10-23"), as.Date("2018-09-30"))) trunc(age)
Checks validity of CPR numbers according to the modulus 11 rule. Note that due to limitations in the possible available CPR numbers, this rule does not apply to all CPR numbers after 2007.
cpr_check( c( "2310450637", "010190-2000", "010115-4000", "300450-1030", "010150-4021", "010150-4AA1" ) )
Including CPR numbers with letters gives a warning and NA
, as it can not be checked by the modulus 11 function. Should be used with care, see the message.
Extracts date of birth (DOB) from a CPR number. Accounts for the decade of birth. See earlier.
cpr_dob(c( "2310450637", "010190-2000", "010115-4000", "300450-1030", "010150-4021" ))
Gives logical vector of whether female gender from last digit of CPR.
table(cpr_female(stRoke::cprs[, 1]))
Plots odds ratios with 95 % confidence intervals. Performs binary logistic regression for outcome factors with two (2) levels and ordinal logistic regression for outcome factors with more than two levels. Mind relevant assumptions.
Outputs ggplot element for further manipulation.
data(talos) talos[, "mrs_1"] <- factor(talos[, "mrs_1"], ordered = TRUE) ci_plot( ds = talos, x = "rtreat", y = "mrs_1", vars = c("hypertension", "diabetes") )
For learning purposes. Uses anonymized data from the TALOS trial to output a Table 1 (with gtsummary::tbl_summary()
), plotting the so-called grotta-bars based on mRS scores (with rankinPlot::grottaBar()
) and a ordinal logistic regression model plot (with stRoke::ci_plot()
).
generic_stroke(stRoke::talos, "rtreat", "mrs_6", variables = c("hypertension", "diabetes", "civil"))
Used for plotting scores from a multi dimensional patient test.
index_plot(stRoke::score[score$event == "A", ])
The win_prob()
is an implementation of the Tournament Method for calculating the probability of winning as suggested by Zou et al 2022. The authors has included a spreadsheet as supplementary materials. This function aims to mimic that functionality. The function also includes a print()
extension for nice printing.
win_prob( data = stRoke::talos, response = "mrs_6", group = "rtreat", sample.size = TRUE, print.tables = TRUE )
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.