在仅具有线性和二次项的逻辑回归中,如果我有一个线性系数和二次系数,我可以说在处有概率的转折点吗?
我可以将逻辑回归中包含的二次项解释为指示转折点吗?
机器算法验证
解释
罗吉特
多项式
2022-03-17 02:38:30
1个回答
是的你可以。
模型是
当不为零时,它在处有一个全局极值。
逻辑回归将这些系数估计为。因为这是一个最大似然估计(参数函数的 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)
}
其它你可能感兴趣的问题