[英]Why `x` is now the mixture of these five gamma distributions from the following R code?
[英]Sampling from a mixture of two Gamma distributions
我的意圖是使用名為bmixture
的程序包從兩個混合且嚴重右偏的 Gamma 分布生成樣本。 https://stats.stackexchange.com/questions/226834/sampling-from-a-mixture-of-two-gamma-distributions提供了一些示例。 例如,我可以使用以下內容,盡管分布並沒有真正傾斜(相反它們看起來很正常)。
library(bmixture)
set.seed(345)
nn <- 10000
wt <- c(0.85,0.20) #weight2
mu <- c(20,70)
sd <- c(1,1.2)
x <- rmixgamma(n=nn,weight=wt,alpha=mu,beta=sd)
hist(x, breaks = 40, freq=FALSE)
輸出:
如何結合偏度參數? 非常感謝任何幫助!
您沒有正確使用參數。 alpha
是形狀參數,其中較低的值會增加偏斜(1 的形狀給出指數分布,較高的數字傾向於正態分布),而beta
是速率參數,其中較高的值會降低均值。 (請參閱此處使用形狀 α 和速率 β 進行表征。 )
伽馬分布的均值是alpha/beta
,標准差是sqrt(alpha/beta^2)
。 要獲得目標均值和標准差,您需要c(400, 3402)
的形狀參數和c(20, 48.61)
的速率參數。 這些形狀參數將導致在合理的樣本量下無法與正態分布區分開來的分布。
要獲得正偏分布,您需要相當低的shape
參數:
library(bmixture)
set.seed(345)
nn <- 10000
wt <- c(0.80,0.20)
shape <- c(3, 30)
rate <- shape / c(20, 70)
x <- rmixgamma(n = nn, weight = wt, alpha = shape, beta = rate)
hist(x, breaks = 40, freq = FALSE)
創建於 2022-12-14,使用reprex v2.0.2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.