[英]How to improve a Zero-Inflated Negative Binomial regression model?
我想你做了一個擬合值的直方圖,所以這只會反映擬合的平均值,並且可能乘以零的比率,這取決於你使用的模型。 不應該重新創建該分布,因為您的數據的傳播方式已嵌入到離散參數中。
我們可以使用pscl
包中的示例:
library(pscl)
data("bioChemists")
fit <- hurdle(art ~ ., data = bioChemists,dist="negbin",zero.dist="binomial")
par(mfrow=c(1,2))
hist(fit$y,main="Observed")
hist(fit$fitted.values,main="Fitted")
如前所述,在此障礙模型中,您看到的擬合值是預測均值乘以為零的比率(請參閱此處的更多信息):
head(fit$fitted.values)
1 2 3 4 5 6
1.9642025 1.2887343 1.3033753 1.3995826 2.4560884 0.8783207
head(predict(fit,type="zero")*predict(fit,type="count"))
1 2 3 4 5 6
1.9642025 1.2887343 1.3033753 1.3995826 2.4560884 0.8783207
為了基於擬合模型模擬數據,我們提取參數:
Theta=fit$theta
Means=predict(fit,type="count")
Zero_p = predict(fit,type="prob")[,1]
具有模擬計數的功能:
simulateCounts = function(mu,theta,zero_p){
N = length(mu)
x = rnbinom(N,mu=mu,size=THETA)
x[runif(x)<zero_p] = 0
x
}
因此,多次運行此模擬以獲得值的范圍:
set.seed(100)
simulated = replicate(10,simulateCounts(Means,Theta,Zero_p))
simulated = unlist(simulated)
par(mfrow=c(1,2))
hist(bioChemists$art,main="Observed")
hist(simulated,main="simulated")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.