1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#' Fitting the Parametric Bayesian Model of Ecological Inference in 2x2 Tables
#'
#' \code{Qfun} returns the complete log-likelihood that is used to calculate
#' the fraction of missing information.
#'
#'
#' @param theta A vector that contains the MLE \eqn{E(W_1)},\eqn{E(W_2)},
#' \eqn{var(W_1)},\eqn{var(W_2)}, and \eqn{cov(W_1,W_2)}. Typically it is the
#' element \code{theta.em} of an object of class \code{ecoML}.
#' @param suff.stat A vector of sufficient statistics of \eqn{E(W_1)},
#' \eqn{E(W_2)}, \eqn{var(W_1)},\eqn{var(W_2)}, and \eqn{cov(W_1,W_2)}.
#' @param n A integer representing the sample size.
#' @author Kosuke Imai, Department of Politics, Princeton University,
#' \email{kimai@@Princeton.Edu}, \url{http://imai.princeton.edu}; Ying Lu,
#' Center for Promoting Research Involving Innovative Statistical Methodology
#' (PRIISM), New York University \email{ying.lu@@nyu.Edu} Aaron Strauss,
#' Department of Politics, Princeton University,
#' \email{abstraus@@Princeton.Edu}.
#' @seealso \code{ecoML}
#' @references Imai, Kosuke, Ying Lu and Aaron Strauss. (2011). \dQuote{eco: R
#' Package for Ecological Inference in 2x2 Tables} Journal of Statistical
#' Software, Vol. 42, No. 5, pp. 1-23. available at
#' \url{http://imai.princeton.edu/software/eco.html}
#'
#' Imai, Kosuke, Ying Lu and Aaron Strauss. (2008). \dQuote{Bayesian and
#' Likelihood Inference for 2 x 2 Ecological Tables: An Incomplete Data
#' Approach} Political Analysis, Vol. 16, No. 1 (Winter), pp. 41-69. available
#' at \url{http://imai.princeton.edu/research/eiall.html}
#' @keywords models
Qfun <- function(theta, suff.stat, n) {
mu<-rep(0,2)
Sigma<-matrix(0, 2,2)
Suff1<-rep(0,2)
Suff2<-matrix(0,2,2)
mu <- theta[1:2]
Sigma[1,1]<-theta[3]
Sigma[2,2]<-theta[4]
Sigma[1,2]<-Sigma[2,1]<-theta[5]*sqrt(Sigma[1,1]*Sigma[2,2])
Suff1 <- n*suff.stat[1:2]
Suff2[1,1]<-n*suff.stat[3]
Suff2[2,2]<-n*suff.stat[4]
Suff2[1,2]<-n*suff.stat[5]
invSigma<-solve(Sigma)
return(-0.5*n*log(det(Sigma))-0.5*sum(diag(invSigma%*%(Suff2-mu%*%t(Suff1)-Suff1%*%t(mu)+n*mu%*%t(mu)))))
}
|