Answers:
是的你可以。
该模型是
当不为零时,它在x =-\ beta_1 /(2 \ beta_2)处具有全局极值。
Logistic回归估计这些系数为。因为这是最大似然估计(并且参数函数的ML估计与估计的功能相同),所以我们可以估计极值的位置为。
该估计的置信区间将很重要。 对于那些足够大的渐进最大似然理论应用数据集,我们可以找到这个区间终点重新表达的形式
并找出在对数似然降低太多之前可以改变多少。渐近地,“太多”是具有一个自由度的卡方分布的分位数的一半。
如果的范围覆盖峰的两侧并且值中有足够数量的和响应来描绘该峰,则该方法将很好地工作。否则,峰的位置将高度不确定,并且渐近估计可能不可靠。
R
执行此操作的代码如下。可以在模拟中使用它来检查置信区间的覆盖范围是否接近预期的覆盖范围。请注意,真实峰值是并且-通过查看直方图的下一行-如何了解大多数下置信度限制小于真实值,以及大多数置信度上限如何大于真实值,正如我们希望的那样。在此示例中,预期的覆盖率是,实际的覆盖率(在逻辑回归未收敛的情况下折算为四)为,表明该方法有效(对于模拟的数据类型)这里)。
n <- 50 # Number of observations in each trial
beta <- c(-1,2,2) # Coefficients
x <- seq(from=-3, to=3, length.out=n)
y0 <- cbind(rep(1,length(x)), x, x^2) %*% beta
# Conduct a simulation.
set.seed(17)
sim <- replicate(500, peak(x, rbinom(length(x), 1, logistic(y0)), alpha=0.05))
# Post-process the results to check the actual coverage.
tp <- -beta[2] / (2 * beta[3])
covers <- sim["lcl",] <= tp & tp <= sim["ucl",]
mean(covers, na.rm=TRUE) # Should be close to 1 - 2*alpha
# Plot the distributions of the results.
par(mfrow=c(2,2))
plot(x, logistic(y0), type="l", lwd=2, col="#4040d0", main="Simulated Data",ylim=c(0,1))
points(x, rbinom(length(x), 1, logistic(y0)), pch=19)
hist(sim["peak.x",], main="Estimates"); abline(v=tp, col="Red")
hist(sim["lcl",], main="Lower Confidence Limits"); abline(v=tp, col="Red")
hist(sim["ucl",], main="Upper Confidence Limits"); abline(v=tp, col="Red")
logistic <- function(x) 1 / (1 + exp(-x))
peak <- function(x, y, alpha=0.05) {
#
# Estimate the peak of a quadratic logistic fit of y to x
# and a 1-alpha confidence interval for that peak.
#
logL <- function(b) {
# Log likelihood.
p <- sapply(cbind(rep(1, length(x)), x, x*x) %*% b, logistic)
sum(log(p[y==1])) + sum(log(1-p[y==0]))
}
f <- function(gamma) {
# Deviance as a function of offset from the peak.
b0 <- c(b[1] - b[2]^2/(4*b[3]) + b[3]*gamma^2, -2*b[3]*gamma, b[3])
-2.0 * logL(b0)
}
# Estimation.
fit <- glm(y ~ x + I(x*x), family=binomial(link = "logit"))
if (!fit$converged) return(rep(NA,3))
b <- coef(fit)
tp <- -b[2] / (2 * b[3])
# Two-sided confidence interval:
# Search for where the deviance is at a threshold determined by alpha.
delta <- qchisq(1-alpha, df=1)
u <- sd(x)
while(fit$deviance - f(tp+u) + delta > 0) u <- 2*u # Find an upper bound
l <- sd(x)
while(fit$deviance - f(tp-l) + delta > 0) l <- 2*l # Find a lower bound
upper <- uniroot(function(gamma) fit$deviance - f(gamma) + delta,
interval=c(tp, tp+u))
lower <- uniroot(function(gamma) fit$deviance - f(gamma) + delta,
interval=c(tp-l, tp))
# Return a vector of the estimate, lower limit, and upper limit.
c(peak=tp, lcl=lower$root, ucl=upper$root)
}