kaigu1990 / stabiot Goto Github PK
View Code? Open in Web Editor NEWCommon Statistical Analysis for Clinical Trials in Biotech
License: GNU General Public License v3.0
Common Statistical Analysis for Clinical Trials in Biotech
License: GNU General Public License v3.0
Create several functions below:
Regarding response rate and CI, its's a question of confidence Intervals for proportions. I prefer to utilize the functions that have been built up in existing packages.
DescTools::BinomCI(x = 54, n = 100, method = "clopper-pearson")
But how about handling the stratified Wilson? A few packages wrap it up. Such as tern::s_proportion()
. However, I feel like it should remain as is and not be added because it is not often utilized.
The response difference can be computed by DescTools::BinomDiffCI()
as well, so just wrap this function inside.
DescTools::BinomDiffCI(60, 100, 45, 100, method=c("wald"))
Regarding odds ratio and CI, it depends on if we need to add stratified variables. If not, it's a common odds ratio calculation that can be done with the DescTools::OddsRatio
function.
DescTools::OddsRatio(matrix(c(20, 22, 30, 28), nrow = 2, byrow = TRUE),
method = "wald", conf.level = 0.95)
Otherwise we can use logistic regression to calculate the odds ratio as well. And then if we use confint()
to obtain the CI , that is Wald's CI actually.
set.seed(12)
dta <- data.frame(
rsp = sample(c(TRUE, FALSE), 100, TRUE),
grp = factor(rep(c("A", "B"), each = 50), levels = c("B", "A")),
strata = factor(sample(c("C", "D"), 100, TRUE))
)
fit <- glm(rsp ~ grp, data = dta, family = binomial(link = "logit"))
exp(cbind(Odds_Ratio = coef(fit), confint(fit)))[-1, , drop = FALSE]
If we want to compute the odds ratio from the Cochran-Mantel-Haenszel test with stratified variables, I know there will be two approaches to handle it. One is mantelhaen.test()
function, another is conditional logistic regression like survival::clogit()
function. Given the results from those two way is not same, I'm going to compare with SAS and refer the documents to decide which one will be wrapped. As I know, tern
package use the survival::clogit()
to deal with the stratified CMH analysis.
set.seed(12)
dta <- data.frame(
rsp = sample(c(TRUE, FALSE), 100, TRUE),
grp = factor(rep(c("A", "B"), each = 50), levels = c("B", "A")),
strata1 = factor(sample(c("C", "D"), 100, TRUE)),
strata2 = factor(sample(c("E", "F"), 100, TRUE)),
strata3 = factor(sample(c("G", "H"), 100, TRUE))
)
Using mantelhaen.test()
function:
df <- dta %>%
count(grp, rsp, strata1, strata2, strata3)
tab <- xtabs(n ~ grp + rsp + strata1 + strata2 + strata3, data = df)
tb <- as.table(array(c(tab), dim = c(2, 2, 2 * 2 *2)))
mantelhaen.test(tb, correct = FALSE)
Using conditional logistic regression:
library(survival)
fit <- clogit(formula = rsp ~ grp + strata(strata1, strata2, strata3), data = dta)
exp(cbind(Odds_Ratio = coef(fit), confint(fit)))
Create a function to handle these cases, as shown below:
22
, number of responders is 4
, what is the response rate and corresponding 95% credible interval?Simply by 4/22=18%
to get the response rate, and qbeta(c(0.025, 0.975), shape1 = 4, shape2 = 18)
to get the 95% credible interval like (5%, 36%)
. There is no need for an additional new function.
This logic simulation should be wrapped into a function.
This case can be simply conducted by extraDistr::pbbinom()
function, like
N = 66
n = 25
nresp = 23
a = 1 + nresp
b = 1 + (n - nresp)
extraDistr::pbbinom(56 - nresp, size = N - n, alpha = a, beta = b, lower.tail = F)
This logic seems like can be conducted by dbeta()
function, but I'm not sure.
n <- 15
a <- 0.5
b <- 0.5
nresp <- 6
tag <- 0.3
pbeta(tag, nresp + a, n - nresp + b, lower.tail = FALSE)
I need a function to help me summarize the results from survfit()
and survdiff()
. For example, if the primary endpoint is PFS, I would like to know how many events and censors there are in each treatment, adding the median PFS, corresponding CI, PFS rate at different periods, and log-rank P-value. If I set the stratified factors, the output should also include the stratified results. Regarding to Cox model, I would like to know the HR and corresponding CI as well. The most important thing is that the above results should have the same method as SAS, so that this R function could be used as a QC role for monitoring.
s_get_surv()
to summarize the essential information for the survival analysis.
s_get_cox()
to summarize the essential information for the cox model.Update few functions:
s_surv_rate()
to analyze the survival rate.Choose which ADaM datasets will be examples for testing.
admiral
and admiralonco
package.random.cdisc.data
to create randomized ADaM datasets.Although I prefer the first option, there are too few responses in rs
domain. And there are also some logic errors in the random.cdisc.data
. So it seems that I have to create a dummy dataset separately.
In the current stage, preparing adrs
is a priority.
How do I conduct the MMRM analysis in R for superiority or non-inferiority trial design?
A brief summary can be seen at https://www.bioinfo-scrounger.com/archives/mmrm_hypothesis/.
So maybe a summary function could be better when I want to get a summary result. So simply wrap several steps into one function.
Well, I'm imagining that the S3 structure is more suitable. In this case, I can use the custom tidy method tidy.mmrm
for mmrm
summary results. Besides, how about the tidymodels
package?
And I also want to wrap the emmeans
functions inside, such as confint()
, test()
to get the CI and hypothesis testing.
The preliminary idea is to create a function called summarize_lsmeans()
, or other names like s_mmrm_lsmeans()
or s_get_lsmeans()
. Considering the lsmeans
can be computed by different models, such as mmrm
, ancova
and others, so we'd better define this function with corresponding classes.
Afterwards, the summarized function should return a class like stabiot.lsmeans
so that users can use the tidy()
function to get a tibble
table for downstream analysis if needed.
Thus the steps should be these:
emmeans()
, contrast()
and test()
from emmeans
.The BOR calculation is a very common analysis in oncology trials for solid tumor, so it's necessary to create a function. Maybe it can be used as a supplement code or for internal analysis.
Related documents are shown below.
https://www.pharmasug.org/proceedings/2023/QT/PharmaSUG-2023-QT-047.pdf
And
The following is the conversion to programming logic:
In the QC process, we always need to compare two or more datasets to check if there is any difference. The common demand is to compare the value, for example the response is identical or not.
Currently I know there is a package diffdf
can deal with this question excellently. But actually I don't need so much information to compare sometimes. Do I need to create a specific function or modify the functions of diffdf
?
A few updates are needed:
ref_start_window
and ref_interval
demonstrating how to calculate.Could I find out an appropriate method for survival simulation?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.