R中出现意外的输入错误

时间:2017-02-10 09:31:25

标签: r benchmarking

我正在尝试使用本书中的SFA代码重现结果:"使用DEA,SFA和R"进行基准测试。它使用Benchmarking包,但代码产生了意外的输入错误。

不知道出了什么问题。

library(Benchmarking)
milkProd <- read.csv( "milkProd.csv" )
x <- with(milkProd, cbind(vet, energy, cows))
y <- matrix(milkProd$milk)
milkSfa <- sfa(log(x), log(y))
summary(milkSfa)

#Percentage of inefficiency variation to total variation
lambda <- lambda.sfa(milkSfa) 
100*lambdaˆ2/(1+lambdaˆ2)

# variance for inefficiency
sigma2u.sfa(milkSfa)

# variance for random errors
sigma2v.sfa(milkSfa)

#Estimate technical efficiency for each DMU
e <- residuals(milkSfa)
s2 <- sigma2.sfa(milkSfa)
lambda <- lambda.sfa(milkSfa)

mustar <- -e*lambdaˆ2/(1+lambdaˆ2)
sstar <- lambda/(1+lambdaˆ2)*sqrt(s2)
teJ <- exp(-mustar-sstar*( dnorm(mustar/sstar)/pnorm(mustar/sstar) ))
estar <- e * lambda / sqrt(s2)
euJ <- sstar * (dnorm(estar)/(1 - pnorm(estar)) - estar)
teJJ <- exp(-euJ)
all.equal(teJ, teJJ)
teMode <- exp(pmin(0,-mustar))

teBC <- pnorm(mustar/sstar -sstar)/pnorm(mustar/sstar) * exp(sstarˆ2/2 -mustar)

cor(cbind(teBC=c(teBC), teMode=c(teMode), teJ=c(teJ)))

mean(teBC)

sum(milkProd$milk*teBC/sum(milkProd$milk))

all.equal(matrix(teBC),te.sfa(milkSfa),check.attributes=FALSE)
all.equal(matrix(teMode),teMode.sfa(milkSfa),check.attributes=F)
all.equal(matrix(teJ),teJ.sfa(milkSfa),check.attributes=FALSE)

plot(milkProd$milk, teBC, xlab = "Kg milk produced", ylab = "efficiency")
lines(lowess(milkProd$milk, teBC), lwd = 1.5)

0 个答案:

没有答案