1

案例一:一个伽玛(我可以做到!)

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)

案例二:两个 Gamma(我做不到!)

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 之一!

4

1 回答 1

0

好吧,有一个众所周知的规则是如何用它们自己的 PDF 制作两个独立随机变量 (Z = X+Y) 之和的概率密度函数 (PDF)

PDF(z) = S PDF_x(t) * PDF_y(z-t) dt

S整合标志在哪里。不确定是否存在带有任何参数的 gamma 和的通用表达式。R中有一些包在上面的积分中进行数字卷积。

那是你要的吗?

更新

两个伽马的KS示例测试

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)
于 2016-04-17T01:17:17.167 回答