一般各種分析其實都是有一定的數(shù)學模型和假設的,有些也相應對輸入數(shù)據(jù)的分布有一定要求。如果不確定自己數(shù)據(jù)是否符合要求疚漆,最好先檢測一下甚脉。比如有時候你糾結使用 FPKM 還是 log2(FPKM + 1) 猴凹,此時查半天資料或許不如自己看看2個數(shù)據(jù)分布的區(qū)別土至。
R包 fitdistrplus 函數(shù) fitdist
檢驗非刪失數(shù)據(jù)的一元分布毡庆,相應的 fitdistcens
則用于檢驗刪失數(shù)據(jù)蝇刀。函數(shù)默認參數(shù):
fitdist(data, distr, method = c("mle", "mme", "qme", "mge"), start=NULL, fix.arg=NULL, discrete, keepdata = TRUE, keepdata.nb=100, ...)
部分參數(shù)解釋
- data: 檢驗的數(shù)據(jù),是個向量切诀。
- distr: 檢驗的分布名。
- method: 檢驗擬合的方法认臊,"mle"代表"maximum likelihood estimation"(最大似然估計),"mme"代表"moment matching estimation"(矩估計),"qme"代表"quantile matching estimation","mge"代表"maximum goodness-of-estimation"。
-
discrete: 是否為離散型分布栈源。如果不設置會根據(jù)
distr
參數(shù)來自動設定,在distr
為 "binom", "nbinom", "geom", "hyper", "pois" 這些值時為TRUE
否則FALSE
伶棒。
下面給出可以使用的 distr
參數(shù)分布名字眯搭。所以如果你想檢驗泊松分布,那么使用 "pois" 而不是 "Poisson" 盗痒。
Distribution | Name |
---|---|
beta | beta |
binomial | binom |
Cauchy | cauchy |
chi-squared | chisq |
exponential | exp |
F | f |
gamma | gamma |
geometric | geom |
hypergeometric | hyper |
log-normal | lnorm |
logistic | logis |
negative binomial | nbinom |
normal | norm |
Poisson | pois |
signed rank | signrank |
Student's t | t |
uniform | unif |
Weibull | weibull |
Wilcoxon | wilcox |
"Talk is cheap" 讓我們看看代碼實例梦重。數(shù)據(jù)采用R自帶的 lung
數(shù)據(jù)集除师。
> head(lung, n = 3)
inst time status age sex ph.ecog ph.karno pat.karno meal.cal wt.loss
1 3 306 2 74 1 1 90 100 1175 NA
2 3 455 2 68 1 0 90 90 1225 15
3 3 1010 1 56 1 0 90 90 NA 15
檢驗一下病人年齡分布。比較正態(tài)分布 norm
和對數(shù)正態(tài)分布 lnorm
哪個模型更適合。
正態(tài)分布
> fitNorm <- fitdist(lung$age, "norm", method = "mme")
> summary(fitNorm)
Fitting of the distribution ' norm ' by matching moments
Parameters :
estimate
mean 62.447368
sd 9.053537
Loglikelihood: -825.8374 AIC: 1655.675 BIC: 1662.534
> plot(fitNorm)
正態(tài)分布
對數(shù)正態(tài)分布
> fitLnorm <- fitdist(lung$age, "lnorm", method = "mme")
> summary(fitLnorm)
Fitting of the distribution ' lnorm ' by matching moments
Parameters :
estimate
meanlog 4.1239236
sdlog 0.1442254
Loglikelihood: -835.8495 AIC: 1675.699 BIC: 1682.558
> plot(fitLnorm)
對數(shù)正態(tài)分布
返回的 AIC
, BIC
之類的參數(shù)我沒搞懂入宦,也不想太深究汹忠。從兩個分布的圖片來看铅乡,正態(tài)分布要好于對數(shù)正態(tài)分布挚赊。
[參考]
An Introduction to R
https://cran.r-project.org/web/packages/fitdistrplus/vignettes/FAQ.html