| Title: | "Risk Model Regression and Analysis with Complex Non-Linear Models" |
|---|---|
| Description: | Performs risk analysis using general non-linear models. Risk models can be the sum or product of terms. Each term is the product of exponential/linear functions of covariates. Additionally sub-terms can be defined as a sum of exponential, linear threshold, and step functions. Cox Proportional hazards <https://en.wikipedia.org/wiki/Proportional_hazards_model>, Poisson <https://en.wikipedia.org/wiki/Poisson_regression>, and Fine-Gray competing risks <https://www.publichealth.columbia.edu/research/population-health-methods/competing-risk-analysis> regression are supported. This work was sponsored by NASA Grants 80NSSC19M0161 and 80NSSC23M0129 through a subcontract from the National Council on Radiation Protection and Measurements (NCRP). The computing for this project was performed on the Beocat Research Cluster at Kansas State University, which is funded in part by NSF grants CNS-1006860, EPS-1006860, EPS-0919443, ACI-1440548, CHE-1726332, and NIH P20GM113109. |
| Authors: | Eric King-Giunta [aut, cre] (ORCID: <https://orcid.org/0000-0002-1577-766X>), Amir Bahadori [ctb] (ORCID: <https://orcid.org/0000-0002-4589-105X>), Dan Andresen [ctb] (ORCID: <https://orcid.org/0000-0003-2345-6695>), Linda Walsh [ctb] (ORCID: <https://orcid.org/0000-0001-7399-9191>), Benjamin French [ctb] (ORCID: <https://orcid.org/0000-0001-9265-5378>), Lawrence Dauer [ctb] (ORCID: <https://orcid.org/0000-0002-5629-8462>), John Boice Jr [ctb] (ORCID: <https://orcid.org/0000-0002-8755-1299>), Kansas State University [cph], NASA [fnd], NCRP [fnd], NRC [fnd] |
| Maintainer: | Eric King-Giunta <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.6.4 |
| Built: | 2026-10-15 23:21:54 UTC |
| Source: | https://github.com/ericgiunta/colossus |
CaseControlRun uses a formula, data.table, and list of controls to prepare and
run a Colossus matched case-control regression function
CaseControlRun( model, df, a_n = list(0), keep_constant = 0, control = list(), conditional_threshold = 50, gradient_control = list(), single = FALSE, observed_info = FALSE, cons_mat = as.matrix(0), cons_vec = 0, norm = "null", ... )CaseControlRun( model, df, a_n = list(0), keep_constant = 0, control = list(), conditional_threshold = 50, gradient_control = list(), single = FALSE, observed_info = FALSE, cons_mat = as.matrix(0), cons_vec = 0, norm = "null", ... )
model |
either a formula written for the get_form function, or the model result from the get_form function. |
df |
a data.table containing the columns of interest |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
keep_constant |
binary values to denote which parameters to change |
control |
list of parameters controlling the convergence, see the control options vignette for details |
conditional_threshold |
threshold above which unconditional logistic regression is used to calculate likelihoods in a matched group |
gradient_control |
a list of control options for the gradient descent algorithm. If any value is given, a gradient descent algorithm is used instead of Newton-Raphson. See the control options vignette for details |
single |
a boolean to denote that only the log-likelihood should be calculated and returned, no derivatives or iterations |
observed_info |
a boolean to denote that the observed information matrix should be used to calculate the standard error for parameters, not the expected information matrix |
cons_mat |
Matrix containing coefficients for a system of linear constraints, formatted as matrix |
cons_vec |
Vector containing constants for a system of linear constraints, formatted as vector |
norm |
methods used to normalize the covariates. Default is 'null' for no normalization. Other options include 'max' to normalize by the absolute maximum and 'mean' to normalize by the mean |
... |
can include the named entries for the control list parameter |
returns a class fully describing the model and the regression results
library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1), e = c(0, 0, 1, 0, 0, 0, 1) ) control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- CaseCon_Strata(Cancer_Status, e) ~ loglinear(a, b, c, 0) + plinear(d, 0) + multiplicative() res <- CaseControlRun(formula, df, a_n = list(c(1.1, -0.1, 0.2, 0.5), c(1.6, -0.12, 0.3, 0.4)), control = control )library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1), e = c(0, 0, 1, 0, 0, 0, 1) ) control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- CaseCon_Strata(Cancer_Status, e) ~ loglinear(a, b, c, 0) + plinear(d, 0) + multiplicative() res <- CaseControlRun(formula, df, a_n = list(c(1.1, -0.1, 0.2, 0.5), c(1.6, -0.12, 0.3, 0.4)), control = control )
CoxRun uses a formula, data.table, and list of controls to prepare and
run a Colossus cox or fine-gray regression function
CoxRun( model, df, a_n = list(0), keep_constant = 0, control = list(), gradient_control = list(), single = FALSE, observed_info = FALSE, cons_mat = as.matrix(0), cons_vec = 0, norm = "null", ... )CoxRun( model, df, a_n = list(0), keep_constant = 0, control = list(), gradient_control = list(), single = FALSE, observed_info = FALSE, cons_mat = as.matrix(0), cons_vec = 0, norm = "null", ... )
model |
either a formula written for the get_form function, or the model result from the get_form function. |
df |
a data.table containing the columns of interest |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
keep_constant |
binary values to denote which parameters to change |
control |
list of parameters controlling the convergence, see the control options vignette for details |
gradient_control |
a list of control options for the gradient descent algorithm. If any value is given, a gradient descent algorithm is used instead of Newton-Raphson. See the control options vignette for details |
single |
a boolean to denote that only the log-likelihood should be calculated and returned, no derivatives or iterations |
observed_info |
a boolean to denote that the observed information matrix should be used to calculate the standard error for parameters, not the expected information matrix |
cons_mat |
Matrix containing coefficients for a system of linear constraints, formatted as matrix |
cons_vec |
Vector containing constants for a system of linear constraints, formatted as vector |
norm |
methods used to normalize the covariates. Default is 'null' for no normalization. Other options include 'max' to normalize by the absolute maximum and 'mean' to normalize by the mean |
... |
can include the named entries for the control list parameter |
returns a class fully describing the model and the regression results
Other Cox Wrapper Functions:
CoxRunMulti()
library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1), e = c(0, 0, 1, 0, 0, 0, 1) ) control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- Cox(Starting_Age, Ending_Age, Cancer_Status) ~ loglinear(a, b, c, 0) + plinear(d, 0) + multiplicative() res <- CoxRun(formula, df, a_n = list(c(1.1, -0.1, 0.2, 0.5), c(1.6, -0.12, 0.3, 0.4)), control = control )library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1), e = c(0, 0, 1, 0, 0, 0, 1) ) control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- Cox(Starting_Age, Ending_Age, Cancer_Status) ~ loglinear(a, b, c, 0) + plinear(d, 0) + multiplicative() res <- CoxRun(formula, df, a_n = list(c(1.1, -0.1, 0.2, 0.5), c(1.6, -0.12, 0.3, 0.4)), control = control )
CoxRunMulti uses a formula, data.table, and list of controls to prepare and
run a Colossus cox or fine-gray regression function
CoxRunMulti( model, df, a_n = list(0), keep_constant = 0, realization_columns = matrix(c("temp00", "temp01", "temp10", "temp11"), nrow = 2), realization_index = c("temp0", "temp1"), control = list(), gradient_control = list(), single = FALSE, observed_info = FALSE, fma = TRUE, mcml = FALSE, cons_mat = as.matrix(0), cons_vec = 0, ... )CoxRunMulti( model, df, a_n = list(0), keep_constant = 0, realization_columns = matrix(c("temp00", "temp01", "temp10", "temp11"), nrow = 2), realization_index = c("temp0", "temp1"), control = list(), gradient_control = list(), single = FALSE, observed_info = FALSE, fma = TRUE, mcml = FALSE, cons_mat = as.matrix(0), cons_vec = 0, ... )
model |
either a formula written for the get_form function, or the model result from the get_form function. |
df |
a data.table containing the columns of interest |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
keep_constant |
binary values to denote which parameters to change |
realization_columns |
used for multi-realization regressions. Matrix of column names with rows for each column with realizations, columns for each realization |
realization_index |
used for multi-realization regressions. Vector of column names, one for each column with realizations. Each name should be used in the "names" variable in the equation definition |
control |
list of parameters controlling the convergence, see the control options vignette for details |
gradient_control |
a list of control options for the gradient descent algorithm. If any value is given, a gradient descent algorithm is used instead of Newton-Raphson. See the control options vignette for details |
single |
a boolean to denote that only the log-likelihood should be calculated and returned, no derivatives or iterations |
observed_info |
a boolean to denote that the observed information matrix should be used to calculate the standard error for parameters, not the expected information matrix |
fma |
a boolean to denote that the Frequentist Model Averaging method should be used |
mcml |
a boolean to denote that the Monte Carlo Maximum Likelihood method should be used |
cons_mat |
Matrix containing coefficients for a system of linear constraints, formatted as matrix |
cons_vec |
Vector containing constants for a system of linear constraints, formatted as vector |
... |
can include the named entries for the control list parameter |
returns a class fully describing the model and the regression results
Other Cox Wrapper Functions:
CoxRun()
library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), t0 = c(18, 20, 18, 19, 21, 20, 18), t1 = c(30, 45, 57, 47, 36, 60, 55), lung = c(0, 0, 1, 0, 1, 0, 0), dose = c(0, 1, 1, 0, 1, 0, 1) ) set.seed(3742) df$rand <- floor(runif(nrow(df), min = 0, max = 5)) df$rand0 <- floor(runif(nrow(df), min = 0, max = 5)) df$rand1 <- floor(runif(nrow(df), min = 0, max = 5)) df$rand2 <- floor(runif(nrow(df), min = 0, max = 5)) realization_columns <- matrix(c("rand0", "rand1", "rand2"), nrow = 1) realization_index <- c("rand") control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- Cox(t0, t1, lung) ~ loglinear(dose, rand, 0) + multiplicative() res <- CoxRunMulti(formula, df, control = control, realization_columns = realization_columns, realization_index = realization_index )library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), t0 = c(18, 20, 18, 19, 21, 20, 18), t1 = c(30, 45, 57, 47, 36, 60, 55), lung = c(0, 0, 1, 0, 1, 0, 0), dose = c(0, 1, 1, 0, 1, 0, 1) ) set.seed(3742) df$rand <- floor(runif(nrow(df), min = 0, max = 5)) df$rand0 <- floor(runif(nrow(df), min = 0, max = 5)) df$rand1 <- floor(runif(nrow(df), min = 0, max = 5)) df$rand2 <- floor(runif(nrow(df), min = 0, max = 5)) realization_columns <- matrix(c("rand0", "rand1", "rand2"), nrow = 1) realization_index <- c("rand") control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- Cox(t0, t1, lung) ~ loglinear(dose, rand, 0) + multiplicative() res <- CoxRunMulti(formula, df, control = control, realization_columns = realization_columns, realization_index = realization_index )
Date_Shift generates a new dataframe with a column containing time difference in a given unit
Date_Shift(df, dcol0, dcol1, col_name, units = "days")Date_Shift(df, dcol0, dcol1, col_name, units = "days")
df |
a data.table containing the columns of interest |
dcol0 |
list of starting month, day, and year |
dcol1 |
list of ending month, day, and year |
col_name |
vector of new column names |
units |
time unit to use |
returns the updated dataframe
Other Data Cleaning Functions:
Joint_Multiple_Events(),
Replace_Missing(),
Time_Since(),
factorize(),
gen_time_dep()
library(data.table) m0 <- c(1, 1, 2, 2) m1 <- c(2, 2, 3, 3) d0 <- c(1, 2, 3, 4) d1 <- c(6, 7, 8, 9) y0 <- c(1990, 1991, 1997, 1998) y1 <- c(2001, 2003, 2005, 2006) df <- data.table(m0 = m0, m1 = m1, d0 = d0, d1 = d1, y0 = y0, y1 = y1) df <- Date_Shift(df, c("m0", "d0", "y0"), c("m1", "d1", "y1"), "date_since")library(data.table) m0 <- c(1, 1, 2, 2) m1 <- c(2, 2, 3, 3) d0 <- c(1, 2, 3, 4) d1 <- c(6, 7, 8, 9) y0 <- c(1990, 1991, 1997, 1998) y1 <- c(2001, 2003, 2005, 2006) df <- data.table(m0 = m0, m1 = m1, d0 = d0, d1 = d1, y0 = y0, y1 = y1) df <- Date_Shift(df, c("m0", "d0", "y0"), c("m1", "d1", "y1"), "date_since")
Event_Count_Gen generates event-count tables
Event_Count_Gen(table, categ = list(), events = list())Event_Count_Gen(table, categ = list(), events = list())
table |
dataframe with every category/event column needed |
categ |
list with category columns and methods, methods can be either strings or lists of boundaries |
events |
list of columns to summarize, supports counts and means and renaming the summary column |
returns a grouped table and a list of category boundaries used
Other Table Generation Functions:
Event_Time_Gen()
library(data.table) a <- c(0, 1, 2, 3, 4, 5, 6) b <- c(1, 2, 3, 4, 5, 6, 7) c <- c(0, 1, 0, 0, 0, 1, 0) table <- data.table( a = a, b = b, c = c ) categ <- list( a = "0/3/5]7", b = list( lower = c(-1, 3, 6), upper = c(3, 6, 10), name = c("low", "medium", "high") ) ) event <- list( c = "count AS cases", a = "mean", b = "mean" ) e <- Event_Count_Gen(table, categ, event)library(data.table) a <- c(0, 1, 2, 3, 4, 5, 6) b <- c(1, 2, 3, 4, 5, 6, 7) c <- c(0, 1, 0, 0, 0, 1, 0) table <- data.table( a = a, b = b, c = c ) categ <- list( a = "0/3/5]7", b = list( lower = c(-1, 3, 6), upper = c(3, 6, 10), name = c("low", "medium", "high") ) ) event <- list( c = "count AS cases", a = "mean", b = "mean" ) e <- Event_Count_Gen(table, categ, event)
Event_Time_Gen generates event-time tables
Event_Time_Gen( table, pyr = list(), time_scale = list(), categ = list(), summaries = list(), events = NULL, fcount = FALSE, lcount = FALSE, studyid = "studyID", verbose = FALSE )Event_Time_Gen( table, pyr = list(), time_scale = list(), categ = list(), summaries = list(), events = NULL, fcount = FALSE, lcount = FALSE, studyid = "studyID", verbose = FALSE )
table |
dataframe with every category/event column needed |
pyr |
list with entry and exit lists, containing day/month/year columns in the table |
time_scale |
list with the time scale information, either a calendar category or an age category |
categ |
list with category columns and methods, methods can be either strings or lists of boundaries |
summaries |
list of columns to summarize, supports counts, means, and weighted means by person-year and renaming the summary column |
events |
list of events or interests, checks if events are within each time interval |
fcount |
boolean if the |
lcount |
boolean if the |
studyid |
id used to determine distinct subjects used for first and last at risk intervals. |
verbose |
boolean if updates should be printed to the console. |
returns a grouped table and a list of category boundaries used
Other Table Generation Functions:
Event_Count_Gen()
library(data.table) a <- c(0, 1, 2, 3, 4, 5, 6) b <- c(1, 2, 3, 4, 5, 6, 7) c <- c(0, 1, 0, 0, 0, 1, 0) d <- c(1, 2, 3, 4, 5, 6, 7) e <- c(2, 3, 4, 5, 6, 7, 8) f <- c( 1900, 1900, 1900, 1900, 1900, 1900, 1900 ) g <- c(1, 2, 3, 4, 5, 6, 7) h <- c(2, 3, 4, 5, 6, 7, 8) i <- c( 1901, 1902, 1903, 1904, 1905, 1906, 1907 ) table <- data.table( a = a, b = b, c = c, d = d, e = e, f = f, g = g, h = h, i = i ) categ <- list( a = "-1/3/5]7" ) calendar_categ <- list( type = "calendar", day = c(1, 1, 1), month = c(1, 1, 1), year = c(1901, 1904, 1908) ) time_scale <- list(time = calendar_categ) summary <- list( c = "count AS cases" ) events <- list("c") pyr <- list( entry = list(year = "f"), exit = list(year = "i"), unit = "years" ) e <- Event_Time_Gen(table, pyr, time_scale, categ, summary, events)library(data.table) a <- c(0, 1, 2, 3, 4, 5, 6) b <- c(1, 2, 3, 4, 5, 6, 7) c <- c(0, 1, 0, 0, 0, 1, 0) d <- c(1, 2, 3, 4, 5, 6, 7) e <- c(2, 3, 4, 5, 6, 7, 8) f <- c( 1900, 1900, 1900, 1900, 1900, 1900, 1900 ) g <- c(1, 2, 3, 4, 5, 6, 7) h <- c(2, 3, 4, 5, 6, 7, 8) i <- c( 1901, 1902, 1903, 1904, 1905, 1906, 1907 ) table <- data.table( a = a, b = b, c = c, d = d, e = e, f = f, g = g, h = h, i = i ) categ <- list( a = "-1/3/5]7" ) calendar_categ <- list( type = "calendar", day = c(1, 1, 1), month = c(1, 1, 1), year = c(1901, 1904, 1908) ) time_scale <- list(time = calendar_categ) summary <- list( c = "count AS cases" ) events <- list("c") pyr <- list( entry = list(year = "f"), exit = list(year = "i"), unit = "years" ) e <- Event_Time_Gen(table, pyr, time_scale, categ, summary, events)
EventAssignment Generic background/excess event calculation function for
standard poisson regressions and likelihood based confidence interval results.
EventAssignment(x, df, ...)EventAssignment(x, df, ...)
x |
result object from a regression, class poisres |
df |
a data.table containing the columns of interest |
... |
extended for other necessary parameters |
returns matrices of events assigned to background and excess
Other Poisson Event Assignment:
EventAssignment.poisres(),
EventAssignment.poisresbound()
EventAssignment.poisres uses user provided data, person-year/event columns, vectors specifying the model,
and options to calculate background and excess events for a solved Poisson regression
## S3 method for class 'poisres' EventAssignment( x, df, assign_control = list(), control = list(), a_n = NULL, ... )## S3 method for class 'poisres' EventAssignment( x, df, assign_control = list(), control = list(), a_n = NULL, ... )
x |
result object from a regression, class poisres |
df |
a data.table containing the columns of interest |
assign_control |
control list for bounds calculated |
control |
list of parameters controlling the convergence, see the control options vignette for details |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
... |
can include the named entries for the assign_control list parameter |
returns matrices of events assigned to background and excess
Other Poisson Event Assignment:
EventAssignment(),
EventAssignment.poisresbound()
EventAssignment.poisresbound uses user provided data, person-year/event columns, vectors specifying the model,
and options to calculate background and excess events for a solved Poisson regression
## S3 method for class 'poisresbound' EventAssignment( x, df, assign_control = list(), control = list(), a_n = NULL, ... )## S3 method for class 'poisresbound' EventAssignment( x, df, assign_control = list(), control = list(), a_n = NULL, ... )
x |
result object from a regression, class poisres |
df |
a data.table containing the columns of interest |
assign_control |
control list for bounds calculated |
control |
list of parameters controlling the convergence, see the control options vignette for details |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
... |
can include the named entries for the assign_control list parameter |
returns matrices of events assigned to background and excess
Other Poisson Event Assignment:
EventAssignment(),
EventAssignment.poisres()
factorize uses user provided list of columns to define new parameter for each unique value and update the data.table.
Not for interaction terms
factorize(df, col_list, verbose = 0)factorize(df, col_list, verbose = 0)
df |
a data.table containing the columns of interest |
col_list |
an array of column names that should have factor terms defined |
verbose |
integer valued 0-4 controlling what information is printed to the terminal. Each level includes the lower levels. 0: silent, 1: errors printed, 2: warnings printed, 3: notes printed, 4: debug information printed. Errors are situations that stop the regression, warnings are situations that assume default values that the user might not have intended, notes provide information on regression progress, and debug prints out C++ progress and intermediate results. The default level is 2 and True/False is converted to 3/0. |
returns a list with two named fields. df for the updated dataframe, and cols for the new column names
Other Data Cleaning Functions:
Date_Shift(),
Joint_Multiple_Events(),
Replace_Missing(),
Time_Since(),
gen_time_dep()
library(data.table) a <- c(0, 1, 2, 3, 4, 5, 6) b <- c(1, 2, 3, 4, 5, 6, 7) c <- c(0, 1, 2, 1, 0, 1, 0) df <- data.table(a = a, b = b, c = c) col_list <- c("c") val <- factorize(df, col_list) df <- val$df new_col <- val$colslibrary(data.table) a <- c(0, 1, 2, 3, 4, 5, 6) b <- c(1, 2, 3, 4, 5, 6, 7) c <- c(0, 1, 2, 1, 0, 1, 0) df <- data.table(a = a, b = b, c = c) col_list <- c("c") val <- factorize(df, col_list) df <- val$df new_col <- val$cols
gen_time_dep generates a new dataframe with time dependent covariates by applying a grid in time
gen_time_dep( df, time1, time2, event0, iscox, dt, new_names, dep_cols, func_form, fname, tform, nthreads = as.numeric(detectCores()) )gen_time_dep( df, time1, time2, event0, iscox, dt, new_names, dep_cols, func_form, fname, tform, nthreads = as.numeric(detectCores()) )
df |
a data.table containing the columns of interest |
time1 |
column used for time period starts |
time2 |
column used for time period end |
event0 |
column used for event status |
iscox |
boolean if rows not at event times should not be kept, rows are removed if true. a Cox proportional hazards model does not use rows with intervals not containing event times |
dt |
spacing in time for new rows |
new_names |
list of new names to use instead of default, default used if entry is ”" |
dep_cols |
columns that are not needed in the new dataframe |
func_form |
vector of functions to apply to each time-dependent covariate. Of the form func(df, time) returning a vector of the new column value |
fname |
filename used for new dataframe |
tform |
list of string function identifiers, used for linear/step |
nthreads |
number of threads to use, do not use more threads than available on your machine |
returns the updated dataframe
Other Data Cleaning Functions:
Date_Shift(),
Joint_Multiple_Events(),
Replace_Missing(),
Time_Since(),
factorize()
library(data.table) # Adapted from the tests a <- c(20, 20, 5, 10, 15) b <- c(1, 2, 1, 1, 2) c <- c(0, 0, 1, 1, 1) df <- data.table(a = a, b = b, c = c) time1 <- "%trunc%" time2 <- "a" event <- "c" grt_f <- function(df, time_col) { return((df[, "b"] * df[, get(time_col)])[[1]]) } func_form <- "lin" df_new <- gen_time_dep( df, time1, time2, event, TRUE, 0.01, c("grt"), NULL, c(grt_f), paste0(tempfile(), "test_new.csv"), func_form, 1 )library(data.table) # Adapted from the tests a <- c(20, 20, 5, 10, 15) b <- c(1, 2, 1, 1, 2) c <- c(0, 0, 1, 1, 1) df <- data.table(a = a, b = b, c = c) time1 <- "%trunc%" time2 <- "a" event <- "c" grt_f <- function(df, time_col) { return((df[, "b"] * df[, get(time_col)])[[1]]) } func_form <- "lin" df_new <- gen_time_dep( df, time1, time2, event, TRUE, 0.01, c("grt"), NULL, c(grt_f), paste0(tempfile(), "test_new.csv"), func_form, 1 )
get_form uses a formula and data.table, to fully describe the model
for a Colossus regression function.
get_form(formula, df, nthreads = as.numeric(detectCores())/2)get_form(formula, df, nthreads = as.numeric(detectCores())/2)
formula |
a formula object, written in Colossus notation. See the unified equation expression vignette vignette for details. |
df |
a data.table containing the columns of interest |
nthreads |
number of threads to use, do not use more threads than available on your machine |
returns a class fully describing the model and the updated data
Other Formula Interpretation:
get_form_joint()
library(data.table) ## basic example code reproduced from the starting-description vignette df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1), e = c(0, 0, 1, 0, 0, 0, 1) ) formula <- Cox(Starting_Age, Ending_Age, Cancer_Status) ~ loglinear(a, b, c, 0) + plinear(d, 0) + multiplicative() model <- get_form(formula, df, 1)library(data.table) ## basic example code reproduced from the starting-description vignette df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1), e = c(0, 0, 1, 0, 0, 0, 1) ) formula <- Cox(Starting_Age, Ending_Age, Cancer_Status) ~ loglinear(a, b, c, 0) + plinear(d, 0) + multiplicative() model <- get_form(formula, df, 1)
get_form_joint uses two event formula, a shared formula,
and data.table, to fully describe the model for a joint Poisson model.
get_form_joint(formula_list, df, nthreads = as.numeric(detectCores())/2)get_form_joint(formula_list, df, nthreads = as.numeric(detectCores())/2)
formula_list |
a list of formula objects, each written in Colossus notation. See the unified equation expression vignette vignette for details. Each formula should include the elements specific to the specified event column. The list can include an entry named "shared" to denote shared terms. The person-year and strata columns should be the same. |
df |
a data.table containing the columns of interest |
nthreads |
number of threads to use, do not use more threads than available on your machine |
returns a class fully describing the model and the updated data
Other Formula Interpretation:
get_form()
Joint_Multiple_Events generates input for a regression with multiple non-independent events and models
Joint_Multiple_Events( df, events, name_list, term_n_list = list(), tform_list = list(), keep_constant_list = list(), a_n_list = list() )Joint_Multiple_Events( df, events, name_list, term_n_list = list(), tform_list = list(), keep_constant_list = list(), a_n_list = list() )
df |
a data.table containing the columns of interest |
events |
vector of event column names |
name_list |
list of vectors for columns for event specific or shared model elements, required |
term_n_list |
list of vectors for term numbers for event specific or shared model elements, defaults to term 0 |
tform_list |
list of vectors for subterm types for event specific or shared model elements, defaults to loglinear |
keep_constant_list |
list of vectors for constant elements for event specific or shared model elements, defaults to free (0) |
a_n_list |
list of vectors for parameter values for event specific or shared model elements, defaults to term 0 |
returns the updated dataframe and model inputs
Other Data Cleaning Functions:
Date_Shift(),
Replace_Missing(),
Time_Since(),
factorize(),
gen_time_dep()
library(data.table) a <- c(0, 0, 0, 1, 1, 1) b <- c(1, 1, 1, 2, 2, 2) c <- c(0, 1, 2, 2, 1, 0) d <- c(1, 1, 0, 0, 1, 1) e <- c(0, 1, 1, 1, 0, 0) df <- data.table(t0 = a, t1 = b, e0 = c, e1 = d, fac = e) time1 <- "t0" time2 <- "t1" df$pyr <- df$t1 - df$t0 pyr <- "pyr" events <- c("e0", "e1") names_e0 <- c("fac") names_e1 <- c("fac") names_shared <- c("t0", "t0") term_n_e0 <- 0 term_n_e1 <- 0 term_n_shared <- c(0, 0) tform_e0 <- "loglin" tform_e1 <- "loglin" tform_shared <- c("quad_slope", "loglin_top") keep_constant_e0 <- 0 keep_constant_e1 <- 0 keep_constant_shared <- c(0, 0) a_n_e0 <- c(-0.1) a_n_e1 <- c(0.1) a_n_shared <- c(0.001, -0.02) name_list <- list(shared = names_shared, e0 = names_e0, e1 = names_e1) term_n_list <- list(shared = term_n_shared, e0 = term_n_e0, e1 = term_n_e1) tform_list <- list(shared = tform_shared, e0 = tform_e0, e1 = tform_e1) keep_constant_list <- list( shared = keep_constant_shared, e0 = keep_constant_e0, e1 = keep_constant_e1 ) a_n_list <- list(shared = a_n_shared, e0 = a_n_e0, e1 = a_n_e1) val <- Joint_Multiple_Events( df, events, name_list, term_n_list, tform_list, keep_constant_list, a_n_list )library(data.table) a <- c(0, 0, 0, 1, 1, 1) b <- c(1, 1, 1, 2, 2, 2) c <- c(0, 1, 2, 2, 1, 0) d <- c(1, 1, 0, 0, 1, 1) e <- c(0, 1, 1, 1, 0, 0) df <- data.table(t0 = a, t1 = b, e0 = c, e1 = d, fac = e) time1 <- "t0" time2 <- "t1" df$pyr <- df$t1 - df$t0 pyr <- "pyr" events <- c("e0", "e1") names_e0 <- c("fac") names_e1 <- c("fac") names_shared <- c("t0", "t0") term_n_e0 <- 0 term_n_e1 <- 0 term_n_shared <- c(0, 0) tform_e0 <- "loglin" tform_e1 <- "loglin" tform_shared <- c("quad_slope", "loglin_top") keep_constant_e0 <- 0 keep_constant_e1 <- 0 keep_constant_shared <- c(0, 0) a_n_e0 <- c(-0.1) a_n_e1 <- c(0.1) a_n_shared <- c(0.001, -0.02) name_list <- list(shared = names_shared, e0 = names_e0, e1 = names_e1) term_n_list <- list(shared = term_n_shared, e0 = term_n_e0, e1 = term_n_e1) tform_list <- list(shared = tform_shared, e0 = tform_e0, e1 = tform_e1) keep_constant_list <- list( shared = keep_constant_shared, e0 = keep_constant_e0, e1 = keep_constant_e1 ) a_n_list <- list(shared = a_n_shared, e0 = a_n_e0, e1 = a_n_e1) val <- Joint_Multiple_Events( df, events, name_list, term_n_list, tform_list, keep_constant_list, a_n_list )
Likelihood_Ratio_Test uses two models and calculates the ratio
Likelihood_Ratio_Test(alternative_model, null_model)Likelihood_Ratio_Test(alternative_model, null_model)
alternative_model |
the new model of interest in list form, output from a Poisson regression |
null_model |
a model to compare against, in list form |
returns the score statistic
library(data.table) # In an actual example, one would run two seperate RunCoxRegression regressions, # assigning the results to e0 and e1 a <- c(0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6) b <- c(1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7) c <- c(1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0) d <- c(3, 4, 5, 6, 7, 8, 9, 1, 2, 1, 1, 2, 1, 2) e <- c(1, 2, 0, 0, 1, 2, 0, 0, 1, 2, 0, 0, 1, 2) df <- data.table(a = a, b = b, c = c, d = d, e = e) keep_constant <- 0 a_n <- c(-0.1, 0.1, 0.1, 0.2) control <- list(ncores = 1, maxiter = 10, verbose = 0) model <- Cox(a, b, c) ~ plinear(d * d, 0) + loglinear(factor(e)) alternative_model <- CoxRun(model, df, control = control, a_n = a_n, keep_constant = c(0, 1, 0) ) null_model <- CoxRun(Cox(a, b, c) ~ null(), df, control = control) score <- Likelihood_Ratio_Test(alternative_model, null_model)library(data.table) # In an actual example, one would run two seperate RunCoxRegression regressions, # assigning the results to e0 and e1 a <- c(0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6) b <- c(1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7) c <- c(1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0) d <- c(3, 4, 5, 6, 7, 8, 9, 1, 2, 1, 1, 2, 1, 2) e <- c(1, 2, 0, 0, 1, 2, 0, 0, 1, 2, 0, 0, 1, 2) df <- data.table(a = a, b = b, c = c, d = d, e = e) keep_constant <- 0 a_n <- c(-0.1, 0.1, 0.1, 0.2) control <- list(ncores = 1, maxiter = 10, verbose = 0) model <- Cox(a, b, c) ~ plinear(d * d, 0) + loglinear(factor(e)) alternative_model <- CoxRun(model, df, control = control, a_n = a_n, keep_constant = c(0, 1, 0) ) null_model <- CoxRun(Cox(a, b, c) ~ null(), df, control = control) score <- Likelihood_Ratio_Test(alternative_model, null_model)
LikelihoodBound Generic likelihood boundary calculation function. Used
by the coxres, poisres, and logitres objects to calculate likelihood based
confidence intervals.
LikelihoodBound(x, df, curve_control = list(), control = list(), ...)LikelihoodBound(x, df, curve_control = list(), control = list(), ...)
x |
result object from a regression, class coxres or poisres |
df |
a data.table containing the columns of interest |
curve_control |
a list of control options for the likelihood boundary regression. See the control options vignette for details. |
control |
list of parameters controlling the convergence, see the control options vignette for details |
... |
extended for other necessary parameters |
returns a summary of the likelihood boundary
Other Likelihood Boundaries:
LikelihoodBound.coxres(),
LikelihoodBound.logitres(),
LikelihoodBound.poisres()
LikelihoodBound.coxres solves the confidence interval for a cox model, starting at the optimum point and
iteratively optimizing end-points of intervals.
## S3 method for class 'coxres' LikelihoodBound(x, df, curve_control = list(), control = list(), ...)## S3 method for class 'coxres' LikelihoodBound(x, df, curve_control = list(), control = list(), ...)
x |
result object from a regression, class coxres |
df |
a data.table containing the columns of interest |
curve_control |
a list of control options for the likelihood boundary regression. See the control options vignette for details. |
control |
list of parameters controlling the convergence, see the control options vignette for details |
... |
can include the named entries for the curve_control list parameter |
returns a summary of the likelihood boundary
Other Likelihood Boundaries:
LikelihoodBound(),
LikelihoodBound.logitres(),
LikelihoodBound.poisres()
LikelihoodBound.logitres solves the confidence interval for a Poisson model, starting at the optimum point and
iteratively optimizing end-points of intervals.
## S3 method for class 'logitres' LikelihoodBound(x, df, curve_control = list(), control = list(), ...)## S3 method for class 'logitres' LikelihoodBound(x, df, curve_control = list(), control = list(), ...)
x |
result object from a regression, class poisres |
df |
a data.table containing the columns of interest |
curve_control |
a list of control options for the likelihood boundary regression. See the control options vignette for details. |
control |
list of parameters controlling the convergence, see the control options vignette for details |
... |
can include the named entries for the curve_control list parameter |
returns a summary of the likelihood boundary
Other Likelihood Boundaries:
LikelihoodBound(),
LikelihoodBound.coxres(),
LikelihoodBound.poisres()
LikelihoodBound.poisres solves the confidence interval for a Poisson model, starting at the optimum point and
iteratively optimizing end-points of intervals.
## S3 method for class 'poisres' LikelihoodBound(x, df, curve_control = list(), control = list(), ...)## S3 method for class 'poisres' LikelihoodBound(x, df, curve_control = list(), control = list(), ...)
x |
result object from a regression, class poisres |
df |
a data.table containing the columns of interest |
curve_control |
a list of control options for the likelihood boundary regression. See the control options vignette for details. |
control |
list of parameters controlling the convergence, see the control options vignette for details |
... |
can include the named entries for the curve_control list parameter |
returns a summary of the likelihood boundary
Other Likelihood Boundaries:
LikelihoodBound(),
LikelihoodBound.coxres(),
LikelihoodBound.logitres()
Linked_Dose_Formula Calculates all parameters for linear-quadratic and linear-exponential linked formulas
Linked_Dose_Formula(tforms, paras)Linked_Dose_Formula(tforms, paras)
tforms |
list of formula types |
paras |
list of formula parameters |
returns list of full parameters
Other Piece-wise Assistance Functions:
Linked_Lin_Exp_Para()
library(data.table) tforms <- list(cov_0 = "quad", cov_1 = "exp") paras <- list(cov_0 = c(1, 3.45), cov_1 = c(1.2, 4.5, 0.1)) full_paras <- Linked_Dose_Formula(tforms, paras)library(data.table) tforms <- list(cov_0 = "quad", cov_1 = "exp") paras <- list(cov_0 = c(1, 3.45), cov_1 = c(1.2, 4.5, 0.1)) full_paras <- Linked_Dose_Formula(tforms, paras)
Linked_Lin_Exp_Para Calculates what the additional parameter would be for a desired maximum
Linked_Lin_Exp_Para(y, a0, a1_goal)Linked_Lin_Exp_Para(y, a0, a1_goal)
y |
point formula switch |
a0 |
linear slope |
a1_goal |
exponential maximum desired |
returns parameter used by Colossus
Other Piece-wise Assistance Functions:
Linked_Dose_Formula()
library(data.table) y <- 7.6 a0 <- 1.2 a1_goal <- 15 full_paras <- Linked_Lin_Exp_Para(y, a0, a1_goal)library(data.table) y <- 7.6 a0 <- 1.2 a1_goal <- 15 full_paras <- Linked_Lin_Exp_Para(y, a0, a1_goal)
LogisticRun uses a formula, data.table, and list of controls to prepare and
run a Colossus logistic regression function
LogisticRun( model, df, a_n = list(0), keep_constant = 0, control = list(), gradient_control = list(), link = "odds", single = FALSE, observed_info = FALSE, cons_mat = as.matrix(0), cons_vec = 0, norm = "null", ... )LogisticRun( model, df, a_n = list(0), keep_constant = 0, control = list(), gradient_control = list(), link = "odds", single = FALSE, observed_info = FALSE, cons_mat = as.matrix(0), cons_vec = 0, norm = "null", ... )
model |
either a formula written for the get_form function, or the model result from the get_form function. |
df |
a data.table containing the columns of interest |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
keep_constant |
binary values to denote which parameters to change |
control |
list of parameters controlling the convergence, see the control options vignette for details |
gradient_control |
a list of control options for the gradient descent algorithm. If any value is given, a gradient descent algorithm is used instead of Newton-Raphson. See the control options vignette for details |
link |
Used in logistic regression, the linking function relating the input model and event probability. Current options are "odds", "ident", and "loglink" for the odds ratio, identity, and complimentary loglink options. |
single |
a boolean to denote that only the log-likelihood should be calculated and returned, no derivatives or iterations |
observed_info |
a boolean to denote that the observed information matrix should be used to calculate the standard error for parameters, not the expected information matrix |
cons_mat |
Matrix containing coefficients for a system of linear constraints, formatted as matrix |
cons_vec |
Vector containing constants for a system of linear constraints, formatted as vector |
norm |
methods used to normalize the covariates. Default is 'null' for no normalization. Other options include 'max' to normalize by the absolute maximum and 'mean' to normalize by the mean |
... |
can include the named entries for the control list parameter |
returns a class fully describing the model and the regression results
Other Logistic Wrapper Functions:
LogisticRunMulti(),
LogisticRunMultiOut()
library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1), e = c(0, 0, 1, 0, 0, 0, 1) ) control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- logit(Cancer_Status) ~ loglinear(a, b, c, 0) + plinear(d, 0) + multiplicative() res <- LogisticRun(formula, df, a_n = c(1.1, -0.1, 0.2, 0.5), control = control)library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1), e = c(0, 0, 1, 0, 0, 0, 1) ) control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- logit(Cancer_Status) ~ loglinear(a, b, c, 0) + plinear(d, 0) + multiplicative() res <- LogisticRun(formula, df, a_n = c(1.1, -0.1, 0.2, 0.5), control = control)
LogisticRunMulti uses a formula, data.table, and list of controls to prepare and
run a Colossus poisson regression function
LogisticRunMulti( model, df, a_n = list(0), keep_constant = 0, realization_columns = matrix(c("temp00", "temp01", "temp10", "temp11"), nrow = 2), realization_index = c("temp0", "temp1"), control = list(), gradient_control = list(), link = "odds", single = FALSE, observed_info = FALSE, fma = TRUE, mcml = FALSE, cons_mat = as.matrix(0), cons_vec = 0, ... )LogisticRunMulti( model, df, a_n = list(0), keep_constant = 0, realization_columns = matrix(c("temp00", "temp01", "temp10", "temp11"), nrow = 2), realization_index = c("temp0", "temp1"), control = list(), gradient_control = list(), link = "odds", single = FALSE, observed_info = FALSE, fma = TRUE, mcml = FALSE, cons_mat = as.matrix(0), cons_vec = 0, ... )
model |
either a formula written for the get_form function, or the model result from the get_form function. |
df |
a data.table containing the columns of interest |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
keep_constant |
binary values to denote which parameters to change |
realization_columns |
used for multi-realization regressions. Matrix of column names with rows for each column with realizations, columns for each realization |
realization_index |
used for multi-realization regressions. Vector of column names, one for each column with realizations. Each name should be used in the "names" variable in the equation definition |
control |
list of parameters controlling the convergence, see the control options vignette for details |
gradient_control |
a list of control options for the gradient descent algorithm. If any value is given, a gradient descent algorithm is used instead of Newton-Raphson. See the control options vignette for details |
link |
Used in logistic regression, the linking function relating the input model and event probability. Current options are "odds", "ident", and "loglink" for the odds ratio, identity, and complimentary loglink options. |
single |
a boolean to denote that only the log-likelihood should be calculated and returned, no derivatives or iterations |
observed_info |
a boolean to denote that the observed information matrix should be used to calculate the standard error for parameters, not the expected information matrix |
fma |
a boolean to denote that the Frequentist Model Averaging method should be used |
mcml |
a boolean to denote that the Monte Carlo Maximum Likelihood method should be used |
cons_mat |
Matrix containing coefficients for a system of linear constraints, formatted as matrix |
cons_vec |
Vector containing constants for a system of linear constraints, formatted as vector |
... |
can include the named entries for the control list parameter |
returns a class fully describing the model and the regression results
Other Logistic Wrapper Functions:
LogisticRun(),
LogisticRunMultiOut()
library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), t0 = c(18, 20, 18, 19, 21, 20, 18), t1 = c(30, 45, 57, 47, 36, 60, 55), lung = c(0, 0, 1, 0, 1, 0, 0), dose = c(0, 1, 1, 0, 1, 0, 1) ) set.seed(3742) df$rand <- floor(runif(nrow(df), min = 0, max = 5)) df$rand0 <- floor(runif(nrow(df), min = 0, max = 5)) df$rand1 <- floor(runif(nrow(df), min = 0, max = 5)) df$rand2 <- floor(runif(nrow(df), min = 0, max = 5)) realization_columns <- matrix(c("rand0", "rand1", "rand2"), nrow = 1) realization_index <- c("rand") control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- logit(lung) ~ loglinear(CONST, dose, rand, 0) + multiplicative() res <- LogisticRunMulti(formula, df, control = control, realization_columns = realization_columns, realization_index = realization_index )library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), t0 = c(18, 20, 18, 19, 21, 20, 18), t1 = c(30, 45, 57, 47, 36, 60, 55), lung = c(0, 0, 1, 0, 1, 0, 0), dose = c(0, 1, 1, 0, 1, 0, 1) ) set.seed(3742) df$rand <- floor(runif(nrow(df), min = 0, max = 5)) df$rand0 <- floor(runif(nrow(df), min = 0, max = 5)) df$rand1 <- floor(runif(nrow(df), min = 0, max = 5)) df$rand2 <- floor(runif(nrow(df), min = 0, max = 5)) realization_columns <- matrix(c("rand0", "rand1", "rand2"), nrow = 1) realization_index <- c("rand") control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- logit(lung) ~ loglinear(CONST, dose, rand, 0) + multiplicative() res <- LogisticRunMulti(formula, df, control = control, realization_columns = realization_columns, realization_index = realization_index )
LogisticRunMultiOut uses a formula, data.table, and list of controls to prepare and
run a Colossus logistic regression function
LogisticRunMultiOut( model, df, a_n = list(0), keep_constant = 0, realization_columns = c("event0", "event1"), control = list(), gradient_control = list(), link = "odds", single = FALSE, observed_info = FALSE, cons_mat = as.matrix(0), cons_vec = 0, ... )LogisticRunMultiOut( model, df, a_n = list(0), keep_constant = 0, realization_columns = c("event0", "event1"), control = list(), gradient_control = list(), link = "odds", single = FALSE, observed_info = FALSE, cons_mat = as.matrix(0), cons_vec = 0, ... )
model |
either a formula written for the get_form function, or the model result from the get_form function. |
df |
a data.table containing the columns of interest |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
keep_constant |
binary values to denote which parameters to change |
realization_columns |
used for multi-realization regressions. Matrix of column names with rows for each column with realizations, columns for each realization |
control |
list of parameters controlling the convergence, see the control options vignette for details |
gradient_control |
a list of control options for the gradient descent algorithm. If any value is given, a gradient descent algorithm is used instead of Newton-Raphson. See the control options vignette for details |
link |
Used in logistic regression, the linking function relating the input model and event probability. Current options are "odds", "ident", and "loglink" for the odds ratio, identity, and complimentary loglink options. |
single |
a boolean to denote that only the log-likelihood should be calculated and returned, no derivatives or iterations |
observed_info |
a boolean to denote that the observed information matrix should be used to calculate the standard error for parameters, not the expected information matrix |
cons_mat |
Matrix containing coefficients for a system of linear constraints, formatted as matrix |
cons_vec |
Vector containing constants for a system of linear constraints, formatted as vector |
... |
can include the named entries for the control list parameter |
returns a class fully describing the model and the regression results
Other Logistic Wrapper Functions:
LogisticRun(),
LogisticRunMulti()
library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), t0 = c(18, 20, 18, 19, 21, 20, 18), t1 = c(30, 45, 57, 47, 36, 60, 55), event = c(0, 0, 1, 0, 1, 0, 0), dose = c(0, 1, 1, 0, 1, 0, 1) ) set.seed(3742) df$event0 <- rbinom(nrow(df), size = 1, prob = 0.3) df$event1 <- rbinom(nrow(df), size = 1, prob = 0.3) df$event2 <- rbinom(nrow(df), size = 1, prob = 0.3) realization_columns <- c("event0", "event1", "event2") control <- list( ncores = 1, lr = 0.75, maxiter = 10, verbose = 0 ) formula <- logit(event) ~ loglinear(dose, 0) + multiplicative() res <- LogisticRunMultiOut(formula, df, realization_columns = realization_columns, control = control )library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), t0 = c(18, 20, 18, 19, 21, 20, 18), t1 = c(30, 45, 57, 47, 36, 60, 55), event = c(0, 0, 1, 0, 1, 0, 0), dose = c(0, 1, 1, 0, 1, 0, 1) ) set.seed(3742) df$event0 <- rbinom(nrow(df), size = 1, prob = 0.3) df$event1 <- rbinom(nrow(df), size = 1, prob = 0.3) df$event2 <- rbinom(nrow(df), size = 1, prob = 0.3) realization_columns <- c("event0", "event1", "event2") control <- list( ncores = 1, lr = 0.75, maxiter = 10, verbose = 0 ) formula <- logit(event) ~ loglinear(dose, 0) + multiplicative() res <- LogisticRunMultiOut(formula, df, realization_columns = realization_columns, control = control )
OMP_Check Called directly from R, checks the omp flag and returns true if omp is enabled
OMP_Check()OMP_Check()
boolean: True for OMP allowed
Other Output and Information Functions:
System_Version()
plot.coxres uses user provided data, time/event columns,
vectors specifying the model, and options to choose and save plots.
The 'plot_options' variable can be used to select the types of plots run.
## S3 method for class 'coxres' plot(x, df, plot_options, a_n = NULL, ...)## S3 method for class 'coxres' plot(x, df, plot_options, a_n = NULL, ...)
x |
result object from a regression, class coxres |
df |
a data.table containing the columns of interest |
plot_options |
list of parameters controlling the plot options, see the plotting vignette for different options |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
... |
can include the named entries for the plot_options parameter |
returns the data used for plots
Other Plotting Wrapper Functions:
plotMartingale.coxres(),
plotRisk.coxres(),
plotSchoenfeld.coxres(),
plotSurvival.coxres()
library(data.table) ## basic example code reproduced from the starting-description vignette df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1) ) control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- Cox(Starting_Age, Ending_Age, Cancer_Status) ~ loglinear(a, b, c, 0) + plinear(d, 0) + multiplicative() res <- CoxRun(formula, df, control = control, a_n = list(c(1.1, -0.1, 0.2, 0.5), c(1.6, -0.12, 0.3, 0.4)) ) plot_options <- list( type = c("surv", paste0( tempfile(), "run" )), studyid = "UserID", verbose = FALSE ) res_plot <- plot(res, df, plot_options)library(data.table) ## basic example code reproduced from the starting-description vignette df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1) ) control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- Cox(Starting_Age, Ending_Age, Cancer_Status) ~ loglinear(a, b, c, 0) + plinear(d, 0) + multiplicative() res <- CoxRun(formula, df, control = control, a_n = list(c(1.1, -0.1, 0.2, 0.5), c(1.6, -0.12, 0.3, 0.4)) ) plot_options <- list( type = c("surv", paste0( tempfile(), "run" )), studyid = "UserID", verbose = FALSE ) res_plot <- plot(res, df, plot_options)
plotMartingale Generic martingale residual plotting, used by the
coxres object to plot martingale residuals. Currently only returns data
that could be plotted.
plotMartingale(x, df, plot_options, a_n = NULL, ...)plotMartingale(x, df, plot_options, a_n = NULL, ...)
x |
result object from a regression, class coxres |
df |
a data.table containing the columns of interest |
plot_options |
list of parameters controlling the plot options, see the plotting vignette for different options |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
... |
can include the named entries for the plot_options parameter |
returns the data used for plots
plotMartingale.coxres uses user provided data, time/event columns,
vectors specifying the model, and options to choose and save plots
## S3 method for class 'coxres' plotMartingale(x, df, plot_options, a_n = NULL, ...)## S3 method for class 'coxres' plotMartingale(x, df, plot_options, a_n = NULL, ...)
x |
result object from a regression, class coxres |
df |
a data.table containing the columns of interest |
plot_options |
list of parameters controlling the plot options, see the plotting vignette for different options |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
... |
can include the named entries for the plot_options parameter |
returns the data used for plots
Other Plotting Wrapper Functions:
plot.coxres(),
plotRisk.coxres(),
plotSchoenfeld.coxres(),
plotSurvival.coxres()
plotRisk Generic risk plotting function. Used by the coxres
object to plot the hazard ratios at different levels of individual
covariates. Currently only returns data that could be plotted.
plotRisk(x, df, plot_options, a_n = NULL, ...)plotRisk(x, df, plot_options, a_n = NULL, ...)
x |
result object from a regression, class coxres |
df |
a data.table containing the columns of interest |
plot_options |
list of parameters controlling the plot options, see the plotting vignette for different options |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
... |
can include the named entries for the plot_options parameter |
returns the data used for plots
plotRisk.coxres uses user provided data, time/event columns,
vectors specifying the model, and options to choose and save plots
## S3 method for class 'coxres' plotRisk(x, df, plot_options, a_n = NULL, ...)## S3 method for class 'coxres' plotRisk(x, df, plot_options, a_n = NULL, ...)
x |
result object from a regression, class coxres |
df |
a data.table containing the columns of interest |
plot_options |
list of parameters controlling the plot options, see the plotting vignette for different options |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
... |
can include the named entries for the plot_options parameter |
returns the data used for plots
Other Plotting Wrapper Functions:
plot.coxres(),
plotMartingale.coxres(),
plotSchoenfeld.coxres(),
plotSurvival.coxres()
plotSchoenfeld Generic Schoenfeld residual plotting function, used by
the coxres object to calculate Schoenfeld residuals. Currently only returns
data that could be plotted.
plotSchoenfeld(x, df, plot_options, a_n = NULL, ...)plotSchoenfeld(x, df, plot_options, a_n = NULL, ...)
x |
result object from a regression, class coxres |
df |
a data.table containing the columns of interest |
plot_options |
list of parameters controlling the plot options, see the plotting vignette for different options |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
... |
can include the named entries for the plot_options parameter |
returns the data used for plots
plotSchoenfeld.coxres uses user provided data, time/event columns,
vectors specifying the model, and options to choose and save plots
## S3 method for class 'coxres' plotSchoenfeld(x, df, plot_options, a_n = NULL, ...)## S3 method for class 'coxres' plotSchoenfeld(x, df, plot_options, a_n = NULL, ...)
x |
result object from a regression, class coxres |
df |
a data.table containing the columns of interest |
plot_options |
list of parameters controlling the plot options, see the plotting vignette for different options |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
... |
can include the named entries for the plot_options parameter |
returns the data used for plots
Other Plotting Wrapper Functions:
plot.coxres(),
plotMartingale.coxres(),
plotRisk.coxres(),
plotSurvival.coxres()
plotSurvival Generic survival plotting, used by the coxres
object. Calculates the baseline hazard, cumulative hazard, and survival
curve for the list of event times. Currently only returns data that could be
plotted.
plotSurvival(x, df, plot_options, a_n = NULL, ...)plotSurvival(x, df, plot_options, a_n = NULL, ...)
x |
result object from a regression, class coxres |
df |
a data.table containing the columns of interest |
plot_options |
list of parameters controlling the plot options, see the plotting vignette for different options |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
... |
can include the named entries for the plot_options parameter |
returns the data used for plots
plotSurvival.coxres uses user provided data, time/event columns,
vectors specifying the model, and options to choose and save plots
## S3 method for class 'coxres' plotSurvival(x, df, plot_options, a_n = NULL, ...)## S3 method for class 'coxres' plotSurvival(x, df, plot_options, a_n = NULL, ...)
x |
result object from a regression, class coxres |
df |
a data.table containing the columns of interest |
plot_options |
list of parameters controlling the plot options, see the plotting vignette for different options |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
... |
can include the named entries for the plot_options parameter |
returns the data used for plots
Other Plotting Wrapper Functions:
plot.coxres(),
plotMartingale.coxres(),
plotRisk.coxres(),
plotSchoenfeld.coxres()
library(data.table) ## basic example code reproduced from the starting-description vignette df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1) ) control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- Cox(Starting_Age, Ending_Age, Cancer_Status) ~ loglinear(a, b, c, 0) + plinear(d, 0) + multiplicative() res <- CoxRun(formula, df, control = control, a_n = list(c(1.1, -0.1, 0.2, 0.5), c(1.6, -0.12, 0.3, 0.4)) ) plot_options <- list( fname = paste0( tempfile(), "run" ), studyid = "UserID", verbose = FALSE ) res_plot <- plotSurvival(res, df, plot_options)library(data.table) ## basic example code reproduced from the starting-description vignette df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1) ) control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- Cox(Starting_Age, Ending_Age, Cancer_Status) ~ loglinear(a, b, c, 0) + plinear(d, 0) + multiplicative() res <- CoxRun(formula, df, control = control, a_n = list(c(1.1, -0.1, 0.2, 0.5), c(1.6, -0.12, 0.3, 0.4)) ) plot_options <- list( fname = paste0( tempfile(), "run" ), studyid = "UserID", verbose = FALSE ) res_plot <- plotSurvival(res, df, plot_options)
PoisRun uses a formula, data.table, and list of controls to prepare and
run a Colossus poisson regression function
PoisRun( model, df, a_n = list(0), keep_constant = 0, control = list(), gradient_control = list(), single = FALSE, observed_info = FALSE, cons_mat = as.matrix(0), cons_vec = 0, norm = "null", ... )PoisRun( model, df, a_n = list(0), keep_constant = 0, control = list(), gradient_control = list(), single = FALSE, observed_info = FALSE, cons_mat = as.matrix(0), cons_vec = 0, norm = "null", ... )
model |
either a formula written for the get_form function, or the model result from the get_form function. |
df |
a data.table containing the columns of interest |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
keep_constant |
binary values to denote which parameters to change |
control |
list of parameters controlling the convergence, see the control options vignette for details |
gradient_control |
a list of control options for the gradient descent algorithm. If any value is given, a gradient descent algorithm is used instead of Newton-Raphson. See the control options vignette for details |
single |
a boolean to denote that only the log-likelihood should be calculated and returned, no derivatives or iterations |
observed_info |
a boolean to denote that the observed information matrix should be used to calculate the standard error for parameters, not the expected information matrix |
cons_mat |
Matrix containing coefficients for a system of linear constraints, formatted as matrix |
cons_vec |
Vector containing constants for a system of linear constraints, formatted as vector |
norm |
methods used to normalize the covariates. Default is 'null' for no normalization. Other options include 'max' to normalize by the absolute maximum and 'mean' to normalize by the mean |
... |
can include the named entries for the control list parameter |
returns a class fully describing the model and the regression results
Other Poisson Wrapper Functions:
PoisRunJoint(),
PoisRunMulti(),
PoisRunMultiOut()
library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1), e = c(0, 0, 1, 0, 0, 0, 1) ) control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- Pois(Ending_Age, Cancer_Status) ~ loglinear(a, b, c, 0) + plinear(d, 0) + multiplicative() res <- PoisRun(formula, df, a_n = c(1.1, -0.1, 0.2, 0.5), control = control)library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1), e = c(0, 0, 1, 0, 0, 0, 1) ) control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- Pois(Ending_Age, Cancer_Status) ~ loglinear(a, b, c, 0) + plinear(d, 0) + multiplicative() res <- PoisRun(formula, df, a_n = c(1.1, -0.1, 0.2, 0.5), control = control)
PoisRunJoint uses a list of formula, data.table, and list of controls to prepare and
run a Colossus poisson regression function on a joint dataset
PoisRunJoint( model, df, a_n = list(0), keep_constant = 0, control = list(), gradient_control = list(), single = FALSE, observed_info = FALSE, cons_mat = as.matrix(0), cons_vec = 0, norm = "null", ... )PoisRunJoint( model, df, a_n = list(0), keep_constant = 0, control = list(), gradient_control = list(), single = FALSE, observed_info = FALSE, cons_mat = as.matrix(0), cons_vec = 0, norm = "null", ... )
model |
either a formula written for the get_form function, or the model result from the get_form function. |
df |
a data.table containing the columns of interest |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
keep_constant |
binary values to denote which parameters to change |
control |
list of parameters controlling the convergence, see the control options vignette for details |
gradient_control |
a list of control options for the gradient descent algorithm. If any value is given, a gradient descent algorithm is used instead of Newton-Raphson. See the control options vignette for details |
single |
a boolean to denote that only the log-likelihood should be calculated and returned, no derivatives or iterations |
observed_info |
a boolean to denote that the observed information matrix should be used to calculate the standard error for parameters, not the expected information matrix |
cons_mat |
Matrix containing coefficients for a system of linear constraints, formatted as matrix |
cons_vec |
Vector containing constants for a system of linear constraints, formatted as vector |
norm |
methods used to normalize the covariates. Default is 'null' for no normalization. Other options include 'max' to normalize by the absolute maximum and 'mean' to normalize by the mean |
... |
can include the named entries for the control list parameter |
returns a class fully describing the model and the regression results
Other Poisson Wrapper Functions:
PoisRun(),
PoisRunMulti(),
PoisRunMultiOut()
library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), Flu_Status = c(0, 1, 0, 0, 1, 0, 1), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1), e = c(0, 0, 1, 0, 0, 0, 1) ) control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula_list <- list(Pois(Ending_Age, Cancer_Status) ~ plinear(d, 0), Pois(Ending_Age, Flu_Status) ~ loglinear(d, 0), shared = Pois(Ending_Age) ~ loglinear(a, b, c, 0) ) res <- PoisRunJoint(formula_list, df, control = control)library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), Flu_Status = c(0, 1, 0, 0, 1, 0, 1), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1), e = c(0, 0, 1, 0, 0, 0, 1) ) control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula_list <- list(Pois(Ending_Age, Cancer_Status) ~ plinear(d, 0), Pois(Ending_Age, Flu_Status) ~ loglinear(d, 0), shared = Pois(Ending_Age) ~ loglinear(a, b, c, 0) ) res <- PoisRunJoint(formula_list, df, control = control)
PoisRunMulti uses a formula, data.table, and list of controls to prepare and
run a Colossus poisson regression function
PoisRunMulti( model, df, a_n = list(0), keep_constant = 0, realization_columns = matrix(c("temp00", "temp01", "temp10", "temp11"), nrow = 2), realization_index = c("temp0", "temp1"), control = list(), gradient_control = list(), single = FALSE, observed_info = FALSE, fma = TRUE, mcml = FALSE, cons_mat = as.matrix(0), cons_vec = 0, ... )PoisRunMulti( model, df, a_n = list(0), keep_constant = 0, realization_columns = matrix(c("temp00", "temp01", "temp10", "temp11"), nrow = 2), realization_index = c("temp0", "temp1"), control = list(), gradient_control = list(), single = FALSE, observed_info = FALSE, fma = TRUE, mcml = FALSE, cons_mat = as.matrix(0), cons_vec = 0, ... )
model |
either a formula written for the get_form function, or the model result from the get_form function. |
df |
a data.table containing the columns of interest |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
keep_constant |
binary values to denote which parameters to change |
realization_columns |
used for multi-realization regressions. Matrix of column names with rows for each column with realizations, columns for each realization |
realization_index |
used for multi-realization regressions. Vector of column names, one for each column with realizations. Each name should be used in the "names" variable in the equation definition |
control |
list of parameters controlling the convergence, see the control options vignette for details |
gradient_control |
a list of control options for the gradient descent algorithm. If any value is given, a gradient descent algorithm is used instead of Newton-Raphson. See the control options vignette for details |
single |
a boolean to denote that only the log-likelihood should be calculated and returned, no derivatives or iterations |
observed_info |
a boolean to denote that the observed information matrix should be used to calculate the standard error for parameters, not the expected information matrix |
fma |
a boolean to denote that the Frequentist Model Averaging method should be used |
mcml |
a boolean to denote that the Monte Carlo Maximum Likelihood method should be used |
cons_mat |
Matrix containing coefficients for a system of linear constraints, formatted as matrix |
cons_vec |
Vector containing constants for a system of linear constraints, formatted as vector |
... |
can include the named entries for the control list parameter |
returns a class fully describing the model and the regression results
Other Poisson Wrapper Functions:
PoisRun(),
PoisRunJoint(),
PoisRunMultiOut()
library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), t0 = c(18, 20, 18, 19, 21, 20, 18), t1 = c(30, 45, 57, 47, 36, 60, 55), lung = c(0, 0, 1, 0, 1, 0, 0), dose = c(0, 1, 1, 0, 1, 0, 1) ) set.seed(3742) df$rand <- floor(runif(nrow(df), min = 0, max = 5)) df$rand0 <- floor(runif(nrow(df), min = 0, max = 5)) df$rand1 <- floor(runif(nrow(df), min = 0, max = 5)) df$rand2 <- floor(runif(nrow(df), min = 0, max = 5)) realization_columns <- matrix(c("rand0", "rand1", "rand2"), nrow = 1) realization_index <- c("rand") control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- Pois(t1, lung) ~ loglinear(CONST, dose, rand, 0) + multiplicative() res <- PoisRunMulti(formula, df, control = control, realization_columns = realization_columns, realization_index = realization_index )library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), t0 = c(18, 20, 18, 19, 21, 20, 18), t1 = c(30, 45, 57, 47, 36, 60, 55), lung = c(0, 0, 1, 0, 1, 0, 0), dose = c(0, 1, 1, 0, 1, 0, 1) ) set.seed(3742) df$rand <- floor(runif(nrow(df), min = 0, max = 5)) df$rand0 <- floor(runif(nrow(df), min = 0, max = 5)) df$rand1 <- floor(runif(nrow(df), min = 0, max = 5)) df$rand2 <- floor(runif(nrow(df), min = 0, max = 5)) realization_columns <- matrix(c("rand0", "rand1", "rand2"), nrow = 1) realization_index <- c("rand") control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- Pois(t1, lung) ~ loglinear(CONST, dose, rand, 0) + multiplicative() res <- PoisRunMulti(formula, df, control = control, realization_columns = realization_columns, realization_index = realization_index )
PoisRunMultiOut uses a formula, data.table, and list of controls to prepare and
run a Colossus poisson regression function
PoisRunMultiOut( model, df, a_n = list(0), keep_constant = 0, realization_columns = c("event0", "event1"), control = list(), gradient_control = list(), single = FALSE, observed_info = FALSE, cons_mat = as.matrix(0), cons_vec = 0, ... )PoisRunMultiOut( model, df, a_n = list(0), keep_constant = 0, realization_columns = c("event0", "event1"), control = list(), gradient_control = list(), single = FALSE, observed_info = FALSE, cons_mat = as.matrix(0), cons_vec = 0, ... )
model |
either a formula written for the get_form function, or the model result from the get_form function. |
df |
a data.table containing the columns of interest |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
keep_constant |
binary values to denote which parameters to change |
realization_columns |
used for multi-realization regressions. Matrix of column names with rows for each column with realizations, columns for each realization |
control |
list of parameters controlling the convergence, see the control options vignette for details |
gradient_control |
a list of control options for the gradient descent algorithm. If any value is given, a gradient descent algorithm is used instead of Newton-Raphson. See the control options vignette for details |
single |
a boolean to denote that only the log-likelihood should be calculated and returned, no derivatives or iterations |
observed_info |
a boolean to denote that the observed information matrix should be used to calculate the standard error for parameters, not the expected information matrix |
cons_mat |
Matrix containing coefficients for a system of linear constraints, formatted as matrix |
cons_vec |
Vector containing constants for a system of linear constraints, formatted as vector |
... |
can include the named entries for the control list parameter |
returns a class fully describing the model and the regression results
Other Poisson Wrapper Functions:
PoisRun(),
PoisRunJoint(),
PoisRunMulti()
library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), t0 = c(18, 20, 18, 19, 21, 20, 18), t1 = c(30, 45, 57, 47, 36, 60, 55), lung = c(0, 0, 1, 0, 1, 0, 0), dose = c(0, 1, 1, 0, 1, 0, 1) ) set.seed(3742) df$rand <- c(1, floor(runif(nrow(df) - 1, min = 0, max = 1))) df$lung0 <- c(1, floor(runif(nrow(df) - 1, min = 0, max = 1))) df$lung1 <- c(1, floor(runif(nrow(df) - 1, min = 0, max = 1))) df$lung2 <- c(1, floor(runif(nrow(df) - 1, min = 0, max = 1))) realization_columns <- c("lung", "lung1", "lung2") control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- Pois(t1, lung) ~ loglinear(CONST, dose, rand, 0) + multiplicative() res <- PoisRunMultiOut(formula, df, control = control, realization_columns = realization_columns )library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), t0 = c(18, 20, 18, 19, 21, 20, 18), t1 = c(30, 45, 57, 47, 36, 60, 55), lung = c(0, 0, 1, 0, 1, 0, 0), dose = c(0, 1, 1, 0, 1, 0, 1) ) set.seed(3742) df$rand <- c(1, floor(runif(nrow(df) - 1, min = 0, max = 1))) df$lung0 <- c(1, floor(runif(nrow(df) - 1, min = 0, max = 1))) df$lung1 <- c(1, floor(runif(nrow(df) - 1, min = 0, max = 1))) df$lung2 <- c(1, floor(runif(nrow(df) - 1, min = 0, max = 1))) realization_columns <- c("lung", "lung1", "lung2") control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- Pois(t1, lung) ~ loglinear(CONST, dose, rand, 0) + multiplicative() res <- PoisRunMultiOut(formula, df, control = control, realization_columns = realization_columns )
RelativeRisk Generic relative risk calculation function,
currently only used by the coxres object, to calculate relative risks
for either the last parameter or a custom point.
RelativeRisk(x, df, ...)RelativeRisk(x, df, ...)
x |
result object from a regression, class coxres |
df |
a data.table containing the columns of interest |
... |
extended for other necessary parameters |
returns matrices of the relatives risks
Other Predicted Risk and Rate:
RelativeRisk.coxmodel(),
RelativeRisk.coxres(),
RelativeRisk.formula()
RelativeRisk.coxmodel uses a cox model object and data, to evaluate
relative risk in the data using the risk model from the result
## S3 method for class 'coxmodel' RelativeRisk(x, df, a_n = NULL, ...)## S3 method for class 'coxmodel' RelativeRisk(x, df, a_n = NULL, ...)
x |
cox model object, which could be fed to a regression |
df |
a data.table containing the columns of interest |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
... |
extended to match any future parameters needed |
returns a class fully describing the model and the regression results
Other Predicted Risk and Rate:
RelativeRisk(),
RelativeRisk.coxres(),
RelativeRisk.formula()
library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1), e = c(0, 0, 1, 0, 0, 0, 1) ) control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- Cox(Starting_Age, Ending_Age, Cancer_Status) ~ loglinear(a, b, c, 0) + plinear(d, 0) + multiplicative() model <- get_form(formula, df)$model res_risk <- RelativeRisk(model, df, a_n = c(1.1, -0.1, 0.2, 0.5))library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1), e = c(0, 0, 1, 0, 0, 0, 1) ) control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- Cox(Starting_Age, Ending_Age, Cancer_Status) ~ loglinear(a, b, c, 0) + plinear(d, 0) + multiplicative() model <- get_form(formula, df)$model res_risk <- RelativeRisk(model, df, a_n = c(1.1, -0.1, 0.2, 0.5))
coxres.RelativeRisk uses a cox result object and data, to evaluate
relative risk in the data using the risk model from the result
## S3 method for class 'coxres' RelativeRisk(x, df, a_n = NULL, ...)## S3 method for class 'coxres' RelativeRisk(x, df, a_n = NULL, ...)
x |
result object from a regression, class coxres |
df |
a data.table containing the columns of interest |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
... |
extended to match any future parameters needed |
returns a class fully describing the model and the regression results
Other Predicted Risk and Rate:
RelativeRisk(),
RelativeRisk.coxmodel(),
RelativeRisk.formula()
library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1), e = c(0, 0, 1, 0, 0, 0, 1) ) control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- Cox(Starting_Age, Ending_Age, Cancer_Status) ~ loglinear(a, b, c, 0) + plinear(d, 0) + multiplicative() res <- CoxRun(formula, df, a_n = list(c(1.1, -0.1, 0.2, 0.5), c(1.6, -0.12, 0.3, 0.4)), control = control ) res_risk <- RelativeRisk(res, df)library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1), e = c(0, 0, 1, 0, 0, 0, 1) ) control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- Cox(Starting_Age, Ending_Age, Cancer_Status) ~ loglinear(a, b, c, 0) + plinear(d, 0) + multiplicative() res <- CoxRun(formula, df, a_n = list(c(1.1, -0.1, 0.2, 0.5), c(1.6, -0.12, 0.3, 0.4)), control = control ) res_risk <- RelativeRisk(res, df)
RelativeRisk.formula uses a formula and data, to evaluate
relative risk in the data using the risk model from the result
## S3 method for class 'formula' RelativeRisk(x, df, a_n = NULL, ...)## S3 method for class 'formula' RelativeRisk(x, df, a_n = NULL, ...)
x |
formula object, which could be fed to a regression |
df |
a data.table containing the columns of interest |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
... |
extended to match any future parameters needed |
returns matrices of the relatives risks
Other Predicted Risk and Rate:
RelativeRisk(),
RelativeRisk.coxmodel(),
RelativeRisk.coxres()
library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1), e = c(0, 0, 1, 0, 0, 0, 1) ) control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- Cox(Starting_Age, Ending_Age, Cancer_Status) ~ loglinear(a, b, c, 0) + plinear(d, 0) + multiplicative() res_risk <- RelativeRisk(formula, df, a_n = c(1.1, -0.1, 0.2, 0.5))library(data.table) df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, 57, 47, 36, 60, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0), a = c(0, 1, 1, 0, 1, 0, 1), b = c(1, 1.1, 2.1, 2, 0.1, 1, 0.2), c = c(10, 11, 10, 11, 12, 9, 11), d = c(0, 0, 0, 1, 1, 1, 1), e = c(0, 0, 1, 0, 0, 0, 1) ) control <- list( ncores = 1, lr = 0.75, maxiters = c(1, 1), halfmax = 1 ) formula <- Cox(Starting_Age, Ending_Age, Cancer_Status) ~ loglinear(a, b, c, 0) + plinear(d, 0) + multiplicative() res_risk <- RelativeRisk(formula, df, a_n = c(1.1, -0.1, 0.2, 0.5))
Replace_Missing checks each column and fills in NA values
Replace_Missing(df, name_list, msv, verbose = FALSE)Replace_Missing(df, name_list, msv, verbose = FALSE)
df |
a data.table containing the columns of interest |
name_list |
vector of string column names to check |
msv |
value to replace na with, same used for every column used |
verbose |
integer valued 0-4 controlling what information is printed to the terminal. Each level includes the lower levels. 0: silent, 1: errors printed, 2: warnings printed, 3: notes printed, 4: debug information printed. Errors are situations that stop the regression, warnings are situations that assume default values that the user might not have intended, notes provide information on regression progress, and debug prints out C++ progress and intermediate results. The default level is 2 and True/False is converted to 3/0. |
returns a filled datatable
Other Data Cleaning Functions:
Date_Shift(),
Joint_Multiple_Events(),
Time_Since(),
factorize(),
gen_time_dep()
library(data.table) ## basic example code reproduced from the starting-description vignette df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, NA, 47, 36, NA, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0) ) df <- Replace_Missing(df, c("Starting_Age", "Ending_Age"), 70)library(data.table) ## basic example code reproduced from the starting-description vignette df <- data.table( UserID = c(112, 114, 213, 214, 115, 116, 117), Starting_Age = c(18, 20, 18, 19, 21, 20, 18), Ending_Age = c(30, 45, NA, 47, 36, NA, 55), Cancer_Status = c(0, 0, 1, 0, 1, 0, 0) ) df <- Replace_Missing(df, c("Starting_Age", "Ending_Age"), 70)
Residual Generic residual calculation function for regression
results. Note that the Cox residuals are calculated using the various
plotting based functions.
Residual(x, df, ...)Residual(x, df, ...)
x |
result object from a regression, class coxres or poisres |
df |
a data.table containing the columns of interest |
... |
extended for other necessary parameters |
returns matrices of residuals
Other Residuals:
Residual.logitmodel(),
Residual.logitres(),
Residual.poismodel(),
Residual.poisres()
Residual.logitmodel uses user provided data, person-year/event columns, vectors specifying the model,
and options to calculate residuals for a solved Poisson regression
## S3 method for class 'logitmodel' Residual( x, df, control = list(), a_n = NULL, link = "odds", pearson = FALSE, deviance = FALSE, ... )## S3 method for class 'logitmodel' Residual( x, df, control = list(), a_n = NULL, link = "odds", pearson = FALSE, deviance = FALSE, ... )
x |
result model for a regression, class logitmodel |
df |
a data.table containing the columns of interest |
control |
list of parameters controlling the convergence, see the control options vignette for details |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
link |
Used in logistic regression, the linking function relating the input model and event probability. Current options are "odds", "ident", and "loglink" for the odds ratio, identity, and complimentary loglink options. |
pearson |
boolean to calculate pearson residuals |
deviance |
boolean to calculate deviance residuals |
... |
can include the named entries for the assign_control list parameter |
returns matrices of residuals
Other Residuals:
Residual(),
Residual.logitres(),
Residual.poismodel(),
Residual.poisres()
Residual.logitres uses user provided data, person-year/event columns, vectors specifying the model,
and options to calculate residuals for a solved Poisson regression
## S3 method for class 'logitres' Residual( x, df, control = list(), a_n = NULL, pearson = FALSE, deviance = FALSE, ... )## S3 method for class 'logitres' Residual( x, df, control = list(), a_n = NULL, pearson = FALSE, deviance = FALSE, ... )
x |
result object from a regression, class logitres |
df |
a data.table containing the columns of interest |
control |
list of parameters controlling the convergence, see the control options vignette for details |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
pearson |
boolean to calculate pearson residuals |
deviance |
boolean to calculate deviance residuals |
... |
can include the named entries for the assign_control list parameter |
returns matrices of residuals
Other Residuals:
Residual(),
Residual.logitmodel(),
Residual.poismodel(),
Residual.poisres()
Residual.poismodel uses user provided data, person-year/event columns, vectors specifying the model,
and options to calculate residuals for a solved Poisson regression
## S3 method for class 'poismodel' Residual( x, df, control = list(), a_n = NULL, pearson = FALSE, deviance = FALSE, ... )## S3 method for class 'poismodel' Residual( x, df, control = list(), a_n = NULL, pearson = FALSE, deviance = FALSE, ... )
x |
result object from a poisson model, class poismodel |
df |
a data.table containing the columns of interest |
control |
list of parameters controlling the convergence, see the control options vignette for details |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
pearson |
boolean to calculate pearson residuals |
deviance |
boolean to calculate deviance residuals |
... |
can include the named entries for the assign_control list parameter |
returns matrices of residuals
Other Residuals:
Residual(),
Residual.logitmodel(),
Residual.logitres(),
Residual.poisres()
Residual.poisres uses user provided data, person-year/event columns, vectors specifying the model,
and options to calculate residuals for a solved Poisson regression
## S3 method for class 'poisres' Residual( x, df, control = list(), a_n = NULL, pearson = FALSE, deviance = FALSE, ... )## S3 method for class 'poisres' Residual( x, df, control = list(), a_n = NULL, pearson = FALSE, deviance = FALSE, ... )
x |
result object from a regression, class poisres |
df |
a data.table containing the columns of interest |
control |
list of parameters controlling the convergence, see the control options vignette for details |
a_n |
list of initial parameter values, used to determine the number of parameters. May be either a list of vectors or a single vector. |
pearson |
boolean to calculate pearson residuals |
deviance |
boolean to calculate deviance residuals |
... |
can include the named entries for the assign_control list parameter |
returns matrices of residuals
Other Residuals:
Residual(),
Residual.logitmodel(),
Residual.logitres(),
Residual.poismodel()
System_Version checks OS, default R c++ compiler, and if OMP is enabled
System_Version()System_Version()
returns a list of results
Other Output and Information Functions:
OMP_Check()
System_Version()System_Version()
Time_Since generates a new dataframe with a column containing time since a reference in a given unit
Time_Since(df, dcol0, tref, col_name, units = "days")Time_Since(df, dcol0, tref, col_name, units = "days")
df |
a data.table containing the columns of interest |
dcol0 |
list of ending month, day, and year |
tref |
reference time in date format |
col_name |
vector of new column names |
units |
time unit to use |
returns the updated dataframe
Other Data Cleaning Functions:
Date_Shift(),
Joint_Multiple_Events(),
Replace_Missing(),
factorize(),
gen_time_dep()
library(data.table) m0 <- c(1, 1, 2, 2) m1 <- c(2, 2, 3, 3) d0 <- c(1, 2, 3, 4) d1 <- c(6, 7, 8, 9) y0 <- c(1990, 1991, 1997, 1998) y1 <- c(2001, 2003, 2005, 2006) df <- data.table( m0 = m0, m1 = m1, d0 = d0, d1 = d1, y0 = y0, y1 = y1 ) tref <- strptime("3-22-1997", format = "%m-%d-%Y", tz = "UTC") df <- Time_Since(df, c("m1", "d1", "y1"), tref, "date_since")library(data.table) m0 <- c(1, 1, 2, 2) m1 <- c(2, 2, 3, 3) d0 <- c(1, 2, 3, 4) d1 <- c(6, 7, 8, 9) y0 <- c(1990, 1991, 1997, 1998) y1 <- c(2001, 2003, 2005, 2006) df <- data.table( m0 = m0, m1 = m1, d0 = d0, d1 = d1, y0 = y0, y1 = y1 ) tref <- strptime("3-22-1997", format = "%m-%d-%Y", tz = "UTC") df <- Time_Since(df, c("m1", "d1", "y1"), tref, "date_since")