This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rootSolve) | |
pvfun0 <- function(p, x, n){ | |
pu <- pbinom(x-1, n, p, lower.tail = FALSE) | |
pl <- pbinom(x, n, p, lower.tail = TRUE) | |
2*pmin(pl, pu) | |
} | |
sol0 <-uniroot.all(f = function(p){pvfun0(p,5,10)-0.05}, | |
interval = c(0.1,0.9)) | |
res_b <- binom.test(5, 10) | |
print(res_b$conf.int) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rootSolve) | |
LRtest <- function(p,x,n){ | |
phat <- x/n | |
lp <- 2*(dbinom(x, n, phat ,log = TRUE)- | |
dbinom(x, n, p ,log = TRUE)) | |
pchisq(lp, 1, lower.tail = FALSE) | |
} | |
set.seed(123) | |
n <- 20 | |
x <- rbinom(1, n, 0.5) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set.seed(1234) | |
n <- 20 | |
x <- rbinom(1,n,0.5) | |
print(x) | |
probbeta <- function(p,x,n){ | |
ahat <- x + .5 | |
bhat <- n - x + .5 | |
pl <- pbeta(p, ahat, bhat, lower.tail=TRUE) | |
pu <- pbeta(p, ahat, bhat, lower.tail=FALSE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set.seed(1234) | |
n <- 12 | |
x <- rbinom(1,n,0.5) | |
res_p <- prop.test(x, n, p = 0.5, correct = FALSE) | |
CI_score <- function(x, n, level){ | |
z <- qnorm(0.5*(1-level), lower.tail = FALSE) | |
phat <- x/n | |
t_1 <- phat+(z^2)/(2*n) | |
t_2 <- sqrt(z^2+4*n*phat*(1-phat))*(z/(2*n)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plot.miniLineTable <- function(tab,...){ | |
oldpar <- graphics::par(no.readonly = TRUE) | |
N <- length(tab$y) | |
graphics::par(mar = c(4, 10, 0, 2), oma = rep(1, 4)) | |
graphics::layout(mat = cbind(N+1,1:N,1:N), respect = FALSE) | |
for (i in 1:N) { | |
tmpy <- tab$y[[i]] | |
matplot(tmpy, type = "l", lty=1, xaxt="n", yaxt="n", | |
xlab = "", ylab = "", frame.plot = FALSE, | |
col=1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(deSolve) | |
library(ggplot2) | |
RNAvelo <- function(Time, State, Pars, input) { | |
with(as.list(c(State, Pars)), { | |
import <- input(Time) | |
du <- import - beta * U | |
ds <- beta * U - gamma * S | |
return(list(c(du, ds))) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Distributions | |
using Plots | |
function Chisqtest(tab, beta0) | |
beta = log(tab[2,2]) - log(tab[2,1]) - (log(tab[1,2])-log(tab[1,1])) | |
V = sum(inv.(tab)) | |
return ccdf(Chisq(1.0), (beta-beta0)^2/V) | |
end | |
function Fishertest(X, phi) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Distributions | |
using Plots | |
function Fishertest(X, phi) | |
cs = sum(X, dims=1) | |
rs = sum(X, dims=2) | |
f(x, phi) = pdf(FisherNoncentralHypergeometric(cs[1],cs[2],rs[1], exp(phi)), x) | |
prob = f.(0:cs[1], phi) | |
return sum(prob[prob .<= prob[X[1,1]+1]]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(MCMCpack) | |
library(exact2x2) | |
library(ggplot2) | |
library(patchwork) | |
X <-matrix(c(12,5,6,12), nrow=2) | |
fpfun <- function(phi){exact2x2::exact2x2(x=X, or=exp(phi))$p.value} | |
rs <- rowSums(X) | |
cs <- colSums(X) | |
flfun <- function(phi){MCMCpack::dnoncenhypergeom(x = X[1,1], cs[1],cs[2],rs[1], exp(phi))} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
set.seed(123) | |
x <- rweibull(50,1.5) - log(2)^(1/1.5) | |
qweibull(0.5,1.5)- log(2)^(1/1.5) #中央値が0の分布 | |
sx <- jitter(sort(x)) #ちょうど0をなくすため | |
pv_w <- sapply(sx,function(m)wilcox.test(x, mu=m)$p.value) | |
pv_s <- sapply(sx,function(m)binom.test(sum(x>m), length(x))$p.value) | |
df4p <- data.frame(x=x,sx=sx,sign=pv_s,wilcox=pv_w) | |
m <- median(x) |