• API
• FAQ
• Tools
• Archive
SHARE
TWEET Untitled a guest Mar 15th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. library(discreteRV)
2.
3. placebo.rate <- 0.5
4. mmm.rate <- 0.3
5. mmm.power <- power.prop.test(p1 = placebo.rate, p2 = mmm.rate, power = 0.8, alternative = "one.sided")
6. n <- as.integer(ceiling(mmm.power\$n))
7. patients <- seq(from = 0, to = n, by = 1)
8. placebo_distribution <- dbinom(patients, size = n, prob = placebo.rate)
9. mmm_distribution <- dbinom(patients, size = n, prob = mmm.rate)
10.
11. get_pmf <- function(p1, p2) {
12.   X1 <- RV(patients,p1, fractions = F)
13.   X2 <- RV(patients,p2, fractions = F)
14.   pmf <- joint(X1, X2, fractions = F)
15.   return(pmf)
16. }
17. extract <- function(string) {
18.   ints <- unlist(strsplit(string,","))
19.   x1 <- as.integer(ints)
20.   x2 <- as.integer(ints)
21.   return(x1-x2)
22. }
23. diff_prob <- function(pmf) {
24.   diff <- unname(sapply(outcomes(pmf),FUN = extract)/n)
25.   probabilities <- unname(probs(pmf))
26.   df <- data.frame(diff,probabilities)
27.   df <- aggregate(. ~ diff, data = df, FUN = sum)
28.   return(df)
29. }
30. most_likely_rate <- function(x) {
31.   x[which(x\$probabilities == max(x\$probabilities)),]\$diff
32. }
33.
34. mmm_rate_diffs <- diff_prob(get_pmf(mmm_distribution,placebo_distribution))
35. placebo_rate_diffs <- diff_prob(get_pmf(placebo_distribution,placebo_distribution))
36. plot(mmm_rate_diffs\$diff,mmm_rate_diffs\$probabilities * 100, type = "l", lty = 2, xlab = "Rate difference", ylab = "# of trials per 100", main = paste("Trials with",n,"patients per treatment arm",sep = " "))
37. lines(placebo_rate_diffs\$diff, placebo_rate_diffs\$probabilities * 100, lty = 1, xaxs = "i")
38. abline(v = c(most_likely_rate(placebo_rate_diffs), most_likely_rate(mmm_rate_diffs)), lty = c(1,2))
39. legend("topleft", legend = c("Alternative hypothesis", "Null hypothesis"), lty = c(2,1))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top