2016-04-06 7 views
2

。probを.007に設定して負の2項データを生成した後、glm.nb()適合から戻ってくる数値を返すが、不正な場合にのみ返る。glm.nb()の "prob"パラメータをどのように得ることができますか?

library(MASS) 
counts<-data.frame(as.matrix(rnbinom(10000, prob = .007, size = 247))) 
names(counts)<-"y" 

head(counts) 

fitted_model<-glm.nb(y ~ 1, data = counts, link="identity") 

#Theta is the shape parameter of the negative binomial distribution. So this is "r". 
r<-theta.ml(fitted_model$y, fitted(fitted_model))[1]  
# the parameter r is referred to as the “dispersion parameter” or “shape parameter” 

mu<-coef(fitted_model) #This is the mean 

# mu=prob*r/(1-prob) according to https://en.wikipedia.org/wiki/Negative_binomial_distribution 
# so prob = 1/(r + mu) ? 
1/(r + mu) # Wrong! This isn't the prob I used to generate th data! 
r/(r + mu) # Right! But why does this get me the correct value of prob? 

#This has hints: http://www.wright.edu/~thaddeus.tarpey/ES714glm.pdf 

適合モデルから「prob」の値を得るために不正行為をしたくないです。誰もがなぜr /(r + mu)= probを説明することができますか?

答えて

2

あなたは?NegBinomial

Gamma(x+n)/(Gamma(n) x!) p^n (1-p)^x 

で与えられた定義にWikipediaの定義

C(k+r-1,k) (1-p)^r p^k 

を比較する場合は、p1-pの役割が切り替わっていることがわかります。 NBを「1つの失敗の前に発生するn個の成功の確率」と定義すると、ウィキペディアはpを「失敗」の確率として定義し、Rはpを「成功」の確率として定義しています。 mu/(r+mu)ではなくから正しい結果が得られます。

+0

今、私は2つのことを学びました。この問題の解決策と、両方のシステムで常にpdf式を比較するルール。 – rwinkel2000

関連する問題