knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(dplyr) library(readr) library(knitr) library(LTASR) per_form <- tibble(Variable = c('id', 'gender', 'race', 'dob', 'pybegin', 'dlo', 'vs', 'code', 'rev' ), Description = c('Unique identifier for each person', 'Sex of person ("M" = male / "F" = female)', 'Race of person ("W" = white / "N" = nonwhite)', 'date of birth', 'date to begin follow-up', 'date last observed. Minimum of end of study, date of death, date lost to follow-up', 'an indicator of ‘D’ for those who are deceased. All other values will be treated as alive or censored as of dlo.', 'ICD code of death; missing if person is censored or alive at study end date', 'revision of ICD code (7-10); missing if person is censored or alive at study end date' ), Format = c('', 'character', 'character', 'character', 'character', 'character', 'character', 'character', 'numeric' ) )
It is highly recommended to use R as well as RStudio. RStudio is a separate piece of software used to write and run R code.
It is also highly recommended to use LTASR in conjunction with the tidyverse package. If this has not been installed yet, it will need to be installed for your first use:
install.packages('tidyverse') install.packages('LTASR')
This will only need to be run once, ever. It will install the necessary packages and functions to your computer.
kable(per_form)
Note: R variable names are case sensitive! LTASR assumes all variable names are lower-case. This can be done in any software. Below is an example person file format:
options(knitr.kable.NA = '') person_example %>% kable()
NOTE: Paths in R use forward slashes (/) instead of the standard back slashes (\) used by windows.
The date columns will need to be converted to R date values. This can be done using the as.Date() function. This function requires the user to specify the format of the dates being converted. Below gives a key in how to describe the date format:
The above date columns in the above example person file have the general format of “%m/%d/%Y”.
Below gives example code to read in the person file as well as code to convert the date columns to date values:
library(LTASR) library(tidyverse) person <- read_csv('C:/person.csv') %>% mutate(dob = as.Date(dob, format='%m/%d/%Y'), pybegin = as.Date(pybegin, format='%m/%d/%Y'), dlo = as.Date(dlo, format='%m/%d/%Y'))
The LTASR package comes with an example person file, called person_example, that can be used for testing. For this example, it will be read in, its dates will be converted and it will be saved as 'person':
person <- person_example %>% mutate(dob = as.Date(dob, format='%m/%d/%Y'), pybegin = as.Date(pybegin, format='%m/%d/%Y'), dlo = as.Date(dlo, format='%m/%d/%Y'))
rateobj <- parseRate('C:/UCOD_WashingtonState012018.xml')
Alternatively, the LTASR package comes pre-installed with a rate object for the 119 LTAS minors of the US population from 1960-2022. This can be used in any analyses:
rateobj <- us_119ucod_recent
py_table <- get_table(person, rateobj)
Once the py_table has been created, it can be saved using the write_csv() function. This file contains person day counts (pdays) and outcome counts for each minor (_o1, _o2, …..).
With your stratified data, you can quickly create a table with all SMRs for each minor found in the rate file using the smr_minor() function as below:
smr_minor_table <- smr_minor(py_table, rateobj)
View(smr_minor_table) write_csv(smr_minor_table, "C:/SMR_Minors.csv")
smr_major_table <- smr_major(smr_minor_table, rateobj) View(smr_major_table) write_csv(smr_major_table, "C:/SMR_Majors")
Additionally, any custom grouping can be calculated as well using the smr_custom() function where groupings are defined as a vector of numbers. Below defines groupings for all deaths and all cancers:
minor_grouping <- 1:119 all_causes <- smr_custom(smr_minor_table, minor_grouping) View(all_causes) minor_grouping <- 4:40 all_cancers <- smr_custom(smr_minor_table, minor_grouping) View(all_cancers)
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.