案例一:一个伽玛(我能做到!)
shape<-shape*10
scale<-scale/10
p_value_average_of_10_draws<-1-pgamma(q=average_of_10_draws, shape=shape, scale=scale, lower.tail = TRUE, log.p = FALSE)
案例二:两个伽马射线(我不能这么做!)
shape_A<-shape_A*10
scale_A<-scale_A/10
shape_B<-shape_B*10
scale_B<-scale_B/10
pgamma_A_and_B <-
pgamma(q=average_of_10_draws, shape=shape_A, scale=scale_A, lower.tail = TRUE, log.p = FALSE)*weight_A
+
pgamma(q=average_of_10_draws, shape=shape_B, scale=scale_B, lower.tail = TRUE, log.p = FALSE)*(1-weight_A)
p_value_average_of_10_draws<-1-pgamma_A_and_B
但这是错误的!
因为它假设所有十场平局都将从A或B中的一场中获得!
好吧,有一个众所周知的规则,如何用两个独立随机变量(Z=X+Y)的和的概率密度函数(PDF)制作它们自己的PDF
PDF(z) = S PDF_x(t) * PDF_y(z-t) dt
其中S
是积分符号。不确定具有任何参数的伽玛之和是否存在通用表达式。R中有一些包在上面的积分中进行数字卷积。
这就是你想要的吗?
更新
两个伽玛的K-S示例检验
library(ggplot2)
fitted.pdf <- function(x, w, a1, s1, a2, s2) {
w*dgamma(x, shape = a1, scale = s1) + (1.0-w)*dgamma(x, shape = a2, scale = s2)
}
fitted.cdf <- function(x, w, a1, s1, a2, s2) {
w*pgamma(x, shape = a1, scale = s1) + (1.0-w)*pgamma(x, shape = a2, scale = s2)
}
p <- ggplot(data = data.frame(x = 0), mapping = aes(x = x))
p <- p + stat_function(fun = function(x) fitted.pdf(x, w=0.6, a1=1.0, s1=1.0, a2=0.8, s2=1.2))
p <- p + stat_function(fun = function(x) fitted.cdf(x, w=0.6, a1=1.0, s1=1.0, a2=0.8, s2=1.2))
p <- p + xlim(0.0, 4.0) + ylim(0.0, 1.0)
print(p)
# sample 100 from exponential
x <- rexp(100)
# K-S test
q <- ks.test(x, y=function(x) fitted.cdf(x, w=0.6, a1=1.0, s1=1.0, a2=0.8, s2=1.2))
print(q)