R/makeWeightsMNPS.R

Defines functions makeWeightsMNPS

makeWeightsMNPS <- function(ps, estimand, sampW = NULL, treatATT = NULL, treatATTps = NULL){
	### ps should be a vector of the probability of having received the treatment that was received
	if(estimand == "ATE"){
		wts <- 1/ps
		if(!is.null(sampW)) wts <- wts * sampW
		return(wts)
	}
	if(estimand == "ATT"){
		wts <- sampW
		wts[treatATT] <- sampW[treatATT]
		wts[!treatATT] <- treatATTps[!treatATT]/ps[!treatATT]
		if(!is.null(sampW)) wts <- wts * sampW
		return(wts)
	}
}

Try the twang package in your browser

Any scripts or data that you put into this service are public.

twang documentation built on May 29, 2024, 4:40 a.m.