对于我的学士论文,我正在尝试对来自调查的恒定总和数据应用线性中值回归模型(参见 A.Blass (2008) 的公式)。这是重新创建 A. Blass 等人 (2008) 提出的概率诱导方法的尝试 -使用诱导选择概率来估计随机效用模型:电力可靠性的偏好
我的因变量是常数总和分配的对数赔率转换。使用以下公式计算:
PE_raw <- PE_raw %>% group_by(sys_RespNum, Task) %>% mutate(LogProb = c(log(Response[1]/Response[1]),
log(Response[2]/Response[1]),
log(Response[3]/Response[1])))
我的自变量是交货成本、最小订单数量和交货窗口,每个分类变量都有级别 0、1、2 和 3。这里,级别 0 表示无选项。
我尝试运行以下分位数回归(使用 R 的 quantreg 包):
LAD.factor <- rq(LogProb ~ factor(`Delivery costs`) + factor(`Minimum order quantity`) + factor(`Delivery window`) + factor(NoneOpt), data=PE_raw, tau=0.5)
但是,我遇到了以下表明奇点的错误:
Error in rq.fit.br(x, y, tau = tau, ...) : Singular design matrix
我进行了线性回归并应用了 R 的别名函数以进行进一步调查。这告诉我三个完美多重共线性的案例:
- 最小订货量 3 = 交货成本 1 + 交货成本 2 + 交货成本 3 - 最小订货量 1 - 最小订货量 2
- 交付窗口 3 = 交付成本 1 + 交付成本 2 + 交付成本 3 - 交付窗口 1 - 交付窗口 2
- NoneOpt = 拦截 - 交付成本 1 - 交付成本 2 - 交付成本 3
事后看来,这些案例都是有道理的。当 R 二分分类变量时,您通过构造得到这些结果,交付成本 1 + 交付成本 2 + 交付成本 3 = 1 和最小订货量 1 + 最小订货量 2 + 最小订货量 3 = 1。重写给出了第一个公式。
它看起来像一个经典的假陷阱。为了解决这个问题,我尝试手动对数据进行二分法并使用以下公式:
LM.factor <- rq(LogProb ~ Delivery.costs_1 + Delivery.costs_2 + Minimum.order.quantity_1 + Minimum.order.quantity_2 + Delivery.window_1 + Delivery.window_2 + factor(NoneOpt), data=PE_dichomitzed, tau=0.5)
我现在得到以下信息,而不是错误消息:
Warning message:
In rq.fit.br(x, y, tau = tau, ...) : Solution may be nonunique
使用汇总功能时:
> summary(LM.factor)
Error in base::backsolve(r, x, k = k, upper.tri = upper.tri, transpose = transpose, :
singular matrix in 'backsolve'. First zero in diagonal [2]
In addition: Warning message:
In summary.rq(LM.factor) : 153 non-positive fis
有人熟悉这个问题吗?我正在寻找替代解决方案。也许我在使用 rq() 函数时出错了,或者数据可能被歪曲了。
我很感谢您的任何意见,在此先感谢您。
可重现的例子
library(quantreg)
#### Raw dataset (PE_raw_SO) ####
# quantile regression (produces singularity error)
LAD.factor <- rq(
LogProb ~ factor(`Delivery costs`) +
factor(`Minimum order quantity`) + factor(`Delivery window`) +
factor(NoneOpt),
data = PE_raw_SO,
tau = 0.5
)
# linear regression to check for singularity
LM.factor <- lm(
LogProb ~ factor(`Delivery costs`) +
factor(`Minimum order quantity`) + factor(`Delivery window`) +
factor(NoneOpt),
data = PE_raw_SO
)
alias(LM.factor)
# impose assumptions on standard errors
summary(LM.factor, se = "iid")
summary(LM.factor, se = "boot")
#### Manually created dummy variables to get rid of
#### collinearity (PE_dichotomized_SO) ####
LAD.di.factor <- rq(
LogProb ~ Delivery.costs_1 + Delivery.costs_2 +
Minimum.order.quantity_1 + Minimum.order.quantity_2 +
Delivery.window_1 + Delivery.window_2 + factor(NoneOpt),
data = PE_dichotomized_SO,
tau = 0.5
)
summary(LAD.di.factor) #backsolve error
# impose assumptions (unusual results)
summary(LAD.di.factor, se = "iid")
summary(LAD.di.factor, se = "boot")
# linear regression to check for singularity
LM.di.factor <- lm(
LogProb ~ Delivery.costs_1 + Delivery.costs_2 +
Minimum.order.quantity_1 + Minimum.order.quantity_2 +
Delivery.window_1 + Delivery.window_2 + factor(NoneOpt),
data = PE_dichotomized_SO
)
alias(LM.di.factor)
summary(LM.di.factor) #regular results, all significant
示例数据+代码链接:GitHub