Corrected bug in iptw function

This commit is contained in:
2025-05-26 17:03:24 +02:00
parent fd6c1efe06
commit 3547d113f5

View File

@ -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)
}