2014-03-06 73 views
0

泊松迴歸看起來如在我的R-代碼如下:計算置信區間

poissmod <- glm(aerobics$y ~ factor(aerobics$x1) + factor(aerobics$x2) + aerobics$x3 + aerobics$x4, family = poisson) 
poissmod 

現在,我必須計算用於因子aerobics$x1的置信區間(在模型中沒有aerobics$x1因爲這不重要)。

這看起來很容易,但我不熟悉的R和我「找不到任何地方的答案...

任何人誰可以幫我嗎?

非常感謝!

回答

2

參見例如在MASSconfint函數(http://stat.ethz.ch/R-manual/R-devel/library/MASS/html/confint.html):

ldose <- rep(0:5, 2) 
numdead <- c(1, 4, 9, 13, 18, 20, 0, 2, 6, 10, 12, 16) 
sex <- factor(rep(c("M", "F"), c(6, 6))) 
SF <- cbind(numdead, numalive = 20 - numdead) 
budworm.lg0 <- glm(SF ~ sex + ldose - 1, family = binomial) 
confint(budworm.lg0) 
confint(budworm.lg0, "ldose") 

的例子爲邏輯迴歸,但是這也將工作爲泊松迴歸。

這裏是從泊松迴歸(https://stat.ethz.ch/R-manual/R-devel/library/stats/html/confint.html)的stats包文檔又如:

## from example(glm) 
counts <- c(18,17,15,20,10,20,25,13,12) 
outcome <- gl(3, 1, 9); treatment <- gl(3, 3) 
glm.D93 <- glm(counts ~ outcome + treatment, family = poisson()) 
confint(glm.D93) # needs MASS to be present on the system 
confint.default(glm.D93) # based on asymptotic normality 
+0

謝謝你的答案。我已經試過了,給出了以下R代碼:confint(poissmod2,'有氧運動$ x1',等級= 0.95)。但是,我得到一個錯誤:參數的長度爲零... – user3387899

+0

歡迎來到SO。這些命令基本上工作。如果您的代碼存在其他問題,我可以幫助您提供可重現的示例。看到http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – majom

+0

那麼,代碼似乎並沒有爲我工作......我不斷收到錯誤:'論點是長度爲零「。所以我的代碼仍然有問題? – user3387899