gpt4 book ai didi

r - R 中逻辑模型交互的优势比和 95% CI

转载 作者:行者123 更新时间:2023-12-05 06:11:55 25 4
gpt4 key购买 nike

我正在运行一个在二分变量和连续变量之间存在交互作用的逻辑模型:

aidslogit<-glm(cd4~ AGE+ANTIRET+AGE*ANTIRET, data = aidsdata, family = "binomial")
summary(aidslogit, digits=3)

Deviance Residuals:
Min 1Q Median 3Q Max
-1.870 -1.190 0.771 1.056 1.586

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.599565 0.313241 -1.914 0.0556 .
AGE -0.008340 0.008849 -0.942 0.3459
ANTIRET 1.308591 0.198031 6.608 3.9e-11 ***
AGE:ANTIRET -0.013547 0.005507 -2.460 0.0139 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

Null deviance: 9832.8 on 7264 degrees of freedom
Residual deviance: 9434.9 on 7261 degrees of freedom
(654 observations deleted due to missingness)
AIC: 9442.9

Number of Fisher Scoring iterations: 4

我想做的是计算不同年龄段(即 20 岁、30 岁和 40 岁)使用抗逆转录病毒药物的 OR 和 95% CI。我想我可以输出协方差并手动完成,但它似乎必须有一种方法可以自动完成。

比较:

在 SAS 中它看起来像这样:

proc logistic data=aidsdata descending;
model cd4=antiret age antiret*age;
oddsratio antiret /at (age=20 30 40);
run;

最佳答案

对于没有交互作用的回归,每个系数的优势比为 exp(coef(aidslogit))。这些是给定变量中单位变化的优势比。

但是对于交互作用,您需要同时包含主效应和交互作用。在这种情况下,AGE 是第二个系数,AGE:ANTIRET 是第四个系数,因此:

# Odds ratio for a one-unit change in AGE when ANTIRET=0
OR = exp(coef(aidslogit)[2])

# Odds ratio for a one-unit change in AGE when ANTIRET=1
OR = exp(coef(aidslogit)[2] + coef(aidslogit)[4])

要计算其他 AGE 差异的优势比,请将系数乘以该数量。例如,要获得 AGE 10 个单位变化的优势比:

# Odds ratio for a 10-unit change in AGE when ANTIRET=0
OR = exp(10 * coef(aidslogit)[2])

# Odds ratio for a 10-unit change in AGE when ANTIRET=1
OR = exp(10 * (coef(aidslogit)[2] + coef(aidslogit)[4]))

关于r - R 中逻辑模型交互的优势比和 95% CI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63748817/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com