![](/img/trans.png)
[英]Stargazer for reporting odds ratios in logit report wrong significance stars
[英]Odds ratios instead of logits in stargazer() LaTeX output
當使用 stargazer 在邏輯回歸對象上創建 LaTeX 表時,標准行為是輸出每個模型的 logit 值。 是否有可能獲得 exp(logit) 代替? 也就是說,我可以得到賠率比嗎?
在觀星者文檔中,以下提到了“Coef”參數,但我不明白這是否可以啟用 exp(logits)。
Coef:將替換每個模型的默認系數值的數值向量列表。 元素名稱將用於將系數與單個協變量匹配,因此應匹配協變量名稱。 NULL 向量表示對於給定模型,應使用默認系數集。 相比之下,NA 向量意味着模型的所有系數都應留空。
根據 2014 年的共生評論,較新版本的 ''stargazer'' 具有選項 ''apply.*'' 用於 ''coef'' ''se'' ''t'' ''p'' 和 '' ci'' 允許直接轉換這些統計數據。
apply.coef a function that will be applied to the coefficients.
apply.se a function that will be applied to the standard errors.
apply.t a function that will be applied to the test statistics.
apply.p a function that will be applied to the p-values.
apply.ci a function that will be applied to the lower and upper bounds of the confidence intervals.
這意味着您可以直接使用...
stargazer(model,
apply.coef = exp,
apply.se = exp)
編輯:然而,我注意到,簡單地對 CI 取冪並不能給出您所期望的。
編輯:您可以使用此處描述的方法獲得正確的 CI。
stargazer
允許你替換很多東西,因變量標簽,協變量標簽等等。 為了替代那些需要提供變量標簽向量的變量,這樣做是為了具有可發布的行名稱,而不是默認情況下來自R
的變量名稱。
因此,為了獲得優勢比,您需要向stargazer
提供優勢比向量。 你如何獲得那個向量? 其實很容易。 假設您的模型名為model
,那么您的代碼是:
coef.vector <- exp(model$coef)
stargazer(model,coef=list(coef.vector))
如果您的表中有多個模型,那么應該擴展列表,例如coef=list(coef.vector1,coef.vector2,...)
,其中列表中的所有向量都將從與上述類似的冪運算中導出。
因此,問題在於您想要顯示(非對數)優勢比,但保留基於基礎線性模型的測試統計數據。 默認情況下,當您使用其中一種“應用”方法時,例如apply.coef = exp
,stargazer 將重新計算 t 統計數據和 p 值。 我們不想那樣。 此外,標准誤差在對數基礎上,但我們不能只是對它們取冪。 我的首選方法是:
在代碼中,這是:
stargazer(model, apply.coef=exp, t.auto=F, p.auto=F, report = "vct*")
各種帖子中有一些正確的答案,但似乎沒有一個能把它們放在一起。 假設如下:
glm_out <- glm(Y ~ X, data=DT, family = "binomial")
對於邏輯回歸,回歸系數 (b1) 是每單位 X 增加 Y 的對數幾率的估計增加。 因此,要獲得優勢比,我們只需使用 exp 函數:
OR <- exp(coef(glm_out))
# pass in coef directly
stargazer(glm_out, coef = list(OR), t.auto=F, p.auto=F)
# or, use the apply.coef option
stargazer(glm_out, apply.coef = exp, t.auto=F, p.auto=F)
您不能簡單地使用apply.se = exp
來獲取 Std。 優勢比的錯誤
相反,您必須使用函數: Std.Error.OR = OR * SE(coef)
# define a helper function to extract SE from glm output
se.coef <- function(glm.output){sqrt(diag(vcov(glm.output)))}
# or, you can use the arm package
se.coef <- arm::se.coef
#Get the odds ratio
OR <- exp(coef(glm_out))
# Then, we can get the `StdErr.OR` by multiplying the two:
Std.Error.OR <- OR * se.coef(glm_out)
所以,為了讓它進入觀星者,我們使用以下內容:
# using Std Errors
stargazer(glm_out, coef=list(OR), se = list(Std.Error.OR), t.auto=F, p.auto=F)
優勢比設置中的置信區間不對稱。 所以,我們不能只做 ±1.96*SE(OR) 來獲得 CI。 相反,我們可以從原始對數賠率exp(coef ± 1.96*SE)
計算它。
# Based on normal distribution to compute Wald CIs:
# we use confint.default to obtain the conventional confidence intervals
# then, use the exp function to get the confidence intervals
CI.OR <- as.matrix(exp(confint.default(glm_out)))
所以,為了讓它進入觀星者,我們使用以下內容:
# using ci.custom
stargazer(glm_out, coef=list(OR), ci.custom = list(CI.OR), t.auto=F, p.auto=F, ci = T)
# using apply.ci
stargazer(glm_out, apply.coef = exp, apply.ci = exp, t.auto=F, p.auto=F, ci = T)
不要使用優勢比的置信區間來計算重要性(請參閱底部的注釋和參考)。 相反,您可以使用對數賠率來做到這一點:
z <- coef(glm_out)/se.coef(glm_out)
並且,使用它來獲得顯着性檢驗的 p.values:
pvalue <- 2*pnorm(abs(coef(glm_out)/se.coef(glm_out)), lower.tail = F)
(來源: https : //data.princeton.edu/wws509/r/c3s1 )
有關統計測試的更詳細討論,請參閱此鏈接: https : //stats.stackexchange.com/questions/144603/why-do-my-p-values-difer-between-logistic-regression-output-chi-squared-test
然而,重要的是要注意,與 p 值不同,95% CI 不報告度量的統計顯着性。 在實踐中,如果 95% CI 不與空值重疊(例如 OR=1),則它通常用作統計顯着性存在的代理。 然而,將跨越零值的 95% CI 的 OR 解釋為表明暴露與結果之間缺乏關聯的證據是不合適的。 來源:解釋優勢比
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.