2014-02-06 62 views
3

我正嘗試將Stata模型從Stata遷移到R.如何使用vglm tobit模型使用健壯的se和cluster se?

Stata強壯的命令是將,vce(robust)添加到模型中。而對於集羣,它將是,vce(cluster idvar)

重現塔塔例如:

use http://www.ats.ucla.edu/stat/stata/dae/tobit, clear 
tobit apt read math i.prog, ul(800) 
tobit apt read math i.prog, ul(800) vce(cluster prog) 

重複性R實施例:

library("VGAM") 

dat <- read.csv("http://www.ats.ucla.edu/stat/data/tobit.csv") 

summary(m <- vglm(apt ~ read + math + prog, tobit(Upper = 800), data = dat)) 

我的理解是,coeftest(m, vcov = sandwich)應該給我健壯本身。

,但我得到以下幾點:Error: $ operator not defined for this S4 class.

有人能提出一個方法來估計健壯本身從vglm模型,也聚集本身與vglm?

+2

我想你會需要這個自己的代碼。 'plm'包可以集羣調整SE,但是這是針對線性模型的。您可以編寫分析解決方案或按羣集編寫塊引導程序。 –

回答

2

在花了一整天的時間看看這個問題後,我想我終於找到了一個合適的包:Zelig

http://docs.zeligproject.org/en/latest/zelig-tobit.html

沒有集羣比較聚類:

WITHOUT

> summary(m <- zelig(apt ~ read + math + prog, 
      below=0, above=Inf, model="tobit", data = dat)) 


How to cite this model in Zelig: 
    Kosuke Imai, Gary King, and Olivia Lau. 2015. 
    "tobit: Linear regression for Left-Censored Dependent Variable" 
    in Kosuke Imai, Gary King, and Olivia Lau, "Zelig: Everyone's Statistical Software," 
    http://gking.harvard.edu/zelig 


Call: 
"survreg"(formula = formula, dist = "gaussian", data = data, 
    robust = robust) 
       Value Std. Error  z  p 
(Intercept) 242.74  29.760 8.16 3.45e-16 
read    2.55  0.576 4.43 9.24e-06 
math    5.38  0.651 8.27 1.31e-16 
proggeneral -13.74  11.596 -1.18 2.36e-01 
progvocational -48.83  12.818 -3.81 1.39e-04 
Log(scale)  4.12  0.050 82.41 0.00e+00 

Scale= 61.6 

Gaussian distribution 
Loglik(model)= -1107.9 Loglik(intercept only)= -1202.8 
    Chisq= 189.72 on 4 degrees of freedom, p= 0 
Number of Newton-Raphson Iterations: 5 
n= 200 

> summary(m <- zelig(apt ~ read + math + prog, below=0, 
      above=Inf, model="tobit", 
      data = dat,robust=T,cluster="prog")) 


How to cite this model in Zelig: 
    Kosuke Imai, Gary King, and Olivia Lau. 2015. 
    "tobit: Linear regression for Left-Censored Dependent Variable" 
    in Kosuke Imai, Gary King, and Olivia Lau, "Zelig: Everyone's Statistical Software," 
    http://gking.harvard.edu/zelig 


Call: 
"survreg"(formula = formula, dist = "gaussian", data = data, 
    robust = robust) 
       Value Std. Err (Naive SE)  z  p 
(Intercept) 242.74 2.8315  29.760 85.73 0.00e+00 
read    2.55 0.3159  0.576 8.08 6.40e-16 
math    5.38 0.2770  0.651 19.44 3.78e-84 
proggeneral -13.74 0.3252  11.596 -42.25 0.00e+00 
progvocational -48.83 0.1978  12.818 -246.83 0.00e+00 
Log(scale)  4.12 0.0586  0.050 70.34 0.00e+00 

Scale= 61.6 

Gaussian distribution 
Loglik(model)= -1107.9 Loglik(intercept only)= -1202.8 
    Chisq= 189.72 on 4 degrees of freedom, p= 0 
(Loglikelihood assumes independent observations) 
Number of Newton-Raphson Iterations: 5 
n= 200 
+0

我接受了您的解決方案,但我會補充一點,它只在數據從下面審查時才起作用。 Zelig(5.0版)也有一個「tobit.bayes」模型,允許上述審查數據,但似乎並不支持集羣模型。 –