Skip to content

Commit

Permalink
fix expct for categorical data
Browse files Browse the repository at this point in the history
  • Loading branch information
mnwright committed Jun 3, 2024
1 parent 151ddf2 commit aa95af7
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions R/expct.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand Down

0 comments on commit aa95af7

Please sign in to comment.