逻辑回归中不同因素的致死剂量 (LD50)
Lethal Dose (LD50) for the different factors in a logistic regression
我有一个逻辑回归模型,其中包含一个连续变量和一个具有各种 levels/factors 的定性变量。有没有办法计算每个因素的 LD50?
library(dplyr)
library(ggeffects)
library(MASS)
# Produce a table with data
set.seed(321)
x1 <- rnorm(400)
x2 <- 3*x1^3 + 2*x1^2 + x1 + 1
x3 <- 1/(1 + exp(-x2))
x4 = rbinom(400, 1, x3)
dt <- tibble(binary = x4,
continuous = x1,
qualitative = sample(c("white", "pink", "lime"), 400, TRUE))
# Logistic model
mdl <- glm(binary ~ continuous + qualitative, family = "binomial", data = dt)
# Calculate LD50, which gives the lethal dose for the whole model
dose.p(mdl) # -0.58 ± 0.11 se
# Plot regression model by factor of the qualitative variable
newdat <- ggpredict(mdl, terms = c("continuous[all]", "qualitative"))
plot(newdat)
我如何计算每个因素的 LD50 ± SE(石灰的 LD50、粉红色的 LD50 等)?
下面为每个因素拟合二元模型与连续模型,并得出 LD50 和 SE:
get_LD50 = function(fit){
data.frame(
LD50 = dose.p(fit)[1],
SE = attributes(dose.p(fit))$SE[,1]
)
}
dt %>% group_by(qualitative) %>%
do(get_LD50(glm(binary ~ continuous, family = "binomial", data = .)))
# A tibble: 3 x 3
# Groups: qualitative [3]
qualitative LD50 SE
<chr> <dbl> <dbl>
1 lime -0.578 0.115
2 pink -0.479 0.104
3 white -0.392 0.116
如果您在统计方面需要更复杂的东西,您必须澄清
我有一个逻辑回归模型,其中包含一个连续变量和一个具有各种 levels/factors 的定性变量。有没有办法计算每个因素的 LD50?
library(dplyr)
library(ggeffects)
library(MASS)
# Produce a table with data
set.seed(321)
x1 <- rnorm(400)
x2 <- 3*x1^3 + 2*x1^2 + x1 + 1
x3 <- 1/(1 + exp(-x2))
x4 = rbinom(400, 1, x3)
dt <- tibble(binary = x4,
continuous = x1,
qualitative = sample(c("white", "pink", "lime"), 400, TRUE))
# Logistic model
mdl <- glm(binary ~ continuous + qualitative, family = "binomial", data = dt)
# Calculate LD50, which gives the lethal dose for the whole model
dose.p(mdl) # -0.58 ± 0.11 se
# Plot regression model by factor of the qualitative variable
newdat <- ggpredict(mdl, terms = c("continuous[all]", "qualitative"))
plot(newdat)
我如何计算每个因素的 LD50 ± SE(石灰的 LD50、粉红色的 LD50 等)?
下面为每个因素拟合二元模型与连续模型,并得出 LD50 和 SE:
get_LD50 = function(fit){
data.frame(
LD50 = dose.p(fit)[1],
SE = attributes(dose.p(fit))$SE[,1]
)
}
dt %>% group_by(qualitative) %>%
do(get_LD50(glm(binary ~ continuous, family = "binomial", data = .)))
# A tibble: 3 x 3
# Groups: qualitative [3]
qualitative LD50 SE
<chr> <dbl> <dbl>
1 lime -0.578 0.115
2 pink -0.479 0.104
3 white -0.392 0.116
如果您在统计方面需要更复杂的东西,您必须澄清