最初,我主要想运行一个R中具有聚集标准错误的probit/logit模型,这在Stata中非常直观。我在这里找到了答案Logistic regression with robust clustered standard errors in R。 因此,我尝试将Stata和R的结果与强健的标准错误和集群标准错误进行比较。但是我注意到,两种软件的标准错误输出并不完全相同。但是,如果我使用这里建议的方法https://diffuseprior.wordpress.com/2012/06/15/standard-robust-and-clustered-standard-errors-computed-in-r/。我可以从R和Stata中获得确切的输出以进行线性回归。因此,我害怕我在R中编写的代码是不正确的,如果我想运行Probit模型而不是Logit模型,可以使用什么命令。或者如果有任何优雅的替代方案来解决这个问题?谢谢。R对于probit和logit回归的健壮和集群标准错误
R代码里面
## 1. linear regression
library(rms)
# model<-lm(Sepal.Length~Sepal.Width+Petal.Length+Petal.Width,iris)
summary(model)
fit=ols(Sepal.Length~Sepal.Width+Petal.Length+Petal.Width, x=T, y=T, data=iris)
fit
robcov(fit) #robust standard error
robcov(fit, cluster=iris$Species) #clustered standard error
## 2. logistic regression
##demo data generation
set.seed(1234)
subj<-rep(1:20,each=4)
con1<-rep(c(1,0),40)
con2<-rep(c(1,1,0,0),20)
effect<-rbinom(80,1,0.34)
data<-data.frame(subj,con1,con2,effect)
library(foreign);write.dta(data,'demo_data.dta')
library(rms)
fit=lrm(effect ~ con1 + con2, x=T, y=T, data=data)
fit
robcov(fit) ##robust standard error
robcov(fit, cluster=data$subj) ## clustered standard error
Stata的代码
## 1. linear regression
webuse iris
reg seplen sepwid petlen petwid
reg seplen sepwid petlen petwid,r
reg seplen sepwid petlen petwid,cluster(iris)
## 2. logistic regression
use demo_data,clear
logit effect con1 con2
logit effect con1 con2,r
logit effect con1 con2,cluster(subj)
你能指定什么'不完全same'意味着什么?有很多涉及的默认值可能不同。先验不清楚哪个违约更好。但是如果你想得到完全相同的值,你需要找出'Stata'和'robcov'使用的默认值,并相应地调整它们。 – coffeinjunky
感谢您的评论,我编辑了我的问题以提供更多信息 – johnsonzhj
您是否可能在没有首先运行物流的情况下使用logit? “'logistic'显示的估算作为胜算比;运行物流后,以查看系数,类型分对数”([源(http://www.stata.com/manuals13/rlogistic.pdf#rlogistic)) – noumenal