From aa95af7de1039c65b547c2d0ebad6f010cc6a81d Mon Sep 17 00:00:00 2001 From: Marvin Wright Date: Mon, 3 Jun 2024 13:53:06 +0200 Subject: [PATCH] fix expct for categorical data --- R/expct.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/R/expct.R b/R/expct.R index b753671..2900fb4 100644 --- a/R/expct.R +++ b/R/expct.R @@ -204,9 +204,8 @@ expct <- function( psi <- rbind(psi_cond, psi_uncond_relevant) } psi[NA_share == 1, wt := 0] - psi[prob < 1, prob := sum(wt * prob)/sum(wt), by = .(c_idx, variable, val)] - cat <- setDT(psi)[, .SD[which.max.random(prob)], by = .(c_idx, variable)] - cat <- unique(cat[, .(c_idx, variable, val)]) + cat <- psi[, sum(wt * prob), by = .(c_idx, variable, val)] + cat <- setDT(cat)[, .SD[which.max.random(V1)], by = .(c_idx, variable)] synth_cat <- dcast(cat, c_idx ~ variable, value.var = 'val')[, c_idx := NULL] }