【问题标题】:Singularity error when doing Tobit regression进行 Tobit 回归时的奇点错误
【发布时间】:2017-12-27 08:42:14
【问题描述】:

我正在尝试估计一个标准 tobit 模型,该模型被截断为零。

变量是

因变量:幸福

自变量

  • 城市(芝加哥,纽约),
  • 性别(男,女),
  • 就业(0=失业,1=就业),
  • 工作类型(失业,蓝色,白色),
  • 假期(失业,每周 1 天,每周 2 天)

“Worktype”和“Holiday”变量与“Employment”变量交互。

我正在使用censReg 包进行 tobit 回归。

censReg(Happiness ~ City + Gender + Employment:Worktype + Employment:Holiday)

但是summary() 返回以下错误。

Error in printCoefmat(coef(x, logSigma = logSigma), digits = digits) : 
  'x' must be coefficient matrix/data frame

为了找出原因,我运行了 OLS 回归。

有一些 NA 值,我认为这是因为模型设计和变量设置(某些变量似乎存在奇异性。'Employment' = 0 的人具有 'Worktype' = Unemployed'Holidays' = Unemployed 的值。这可能是原因?)

lm(Happiness ~ City + Gender + Employment:Worktype + Employment:Holiday)


Coefficients: (2 not defined because of singularities)
                               Estimate Std. Error t value Pr(>|t|)  
(Intercept)                      41.750      9.697   4.305   0.0499 *
CityNew York                    -44.500     11.197  -3.974   0.0579 .
Gender1                           2.750     14.812   0.186   0.8698  
Employment:WorktypeUnemployed        NA         NA      NA       NA  
Employment:WorktypeBluecolor     35.000     17.704   1.977   0.1867  
Employment:WorktypeWhitecolor   102.750     14.812   6.937   0.0202 *
Employment:Holiday1 day a week  -70.000     22.394  -3.126   0.0889 .
Employment:Holiday2 day a week       NA         NA      NA       NA 

我怎样才能忽略 NA 值并运行 tobit 回归而不出错?

以下是可重现的代码。

Happiness <- c(0, 80, 39, 0, 69, 90, 100, 30)

 City <- as.factor(c("New York", "Chicago", "Chicago", "New York", "Chicago", 
"Chicago", "New York", "New York"))
 Gender <- as.factor(c(0, 1, 0, 1, 1, 1, 0, 1)) # 0 = man, 1 = woman.
 Employment <- c(0,1, 0, 0, 1 ,1 , 1 , 1) # 0 = unemployed, 1 = employed.
 Worktype <- as.factor(c(0, 2, 0, 0, 1, 1, 2,2))
 levels(Worktype) <- c("Unemployed", "Bluecolor", "Whitecolor")
 Holiday <- as.factor(c(0, 1, 0, 0, 2, 2, 2, 1))
 levels(Holiday) <- c("Unemployed", "1 day a week", "2 day a week")

 data <- data.frame(Happiness, City, Gender, Employment, Worktype, Holiday)
 reg <- lm(Happiness ~ City + Gender + Employment:Worktype +      
           Employment:Holiday)
 summary(reg)

 install.packages("censReg")
 library(censReg)
 tobitreg <- censReg(Happiness ~ City + Gender + Employment:Worktype +      
                     Employment:Holiday)
 summary(tobitreg)

【问题讨论】:

    标签: r regression na


    【解决方案1】:

    如果您逐步调试对 censReg 的调用,您会达到以下 maxLik 优化:

    result <- maxLik(censRegLogLikCross, start = start, 
          yVec = yVec, xMat = xMat, left = left, right = right, 
          obsBelow = obsBelow, obsBetween = obsBetween, obsAbove = obsAbove, 
          ...)
    

    使用 OLS 回归确定的初始条件向量 start 包含两个系数的 NA,正如您已经发现的那样:

    • 就业:工作类型失业
    • 工作:每周放假2天

    这会导致maxLik 返回 NULL,并带有错误消息:

    Return code 100: Initial value out of range.
    

    summary 函数得到这个 NULL,它解释了你得到的最终错误消息。

    要覆盖它,您可以设置start 参数:

    tobitreg <- censReg(formula = Happiness ~ City + Gender + Employment:Worktype +      
                          Employment:Holiday, start = rep(0,9) )
    summary(tobitreg)
    
    Call:
    censReg(formula = Happiness ~ City + Gender + Employment:Worktype + 
        Employment:Holiday, start = rep(0, 9))
    
    Observations:
             Total  Left-censored     Uncensored Right-censored 
                 8              2              6              0 
    
    Coefficients:
                                   Estimate Std. error t value Pr(> t)
    (Intercept)                      38.666        Inf       0       1
    CityNew York                    -50.669        Inf       0       1
    Gender1                        -360.633        Inf       0       1
    Employment:WorktypeUnemployed     0.000        Inf       0       1
    Employment:WorktypeBluecolor    345.674        Inf       0       1
    Employment:WorktypeWhitecolor    56.210        Inf       0       1
    Employment:Holiday1 day a week  346.091        Inf       0       1
    Employment:Holiday2 day a week   55.793        Inf       0       1
    logSigma                          1.794        Inf       0       1
    
    Newton-Raphson maximisation, 141 iterations
    Return code 1: gradient close to zero
    Log-likelihood: -19.35431 on 9 Df
    

    即使错误消息消失,结果也不可靠:

    • 错误 = Inf
    • 梯度接近 0:没有最优值,解是一个超平面

    回归中的 NA 系数表明这些系数与其他系数线性相关,因此您需要删除其中一些系数以获得唯一解。

    正如您所怀疑的,这是因为您在worktype = Unemployed 时只有Employement = 0,因此模型无法估计Employment:WorktypeUnemployed 的系数。 Employment:Holiday 系数也有同样的问题。

    所以我担心您正在评估的回归模型没有单一的最佳解决方案。

    如果您摆脱链接变量,则此方法有效:

    tobitreg <- censReg(formula = Happiness ~ City + Gender + Employment )
    summary(tobitreg)
    Call:
    censReg(formula = Happiness ~ City + Gender + Employment)
    
    Observations:
             Total  Left-censored     Uncensored Right-censored 
                 8              2              6              0 
    
    Coefficients:
                 Estimate Std. error t value  Pr(> t)    
    (Intercept)   38.6141     5.7188   6.752 1.46e-11 ***
    CityNew York -50.1813     6.4885  -7.734 1.04e-14 ***
    Gender1      -70.3859     8.2943  -8.486  < 2e-16 ***
    Employment   111.5672    10.0927  11.054  < 2e-16 ***
    logSigma       1.7930     0.2837   6.320 2.61e-10 ***
    ---
    Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
    
    Newton-Raphson maximisation, 8 iterations
    Return code 1: gradient close to zero
    Log-likelihood: -19.36113 on 5 Df
    

    【讨论】:

    • 很快就会检查出来。非常感谢您的努力!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-19
    • 2022-10-06
    • 1970-01-01
    • 1970-01-01
    • 2019-07-17
    • 2020-07-08
    • 2021-12-25
    相关资源
    最近更新 更多