R/prob_confounding.R

#'@export
prob_confounding <- function(data, post, rho, mix_grid, nsamps=1000){
  #ll_mat <- ll_v7_loo(post$g, post$gp, post$q, rho,
  #                    mix_grid$S1, mix_grid$S2, mix_grid$pi,
  #                    data$beta_hat_1, data$beta_hat_2,
  #                    data$seb1, data$seb2)
  samps <-samp_from_grid(post, c("q", "gamma", "eta"), nsamps)
  ll_mat_Z1 <- ll_v7_samps_Z1(samps$gamma, samps$eta, samps$q, rho,
                      mix_grid$S1, mix_grid$S2, mix_grid$pi,
                      data$beta_hat_1, data$beta_hat_2,
                      data$seb1, data$seb2)

  ll_mat_Z0 <- ll_v7_samps_Z0(samps$gamma, samps$eta, samps$q, rho,
                              mix_grid$S1, mix_grid$S2, mix_grid$pi,
                              data$beta_hat_1, data$beta_hat_2,
                              data$seb1, data$seb2)
  R <- list("ll_Z1" = rowMeans(ll_mat_Z1), "ll_Z0" = rowMeans(ll_mat_Z0))
  R$ll_dif <- R$ll_Z1-R$ll_Z0
  R$prob_Z1 <- exp(R$ll_Z1)/(exp(R$ll_Z1) + exp(R$ll_Z0))
  return(R)
}
jean997/sherlockAsh documentation built on May 18, 2019, 11:45 p.m.