问题
I used the quantreg
package in R to compute the quantile regression model. In the model, dependent Variable(Y) is NAS_DELAY
, and the independent variable(Xs) are SEANSON1TO4
, SEANSON2TO4
, SEANSON3TO4
.
The model is:
NAS_DELAY=aSEANSON1TO4+bSEANSON2TO4+cSEANSON3TO4+d
The SEANSON1TO4
,SEANSON2TO4
,SEANSON3TO4
are dummy variables, 0 or 1. I use R to compute the intercept and other regression coefficient, but the result showed that
"error in rq.fit.br(x,y,tau=tau,....)singular design matrix ;in addition: Warning messages 1:in summary.rq(xi,....):278951 non-positivr fis".
I can't figure out why.
"fit2<-summary(rq(NAS_DELAY ~SEASON1TO4+SEASON2TO4+SEASON3TO4,tau=c(0.1,0.2,0.3,0.4,0.5),data=fddata))
Error in base::backsolve(r, x, k = k, upper.tri = upper.tri, transpose = transpose, : singular matrix in 'backsolve'. First zero in diagonal [1]"
In addition: Warning messages:
1: In rq.fit.br(x, y, tau = tau, ...) : Solution may be nonunique
2: In rq.fit.br(x, y, tau = tau, ...) : Solution may be nonunique
3: In rq.fit.br(x, y, tau = tau, ...) : Solution may be nonunique
4: In rq.fit.br(x, y, tau = tau, ...) : Solution may be nonunique
5: In rq.fit.br(x, y, tau = tau, ...) : Solution may be nonunique
6: In summary.rq(xi, ...) : 188771 non-positive fis
What am I doing wrong?
回答1:
Because of the constructed factors in your dataset, the matrix composition is singular.
See explanations of singularity : here, here, and here . Essentially quantreg depends on inverting the data matrix and because of the form of the factors, the matrix is uninvertable.
If you have enough data / if it makes sense for your data, this thread points to some possible solutions if appropriate for your data.
回答2:
I had only partially the same problem but this might still help someone. I tried:
myFactor <- as.factor(myData$myVariable)
myDummies = model.matrix(~myFactor)
summary.rq(q <- rq(myTarget ~ myOtherPredictor1+myOtherPredictor2+myDummies))
This resulted in
Error in rq.fit.br(x, y, tau = tau, ...) : Singular design matrix
However, executingsummary.rq(q <- rq(myTarget ~ myOtherPredictor1+myOtherPredictor2+myFactor))
Produced no errors. Converting to dummies before call to rq can be problematic when there are also other predictors.
来源:https://stackoverflow.com/questions/26611992/quantile-regression-dummy-variable