从ictreg模型自动计算BIC

时间:2018-06-18 13:48:04

标签: r

我找了一种方法来计算贝叶斯信息准则(BIC),该方法是使用ictreg()包提供的list估算的模型,但未找到答案。

示例:

library(list)

data(race)

lm.results <- ictreg(y ~ south + age + male + college, data = race, 
                 treat = "treat", J=3, method = "ml")

summary(lm.results)

结果:

Item Count Technique Regression 

Call: ictreg(formula = y ~ south + age + male + college, data = race, 
    treat = "treat", J = 3, method = "ml")

Sensitive item 
                Est.    S.E.
(Intercept) -5.50833 1.02112
south        1.67564 0.55855
age          0.63587 0.16334
male         0.84647 0.49375
college     -0.31527 0.47360

Control items 
                Est.    S.E.
(Intercept)  1.19141 0.14369
south       -0.29204 0.09692
age          0.03322 0.02768
male        -0.25060 0.08194
college     -0.51641 0.08368

Log-likelihood: -1444.394

Number of control items J set to 3. Treatment groups were indicated by '1' and the control group by '0'.

1 个答案:

答案 0 :(得分:0)

这是我遇到的解决方案。它使用该模型使用以下公式计算BIC:-2*log-likelihood + npar*log(nobs),其中npar表示参数的数量,nobs是拟合模型中的观测数量

以下函数计算BIC:

bic_ictreg <- function(fit) {
  # Check if method is "ml". Stop if not.
  if(fit[["method"]] != "ml") {
    stop("Function needs a model that uses the Expectation-Maximization algorithm to estimate. Use method = 'ml' within ictreg")
  }

  # Calculate BIC
  -2*fit[["llik"]] + (length(fit[["par.treat"]]) + 
                        length(fit[["par.control"]])) * 
    log(length(fit[["pred.post"]]))
}

bic_ictreg(lm.results)

上面的例子:

library(list)

data(race)

lm.results <- ictreg(y ~ south + age + male + college, data = race, 
                 treat = "treat", J=3, method = "ml")

bic_ictreg(lm.results)

结果:

[1] 2959.797

结果与布莱尔报告的BIC一致。今井(2012年,第70页)。

参考

Blair,G。,&amp; Imai,K。(2012)。列表实验的统计分析。 政治分析,20(01),47-77。 https://doi.org/10.1093/pan/mpr048