From 3547d113f5eec56c5495c70c736975d40246eb84 Mon Sep 17 00:00:00 2001 From: corentinchoisy Date: Mon, 26 May 2025 17:03:24 +0200 Subject: [PATCH] Corrected bug in iptw function --- R/iptw.R | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/R/iptw.R b/R/iptw.R index 317381a..2dd0cf7 100644 --- a/R/iptw.R +++ b/R/iptw.R @@ -34,13 +34,11 @@ iptw <- function(df=NULL,Y=NULL,X=NULL,target="ate") { if (target == "ate") { psw <- df$TT/fitted(lr_out) + (1-df$TT)/(1-fitted(lr_out)) } else if (target=="att") { - psw <- rep(NA,nrow(df)) + psw <- fitted(lr_out)/(1-fitted(lr_out)) psw[df[,Y]==1] <- 1 - psw[df[,Y]==0] <- fitted(lr_out)/(1-fitted(lr_out)) } else if (target=="atu") { - psw <- rep(NA,nrow(df)) + psw <- (1-fitted(lr_out))/(fitted(lr_out)) psw[df[,Y]==0] <- 1 - psw[df[,Y]==1] <- (1-fitted(lr_out))/(fitted(lr_out)) } return(psw) }