Title: | Misc package for Daniel Sjoberg |
---|---|
Description: | Misc package for Daniel Sjoberg. |
Authors: | Daniel D. Sjoberg |
Maintainer: | Daniel D. Sjoberg <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2024-11-18 03:08:49 UTC |
Source: | https://github.com/ddsjoberg/sjofun |
Find the minimum of a function using the Golded-section search algorithm
golden_search(x, a, b, tol = 1e-04)
golden_search(x, a, b, tol = 1e-04)
x |
function with one argument |
a |
min value of search values |
b |
max value of search values |
tol |
tolerance level. Default is |
contfunc = function(x){ -exp(-x) * sin(x) } golden_search(contfunc, a = 0, b = 1.5)
contfunc = function(x){ -exp(-x) * sin(x) } golden_search(contfunc, a = 0, b = 1.5)
The model-based sinlge-arm comparison addresses the fundamental question of whether the current treatment provides a clinically significant improvement over prior treatments in the population. The proposed test statistic computes the difference between the observed outcome from the current treatment and the covariate-specific predicted outcome based on a model of the historical data. Thus, the difference between the observed and predicted quantities is attributed to the current treatment.
model_diff( data, outcome, covars, model, cov, coef, type = "logistic", output.details = FALSE )
model_diff( data, outcome, covars, model, cov, coef, type = "logistic", output.details = FALSE )
data |
a data frame containing the outcome and the outcome predictions. |
outcome |
the outcome, or response variable name. Must be a variable contained within the data frame specified in data=. |
covars |
vector of covariate/predictor variable(s) names. Must be a variable(s) contained within the data frame specified in data=. If model includes an intercept, user must include the column of ones in the covars vector |
model |
glm object of the predictive model estimated on historical cohort. If specified, the outcome, covars, cov, and coef objects will be extracted from object. |
cov |
Variance-covaraince matrix of the beta coefficients from predictive model. |
coef |
Vector of the beta coefficients from predictive model. If model includes an intercept, a vector of ones must appear in data. |
type |
Type of predictive model used. logistic is currently the only valid input. |
output.details |
Save additional information. Default is FALSE. |
Heller, Glenn, Michael W. Kattan, and Howard I. Scher. "Improving the decision to pursue a phase 3 clinical trial by adjusting for patient-specific factors in evaluating phase 2 treatment efficacy data." Medical Decision Making 27.4 (2007): 380-386.
Returns a list of results from analysis.
Daniel D Sjoberg [email protected]
set.seed(23432) #simulating historic dataset and creating prediction model. marker=rnorm(500, sd = 2) respond=runif(500)<plogis(marker) historic.data=data.frame(respond,marker) model.fit=glm(data=historic.data, formula = respond ~ marker, family = binomial(logit)) #simulating new data, with higher response rate new.data = marker=rnorm(50, sd = 2) respond=runif(50)<plogis(marker + 1) new.data=data.frame(respond,marker) #comparing outcomes in new data to those predicted in historic data # z-statistic = 2.412611 indicates signficant difference model_diff(data = new.data, model = model.fit) #comparing model based difference with binomial test #p-value of 0.3222 indicates we fail to reject null hypothesis binom.test(x=sum(new.data$respond), n=nrow(new.data), p = 0.5, alternative = c("two.sided"))
set.seed(23432) #simulating historic dataset and creating prediction model. marker=rnorm(500, sd = 2) respond=runif(500)<plogis(marker) historic.data=data.frame(respond,marker) model.fit=glm(data=historic.data, formula = respond ~ marker, family = binomial(logit)) #simulating new data, with higher response rate new.data = marker=rnorm(50, sd = 2) respond=runif(50)<plogis(marker + 1) new.data=data.frame(respond,marker) #comparing outcomes in new data to those predicted in historic data # z-statistic = 2.412611 indicates signficant difference model_diff(data = new.data, model = model.fit) #comparing model based difference with binomial test #p-value of 0.3222 indicates we fail to reject null hypothesis binom.test(x=sum(new.data$respond), n=nrow(new.data), p = 0.5, alternative = c("two.sided"))
Trial is a single arm Bayesian phase 2 trial with sequential stopping boundaries as outlined in Thall, Peter F., and Richard Simon. "Practical Bayesian guidelines for phase IIB clinical trials." Biometrics (1994): 337-349.
ph2_single_bayes_seq_sim( theta_s_mu, theta_s_width, theta_s_w_conf_level = 0.9, theta_e_c, delta_0, n_min, n_max, sim_n = 1, pr_low = 0.05, pr_high = 0.95, mu_e = theta_s_mu + delta_0, verbose = FALSE, quiet = FALSE )
ph2_single_bayes_seq_sim( theta_s_mu, theta_s_width, theta_s_w_conf_level = 0.9, theta_e_c, delta_0, n_min, n_max, sim_n = 1, pr_low = 0.05, pr_high = 0.95, mu_e = theta_s_mu + delta_0, verbose = FALSE, quiet = FALSE )
theta_s_mu |
Mean of prior distribution on theta_s |
theta_s_width |
Width of the probability interval (set by |
theta_s_w_conf_level |
Confidence level of width of probabilty specified |
theta_e_c |
Concentration parameter for prior distribution on theta_e |
delta_0 |
Targeted improvement of treatment for treatment E over S |
n_min |
Minimum number of patients that may be enrolled |
n_max |
Maximum number of patients that may be enrolled |
sim_n |
Number of simulated trials to create |
pr_low |
Lower probability limit for concluding treatment not promising |
pr_high |
Upper probablity limit for concluding treatment promising |
mu_e |
True rate of success with experimental treatment
in |
verbose |
When TRUE, additional information is returned as an attribute |
quiet |
Run with no notes, progress bars, etc. |
# simulate trial results sim_results <- ph2_single_bayes_seq_sim( # setting priors for standard treatment theta_s_mu = 0.2, theta_s_width = 0.20, theta_s_w_conf_level = 0.90, # setting priors for experimental treatment theta_e_c = 2, delta_0 = 0.15, # other trial parameters n_min = 10, n_max = 65, pr_low = 0.05, pr_high = 0.95, # true effect of experimental tx mu_e = 0.35, # number of simulations sim_n = 1000 ) # tabulate summary library(gtsummary) sim_results %>% dplyr::select(-sim_id) %>% tbl_summary( label = list(result ~ "Trial Result", n_enrolled ~ "No. Enrolled in Trial") ) %>% add_stat_label() %>% as_kable()
# simulate trial results sim_results <- ph2_single_bayes_seq_sim( # setting priors for standard treatment theta_s_mu = 0.2, theta_s_width = 0.20, theta_s_w_conf_level = 0.90, # setting priors for experimental treatment theta_e_c = 2, delta_0 = 0.15, # other trial parameters n_min = 10, n_max = 65, pr_low = 0.05, pr_high = 0.95, # true effect of experimental tx mu_e = 0.35, # number of simulations sim_n = 1000 ) # tabulate summary library(gtsummary) sim_results %>% dplyr::select(-sim_id) %>% tbl_summary( label = list(result ~ "Trial Result", n_enrolled ~ "No. Enrolled in Trial") ) %>% add_stat_label() %>% as_kable()