Corrected bug in iptw function
This commit is contained in:
6
R/iptw.R
6
R/iptw.R
@ -34,13 +34,11 @@ iptw <- function(df=NULL,Y=NULL,X=NULL,target="ate") {
|
|||||||
if (target == "ate") {
|
if (target == "ate") {
|
||||||
psw <- df$TT/fitted(lr_out) + (1-df$TT)/(1-fitted(lr_out))
|
psw <- df$TT/fitted(lr_out) + (1-df$TT)/(1-fitted(lr_out))
|
||||||
} else if (target=="att") {
|
} 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]==1] <- 1
|
||||||
psw[df[,Y]==0] <- fitted(lr_out)/(1-fitted(lr_out))
|
|
||||||
} else if (target=="atu") {
|
} 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]==0] <- 1
|
||||||
psw[df[,Y]==1] <- (1-fitted(lr_out))/(fitted(lr_out))
|
|
||||||
}
|
}
|
||||||
return(psw)
|
return(psw)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user