보통 일부 효과 (APE)는
이러한 하나의 방법이 사용하는 R.에서 다수의 방식으로 획득 패키지 mfx
:
install.packages("mfx")
require(mfx) # use logitmfx() or any other appropriate function from this package
또는 tonymisc
에서 mfx
기능.
mfxboot <- function(modform,dist,data,boot=1000,digits=3){
x <- glm(modform, family=binomial(link=dist),data)
# get marginal effects
pdf <- ifelse(dist=="probit",
mean(dnorm(predict(x, type = "link"))),
mean(dlogis(predict(x, type = "link"))))
marginal.effects <- pdf*coef(x)
# start bootstrap
bootvals <- matrix(rep(NA,boot*length(coef(x))), nrow=boot)
set.seed(1111)
for(i in 1:boot){
samp1 <- data[sample(1:dim(data)[1],replace=T,dim(data)[1]),]
x1 <- glm(modform, family=binomial(link=dist),samp1)
pdf1 <- ifelse(dist=="probit",
mean(dnorm(predict(x, type = "link"))),
mean(dlogis(predict(x, type = "link"))))
bootvals[i,] <- pdf1*coef(x1)
}
res <- cbind(marginal.effects,apply(bootvals,2,sd),marginal.effects/apply(bootvals,2,sd))
if(names(x$coefficients[1])=="(Intercept)"){
res1 <- res[2:nrow(res),]
res2 <- matrix(as.numeric(sprintf(paste("%.",paste(digits,"f",sep=""),sep=""),res1)),nrow=dim(res1)[1])
rownames(res2) <- rownames(res1)
} else {
res2 <- matrix(as.numeric(sprintf(paste("%.",paste(digits,"f",sep=""),sep="")),nrow=dim(res)[1]))
rownames(res2) <- rownames(res)
}
colnames(res2) <- c("marginal.effect","standard.error","z.ratio")
return(res2)
}
이, 수식을 가져 데이터를 얻을, 그것을 시도하고 실패 할 경우, 질문 :
또 다른
는 부트 스트랩을 사용하여 이것과 같은 사용자 정의 기능입니다. [Here] (http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)는 좋은 질문을하는 방법에 대한 몇 가지 예입니다. –당신이 새로운 사람이라는 것을 알았으므로이 사실을 알지 못했지만 실제로는 http://stats.stackexchange.com/questions/224079/how-to-calculate-ape-in-case의 교차 게시 규칙에 위배됩니다. -of-iv-probit-with-r 당신의 질문을 잠시 보류 했으므로 가능한 경우 CV에서 삭제하도록 제안합니다. –
힌트를 보내 주셔서 감사합니다! 나는 다른 질문을 삭제했다. – Flo