Title: | Parametric Models for Survival Data |
---|---|
Description: | Executes simple parametric models for right-censored survival data. Functionality emulates capabilities in 'Minitab', including fitting right-censored data, assessing fit, plotting survival functions, and summary statistics and probabilities. |
Authors: | Ashley Jacobson [aut, cre], Victor Wilson [aut], Shannon Pileggi [aut] |
Maintainer: | Ashley Jacobson <[email protected]> |
License: | GPL-2 |
Version: | 0.1.0 |
Built: | 2025-03-06 03:18:44 UTC |
Source: | https://github.com/apjacobson/parmsurvfit |
Diekmann et al. (1996) investigated the association between driver characteristics and social status of cars to aggressive driver responses by measuring the time that elapsed between the being blocked and honking the horn. Researchers intentionally blocked 57 motorists at a green light by a Volkswagen Jetta, and recorded the time it took for motorists to show signs of aggression. Signs of aggression included honking their horn or beaming the headlights at the Jetta
aggressive
aggressive
A data frame with 57 rows and 2 variables:
Number of seconds until showing signs of aggression
censoring status indicator variable (0 = censored event time, 1 = complete event time)
https://stats.idre.ucla.edu/other/examples/alda/
Computes Anderson-Darling goodness of fit test statistic given that the data follows a specified parametric distribution.
compute_AD(data, dist, time = "time", censor = "censor")
compute_AD(data, dist, time = "time", censor = "censor")
data |
A dataframe containing a time column and a censor column. |
dist |
A string name for a distribution that has a corresponding density function and a distribution function. Examples include "norm", "lnorm", "exp", "weibull", "logis", "llogis", "gompertz", etc. |
time |
The string name of the time column of the dataframe. Defaults to "time". |
censor |
The string name of the censor column of the dataframe. Defaults to "censor". The censor column must be a numeric indicator variable where complete times correspond to a value of 1 and incomplete times correspond to 0. |
data("rearrest") compute_AD(rearrest, "lnorm", time = "months") compute_AD(rearrest, "weibull", time = "months")
data("rearrest") compute_AD(rearrest, "lnorm", time = "months") compute_AD(rearrest, "weibull", time = "months")
Data on age at first drink of alcohol.
firstdrink
firstdrink
A data frame with 1000 rows and 3 variables:
the age at which the survey respondent had their first drink of alcohol
censoring status indicator variable (0 = censored event time, 1 = complete event time)
a dichotomous variable identifying gender (1 = male, 2 = female)
"National Comorbidity Survey (1990-1992)"
Fits right censored data to a distribution using maximum likelihood estimates.
fit_data(data, dist, time = "time", censor = "censor", by = "")
fit_data(data, dist, time = "time", censor = "censor", by = "")
data |
A dataframe containing a time column and a censor column. |
dist |
A string name for a distribution that has a corresponding density function and a distribution function. Examples include "norm", "lnorm", "exp", "weibull", "logis", "llogis", "gompertz", etc. |
time |
The string name of the time column of the dataframe. Defaults to "time". |
censor |
The string name of the censor column of the dataframe. Defaults to "censor". The censor column must be a numeric indicator variable where complete times correspond to a value of 1 and incomplete times correspond to 0. |
by |
The string name of a grouping variable. If specified, the function returns a list. The list will be in alphabetic order of the values in the by column. Variable can contain logical, string, character, or numeric data. |
data("rearrest") fit_data(rearrest, "lnorm", time = "months") fit_data(rearrest, "weibull", time = "months", by = "personal")
data("rearrest") fit_data(rearrest, "lnorm", time = "months") fit_data(rearrest, "weibull", time = "months", by = "personal")
A dataset that contains the time (in years) that 1000 students (472 males and 528 females) took to graduate (obtain a bachelor’s degree) from college (measured from the time they entered a post-secondary institution, i.e. either a junior college or four year degree granting institution). The Gender column contains the gender of each student (1 = male, 2 = female), and Censor contains the values of the censoring status variable.
graduate
graduate
A data frame with 1000 rows and 3 variables:
years until graduation
censoring status indicator variable (0 = censored event time, 1 = complete event time)
a dichotomous variable identifying gender (1 = male, 2 = female)
National Educational Longitudinal Survey (NELS) from 1988-2002
The dataset contains data for the top 128 grossing actors up to 2017 as listed on Box Office Mojo. The data for the first film appearance and for the first Oscar nomination was taken from IMDb. It should be noted that of the 128 observations in the data set, 48 were right-censored. Right-censored observations represent actors who have not received an Oscar nomination by the year 2017 or actors that died before 2017 without ever receiving an Oscar nomination. For the censor variable "1" represents complete observations, actors who received an Oscar nomination by the year 2017, and "0" represents right-censored observations.
oscars
oscars
A data frame with 128 rows and 12 variables:
observation number
name of actor
actor's total adjusted gross earnings (in millions)
number of movies actor received credit for
actor's average gross earnings per movie
title of actor's movie with the top gross earnings
actor's top gross earnings from a single movie
actor's gender
number of years between actor's first full film appearance and first Oscar nomination
censoring status indicator variable (0 = censored event time, 1 = complete event time)
year of actor's first full film appearance
year of actor's first Oscar nomination
https://github.com/shannonpileggi/SP–Pablo–RProgramming
Executes parametric survival analysis techniques similar to those in 'Minitab'. Fits right censored data to a given parametric distribution, produces summary statistics of the fitted distribution, and plots parametric survival, hazard, and cumulative hazard plots. Produces Anderson-Darling test statistic and probability plots to assess goodness of fit of right censored data to a distribution.
Functions
Datasets
Plots cumulative hazard curve of right censored data given that it follows a specified parametric distribution.
plot_cumhaz(data, dist, time = "time", censor = "censor", by = "")
plot_cumhaz(data, dist, time = "time", censor = "censor", by = "")
data |
A dataframe containing a time column and a censor column. |
dist |
A string name for a distribution that has a corresponding density function and distribution function. Examples include "norm", "lnorm", "exp", "weibull", "logis", "llogis", "gompertz", etc. |
time |
The string name of the time column of the dataframe. Defaults to "time". |
censor |
The string name of the censor column of the dataframe. Defaults to "censor". The censor column must be a numeric indicator variable where complete times correspond to a value of 1 and incomplete times correspond to 0. |
by |
The string name of a grouping variable. If specified, multiple lines will be plotted. Variable can contain logical, string, character, or numeric data. |
data("rearrest") plot_cumhaz(rearrest, "lnorm", time = "months") plot_cumhaz(rearrest, "weibull", time = "months", by = "personal")
data("rearrest") plot_cumhaz(rearrest, "lnorm", time = "months") plot_cumhaz(rearrest, "weibull", time = "months", by = "personal")
Creates histogram of right censored data with the density function of a fitted parametric distribution overlayed.
plot_density(data, dist, time = "time", censor = "censor", by = "")
plot_density(data, dist, time = "time", censor = "censor", by = "")
data |
A dataframe containing a time column and a censor column. |
dist |
A string name for a distribution that has a corresponding density function and distribution function. Examples include "norm", "lnorm", "exp", "weibull", "logis", "llogis", "gompertz", etc. |
time |
The string name of the time column of the dataframe. Defaults to "time". |
censor |
The string name of the censor column of the dataframe. Defaults to "censor". The censor column must be a numeric indicator variable where complete times correspond to a value of 1 and incomplete times correspond to 0. |
by |
The string name of a grouping variable. If specified, the function plots each group individually along with the plot for all groups together. Variable can contain logical, string, character, or numeric data. |
data("rearrest") plot_density(rearrest, "exp", time = "months") plot_density(rearrest, "weibull", time = "months", by = "personal")
data("rearrest") plot_density(rearrest, "exp", time = "months") plot_density(rearrest, "weibull", time = "months", by = "personal")
Plots hazard curve of right censored data given that it follows a specified parametric distribution.
plot_haz(data, dist, time = "time", censor = "censor", by = "")
plot_haz(data, dist, time = "time", censor = "censor", by = "")
data |
A dataframe containing a time column and a censor column. |
dist |
A string name for a distribution that has a corresponding density function and distribution function. Examples include "norm", "lnorm", "exp", "weibull", "logis", "llogis", "gompertz", etc. |
time |
The string name of the time column of the dataframe. Defaults to "time". |
censor |
The string name of the censor column of the dataframe. Defaults to "censor". The censor column must be a numeric indicator variable where complete times correspond to a value of 1 and incomplete times correspond to 0. |
by |
The string name of a grouping variable. If specified, multiple lines will be plotted. Variable can contain logical, string, character, or numeric data. |
data("rearrest") plot_haz(rearrest, "logis", time = "months") plot_haz(rearrest, "weibull", time = "months", by = "personal")
data("rearrest") plot_haz(rearrest, "logis", time = "months") plot_haz(rearrest, "weibull", time = "months", by = "personal")
Creates percent-percent plot of right censored data given that it follows a specified parametric distribution.
plot_ppsurv(data, dist, time = "time", censor = "censor")
plot_ppsurv(data, dist, time = "time", censor = "censor")
data |
A dataframe containing a time column and a censor column. |
dist |
A string name for a distribution that has a corresponding density function and distribution function. Examples include "norm", "lnorm", "exp", "weibull", "logis", "llogis", "gompertz", etc. |
time |
The string name of the time column of the dataframe. Defaults to "time". |
censor |
The string name of the censor column of the dataframe. Defaults to "censor". The censor column must be a numeric indicator variable where complete times correspond to a value of 1 and incomplete times correspond to 0. |
data("rearrest") plot_ppsurv(rearrest, "weibull", time = "months") plot_ppsurv(rearrest, "exp", time = "months")
data("rearrest") plot_ppsurv(rearrest, "weibull", time = "months") plot_ppsurv(rearrest, "exp", time = "months")
Plots survival curve of right censored data given that it follows a specified parametric distribution.
plot_surv(data, dist, time = "time", censor = "censor", by = "")
plot_surv(data, dist, time = "time", censor = "censor", by = "")
data |
A dataframe containing a time column and a censor column. |
dist |
A string name for a distribution that has a corresponding density function and distribution function. Examples include "norm", "lnorm", "exp", "weibull", "logis", "llogis", "gompertz", etc. |
time |
The string name of the time column of the dataframe. Defaults to "time". |
censor |
The string name of the censor column of the dataframe. Defaults to "censor". The censor column must be a numeric indicator variable where complete times correspond to a value of 1 and incomplete times correspond to 0. |
by |
The string name of a grouping variable. If specified, multiple lines will be plotted. Variable can contain logical, string, character, or numeric data. |
data("rearrest") plot_surv(rearrest, "lnorm", time = "months") plot_surv(rearrest, "weibull", time = "months", by = "personal")
data("rearrest") plot_surv(rearrest, "lnorm", time = "months") plot_surv(rearrest, "weibull", time = "months", by = "personal")
Henning and Frueh (1996) followed criminal activities of 194 inmates released from a medium security prison for 36 months. The data from this study can be used to investigate the time until the former inmates were re-arrested. If the former inmate had been re-arrested for a criminal act before 36 months (after initial prison release) had passed, then that former inmate’s event time was complete. If the former inmate had not been re-arrested for a criminal act after 36 months had passed, or had completely dropped out of the study, then that former inmate’s event time was right censored.
rearrest
rearrest
A data frame with 194 rows and 5 variables:
months until re-arrest
censoring status indicator variable (0 = censored event time, 1 = complete event time)
a dichotomous variable identifying former inmates who had a history of person-related crimes (1 = personal), i.e. those with one or more convictions for offenses such as aggravated assault or kidnapping
a dichotomous variable indicating whether former inmates were convicted of a property-related crime (1 = property)
the "centered" age of individual, i.e. the difference between the age of the individual upon release and the average age of all inmates in the study.
https://stats.idre.ucla.edu/other/examples/alda/
Computes probability of survival beyond time t given that the data follows a specified parametric distribution.
surv_prob(data, dist, x, lower.tail = F, time = "time", censor = "censor", by = "")
surv_prob(data, dist, x, lower.tail = F, time = "time", censor = "censor", by = "")
data |
A dataframe containing a time column and a censor column. |
dist |
A string name for a distribution that has a corresponding density function and a distribution function. Examples include "norm", "lnorm", "exp", "weibull", "logis", "llogis", "gompertz", etc. |
x |
A scalar quantity, time at which the probability of survival is computed |
lower.tail |
Logical; if |
time |
The string name of the time column of the dataframe. Defaults to "time". |
censor |
The string name of the censor column of the dataframe. Defaults to "censor". The censor column must be a numeric indicator variable where complete times correspond to a value of 1 and incomplete times correspond to 0. |
by |
The string name of a grouping variable. If specified, the function prints probability for each group individually along with the overall probability. Variable can contain logical, string, character, or numeric data. |
data("rearrest") surv_prob(rearrest, "lnorm", 110, time = "months") surv_prob(rearrest, "weibull", 90, time = "months", lower.tail = TRUE)
data("rearrest") surv_prob(rearrest, "lnorm", 110, time = "months") surv_prob(rearrest, "weibull", 90, time = "months", lower.tail = TRUE)
Estimates various statistics, including median, mean, standard deviation, and percentiles of survival time given that the data follows a specified parametric distribution.
surv_summary(data, dist, time = "time", censor = "censor", by = "")
surv_summary(data, dist, time = "time", censor = "censor", by = "")
data |
A dataframe containing a time column and a censor column. |
dist |
A string name for a distribution that has a corresponding density function and a distribution function. Examples include "norm", "lnorm", "exp", "weibull", "logis", "llogis", "gompertz", etc. |
time |
The string name of the time column of the dataframe. Defaults to "time". |
censor |
The string name of the censor column of the dataframe. Defaults to "censor". The censor column must be a numeric indicator variable where complete times correspond to a value of 1 and incomplete times correspond to 0. |
by |
The string name of a grouping variable. If specified, returns summary statistics for each group. Variable can contain logical, string, character, or numeric data. |
data("rearrest") surv_summary(rearrest, "lnorm", time = "months") surv_summary(rearrest, "weibull", time = "months", by = "personal")
data("rearrest") surv_summary(rearrest, "lnorm", time = "months") surv_summary(rearrest, "weibull", time = "months", by = "personal")