R Tobit回归时的奇异性误差
我试图估计一个标准的托比特模型,它被删失为零 变量是 因变量:幸福感 自变量:R Tobit回归时的奇异性误差,r,regression,na,R,Regression,Na,我试图估计一个标准的托比特模型,它被删失为零 变量是 因变量:幸福感 自变量: 城市(芝加哥,纽约) 性别(男,女) 就业(0=失业,1=就业) 工作类型(失业、蓝色、白色) 假期(失业,每周1天,每周2天) “工作类型”和“假日”变量与“就业”变量相互作用 我正在使用censReg包进行tobit回归 censReg(Happiness ~ City + Gender + Employment:Worktype + Employment:Holiday) 但是summary()返回以下错
- 城市(芝加哥,纽约)
- 性别(男,女)
- 就业(0=失业,1=就业)
- 工作类型(失业、蓝色、白色)
- 假期(失业,每周1天,每周2天)
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回归
censReg(Happiness ~ City + Gender + Employment:Worktype + Employment:Holiday)
有一些NA值,我认为这是因为模型设计和变量设置(某些变量似乎存在奇点。而'Employment'=0
的人有值'Worktype'=unemployee
,'Holidays'=unemployee
。这可能是原因?)
我怎么能忽略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)
Happiness如果您一步一步地调试对censReg的调用,您将实现以下maxLik优化:
result <- maxLik(censRegLogLikCross, start = start,
yVec = yVec, xMat = xMat, left = left, right = right,
obsBelow = obsBelow, obsBetween = obsBetween, obsAbove = obsAbove,
...)
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
我很快就会查出来的。非常感谢您的努力!
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
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