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つのことを学びました。この問題の解決策と、両方のシステムで常にpdf式を比較するルール。 – rwinkel2000