使用censReg()在R中建立轨道模型,并带有任意观测值的观测值

时间:2019-12-15 20:46:07

标签: r

使用censReg()函数估计R中的轨道模型。似乎,被检查观测值的观测值应该无关紧要(当然,只要它们低于检查值即可)。与下面的代码中的tobit1和tobit2相比,这是正确的。但是,当我仅将观察值更改一点(从-2.8e5到-2.9e5)时,结果将完全改变。知道这里发生了什么吗?

set.seed(8)
n = 200
x = rnorm(n)
a=3; b = 3
# generate latent y; censoring value k; and observed z
y = rnorm(n, a+b*x)
k = 2
z = ifelse(y>k, y, 0)
table(z==0) # 82 T, 118 F

# tobit with "reasonable" observed values for censored obs:
tobit1 = censReg(z~x,left=k) 

# tobit with arbitrarily low observed values for censored obs:
z2 = ifelse(y>k, y, -2.8e5)
tobit2 = censReg(z2~x,left=k) 
# ... and even lower:
z3 = ifelse(y>k, y, -2.9e5)
tobit3 = censReg(z3~x,left=k) 

stargazer(tobit1,tobit2,tobit3,type='text')

=================================================
                         Dependent variable:     
                    -----------------------------
                        z        z2        z3    
                       (1)      (2)       (3)    
-------------------------------------------------
x                   2.988***  2.988*** 8,518.070 
                     (0.109)  (0.109)            

logSigma             -0.090    -0.090    8.808   
                     (0.065)  (0.065)            

Constant            2.937***  2.937*** -7,792.855
                     (0.097)  (0.097)            

-------------------------------------------------
Observations           200      200       200    
Log Likelihood      -177.353  -177.353 -1,201.950
Akaike Inf. Crit.    360.707  360.707  2,409.899 
Bayesian Inf. Crit.  370.602  370.602  2,419.794 
=================================================
Note:                 *p<0.1; **p<0.05; ***p<0.01

1 个答案:

答案 0 :(得分:0)

嗯,真令人失望。我遇到了麻烦,需要通过Google确定censReg位于软件包“ censReg”中(表面上并不明显),安装该软件包及其依赖项,并同时加载“ censReg”和“观星者”。现在我明白了:

> # tobit with "reasonable" observed values for censored obs:
> tobit1 = censReg(z~x,left=k) 
Warning message:
In censReg(z ~ x, left = k) :
  at least one value of the endogenous variable is smaller than the left limit
> 
> # tobit with arbitrarily low observed values for censored obs:
> z2 = ifelse(y>k, y, -2.8e5)
> tobit2 = censReg(z2~x,left=k) 
Warning message:
In censReg(z2 ~ x, left = k) :
  at least one value of the endogenous variable is smaller than the left limit
> # ... and even lower:
> z3 = ifelse(y>k, y, -2.9e5)
> tobit3 = censReg(z3~x,left=k) 
Warning message:
In censReg(z3 ~ x, left = k) :
  at least one value of the endogenous variable is smaller than the left limit

stargazer(tobit1,tobit2,tobit3,type='text')

=================================================
                         Dependent variable:     
                    -----------------------------
                        z        z2        z3    
                       (1)       (2)       (3)   
-------------------------------------------------
x                   2.988***  2.988***  2.988*** 
                     (0.109)   (0.109)   (0.109) 

logSigma             -0.090    -0.090    -0.090  
                     (0.065)   (0.065)   (0.065) 

Constant            2.937***  2.937***  2.937*** 
                     (0.097)   (0.097)   (0.097) 

-------------------------------------------------
Observations           200       200       200   
Log Likelihood      -177.353  -177.353  -177.353 
Akaike Inf. Crit.    360.707   360.707   360.707 
Bayesian Inf. Crit.  370.602   370.602   370.602 
=================================================
Note:                 *p<0.1; **p<0.05; ***p<0.01

因此,您收到的警告消息是您没有提供的,并且可能发现了一个仅针对您所使用的操作系统的隐晦感,而您并未透露。我在Ubuntu 18.04机器上使用R 3.6.1。您应该确定您正在使用R的最新版本(尽管我尚未更新到3.6.2)和所有涉及的软件包(请注意我有stargazer_5.2.2 + censReg_0.5-30 + maxLik_1)。 3-6),如果是,请将错误报告发送至:

 maintainer("censReg")
[1] "Arne Henningsen <arne.henningsen@gmail.com>"

请附加您的内容:

 sessionInfo()

R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] stargazer_5.2.2   censReg_0.5-30    maxLik_1.3-6      miscTools_0.6-22  vars_1.5-3       
 [6] lmtest_0.9-37     urca_1.3-0        strucchange_1.5-1 sandwich_2.5-1    zoo_1.8-6        
[11] MASS_7.3-51.4     MTS_1.0          

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3          Formula_1.2-3       magrittr_1.5        lattice_0.20-38    
 [5] bibtex_0.4.2        stringr_1.4.0       timeSeries_3042.102 tools_3.6.1        
 [9] grid_3.6.1          glmmML_1.1.0        timeDate_3043.102   nlme_3.1-141       
[13] yaml_2.2.0          bdsmatrix_1.3-3     Rdpack_0.11-0       gbRd_0.4-11        
[17] plm_2.1-0           fGarch_3042.83.1    stringi_1.4.3       compiler_3.6.1     
[21] fBasics_3042.89     spatial_7.3-11      mvtnorm_1.0-11