저는 R에 상당히 익숙하고 꽤 기초적인 응용 프로그램에 익숙합니다. 지금 내가 함께 내가 도움이 필요한 문제가 발생했습니다 : 내가 주문 로지스틱 회귀에 대한클러스터 표준 오차 할 수있는 방법을 찾고 있어요정렬 된 logit에 대한 클러스터 표준 오류 추정에서 삭제 된 polr - 값
을 이미
(내 추정은 this 예와 유사하다) vcovCLrobcov 및 을 시도하고 그들이 나에게 유사한 오류 메시지 제공 : meatCL에서
- 오류 (X, CL uster = cluster, type = type, ...) : 'cluster'및 'estfun()'의 숫자가 과 일치하지 않습니다.
- u [, ii]의 오류 < - ui : 대체 길이의 배수가 아님
미리 감사드립니다.
편집
: 나는 누락 된 값에 대한 좀 더 많은 정보를 찾았지만 그게 문제 될 것 같지 않습니다 - 그것은 내가 this 대답을 사용하여 해결, 또는 경우는 NA의없이 데이터 집합을 사용하는 경우에도 지속하기 때문이다. 아래 예의 경우와 같습니다. 문제는 polr이 결과의 일부로 잔차를주지 않는다는 것입니다. 이 문제를 어떻게 해결할 수 있습니까?dat <- read.dta("https://stats.idre.ucla.edu/stat/data/ologit.dta")
length(dat$apply)
twenty <- seq(from=1, to=20, by=1)
dat$clustervar<-sample(twenty, size=400, replace=TRUE)
m <- polr(apply ~ pared + public + gpa, data = dat, Hess=TRUE)
vcovCL <- function(x, cluster.by, type="sss", dfcw=1){
# R-codes (www.r-project.org) for computing
# clustered-standard errors. Mahmood Arai, Jan 26, 2008.
# The arguments of the function are:
# fitted model, cluster1 and cluster2
# You need to install libraries `sandwich' and `lmtest'
# reweighting the var-cov matrix for the within model
require(sandwich)
cluster <- cluster.by
M <- length(unique(cluster))
N <- length(cluster)
stopifnot(N == length(x$residuals))
K <- x$rank
##only Stata small-sample correction supported right now
##see plm >= 1.5-4
stopifnot(type=="sss")
if(type=="sss"){
dfc <- (M/(M-1))*((N-1)/(N-K))
}
uj <- apply(estfun(x), 2, function(y) tapply(y, cluster, sum))
mycov <- dfc * sandwich(x, meat=crossprod(uj)/N) * dfcw
return(mycov)
}
vcovCL(dat, m, dat$clustervar)
이 날을 제공합니다
Error: N == length(x$residuals) is not TRUE
Called from: vcovCL(dat, m, dat$clustervar)
이다 : 나는 그 coeftest이 제공 무슨 생각 질문을 편집하여 기본 패키지 위에 필수 라이브러리를로드하고 데이터 세트 (해당 패키지 중 하나에있는 예제 중 하나)에 액세스 한 다음 분석을 실행하려고 시도하는 코드를 포함시켜야합니다. –
(저는 다른 질문에 대답하여 덜 잘 제시된 질문을 닫으려고했습니다.) 그리고 예, 실종은 적어도 vcocCL에 대한 평가를 망칠 것입니다. 회귀에 대한 누락 된 데이터를 가져 오는 것이 현명한 접근 인 것처럼 보일 것입니다. –
의견을 보내 주셔서 감사합니다. 나는 그 질문을 더 정확하게 설명하려고 노력했다. 또한 다른 질문에 대한 답을 간과했다고 생각하십시오. 나는 그것이 내가 찾던 대답이 아니라고 말했음에 틀림 없다. – OuVaLeMonde