gpt4 book ai didi

r - 具有定量和定性解释变量之间相互作用的多元 Logistic 回归

转载 作者:行者123 更新时间:2023-12-04 18:03:56 26 4
gpt4 key购买 nike

作为后续 this question ,我拟合了具有定量和定性解释变量之间相互作用的多元 Logistic 回归。 MWE如下:

Type  <- rep(x=LETTERS[1:3], each=5)
Conc <- rep(x=seq(from=0, to=40, by=10), times=3)
Total <- 50
Kill <- c(10, 30, 40, 45, 38, 5, 25, 35, 40, 32, 0, 32, 38, 47, 40)

df <- data.frame(Type, Conc, Total, Kill)

fm1 <-
glm(
formula = Kill/Total~Type*Conc
, family = binomial(link="logit")
, data = df
, weights = Total
)

summary(fm1)

Call:
glm(formula = Kill/Total ~ Type * Conc, family = binomial(link = "logit"),
data = df, weights = Total)

Deviance Residuals:
Min 1Q Median 3Q Max
-4.871 -2.864 1.204 1.706 2.934

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.65518 0.23557 -2.781 0.00541 **
TypeB -0.34686 0.33677 -1.030 0.30302
TypeC -0.66230 0.35419 -1.870 0.06149 .
Conc 0.07163 0.01152 6.218 5.04e-10 ***
TypeB:Conc -0.01013 0.01554 -0.652 0.51457
TypeC:Conc 0.03337 0.01788 1.866 0.06201 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

Null deviance: 277.092 on 14 degrees of freedom
Residual deviance: 96.201 on 9 degrees of freedom
AIC: 163.24

Number of Fisher Scoring iterations: 5

anova(object=fm1, test="LRT")

Analysis of Deviance Table

Model: binomial, link: logit

Response: Kill/Total

Terms added sequentially (first to last)


Df Deviance Resid. Df Resid. Dev Pr(>Chi)
NULL 14 277.092
Type 2 6.196 12 270.895 0.04513 *
Conc 1 167.684 11 103.211 < 2e-16 ***
Type:Conc 2 7.010 9 96.201 0.03005 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


df$Pred <- predict(object=fm1, data=df, type="response")

df1 <- with(data=df,
expand.grid(Type=levels(Type)
, Conc=seq(from=min(Conc), to=max(Conc), length=51)
)
)
df1$Pred <- predict(object=fm1, newdata=df1, type="response")

library(ggplot2)
ggplot(data=df, mapping=aes(x=Conc, y=Kill/Total, color=Type)) + geom_point() +
geom_line(data=df1, mapping=aes(x=Conc, y=Pred), linetype=2) +
geom_hline(yintercept=0.5,col="gray")

enter image description here

我要计算 LD50 , LD90LD95与他们的置信区间。由于相互作用很重要,所以我想计算 LD50 , LD90LD95每个 Type (A, B, and C) 的置信区间分别地。

LD 代表 lethal dose.它是杀死 X% (LD50 = 50%) 测试群体所需的物质量。

已编辑 Type是代表不同类型药物的定性变量, Conc是代表不同药物浓度的定量变量。

最佳答案

您使用 drc适合逻辑剂量 react 模型的软件包。

先拟合模型

require(drc)
mod <- drm(Kill/Total ~ Conc,
curveid = Type,
weights = Total,
data = df,
fct = L.4(fixed = c(NA, 0, 1, NA)),
type = 'binomial')

这里 curveid=指定数据的分组和 fct=指定一个 4 参数逻辑函数,下键和上键的参数固定为 0 和 1。

注意与 glm 的区别可以忽略不计:
df2 <- with(data=df,
expand.grid(Conc=seq(from=min(Conc), to=max(Conc), length=51),
Type=levels(Type)))
df2$Pred <- predict(object=mod, newdata = df2)

这是与 glm 预测差异的直方图
hist(df2$Pred - df1$Pred)

enter image description here

从模型估计有效剂量(和 CI)

这很容易使用 ED()功能:
ED(mod, c(50, 90, 95), interval = 'delta')

Estimated effective doses
(Delta method-based confidence interval(s))

Estimate Std. Error Lower Upper
A:50 9.1468 2.3257 4.5885 13.705
A:90 39.8216 4.3444 31.3068 48.336
A:95 50.2532 5.8773 38.7338 61.773
B:50 16.2936 2.2893 11.8067 20.780
B:90 52.0214 6.0556 40.1527 63.890
B:95 64.1714 8.0068 48.4784 79.864
C:50 12.5477 1.5568 9.4963 15.599
C:90 33.4740 2.7863 28.0129 38.935
C:95 40.5904 3.6006 33.5334 47.648

对于每组,我们使用 CI 获得 ED50、ED90 和 ED95。

关于r - 具有定量和定性解释变量之间相互作用的多元 Logistic 回归,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36065327/

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