washb_ttest.Rd
Function to call the paired t-test for two different arms of the study.
washb_ttest(Y,tr,strat,contrast)
Y | quantitative outcome variable (e.g. LAZ) |
---|---|
tr | binary treatment group variable, comparison group first |
strat | stratification variable (here: block) |
contrast | vector of length 2 that includes the tr groups to contrast |
Returns a vector with the mean difference (diff), 95 percent confidence intervals (ci.lb and ci.ub), t-statistic (t-stat), and p-value (p) for the paired t-test
washb_ttest
estimates a paired t-test for differences in means paired within randomization blocks.
The arguments Y
,tr
, and strat
need to be from the same dataset.
# NOT RUN { #The washb_ttest function #Load in Bangladesh anthropometry data. data(washb_bangladesh_anthro) washb_bangladesh_anthro <- washb_bangladesh_anthro data(washb_bangladesh_enrol) washb_bangladesh_enrol <- washb_bangladesh_enrol washb_bangladesh_enrol$svydate <- NULL washb_bangladesh_enrol$month <- NULL laz <- merge(washb_bangladesh_enrol,washb_bangladesh_anthro,by=c("dataid","clusterid","block","tr"),all.x=FALSE,all.y=TRUE) # subset to the endline target children laz <- subset(laz,svy==2) laz <- subset(laz,tchild=="Target child") # Drop children with extreme LAZ values laz <- subset(laz,laz_x!=1) laz$tr <- factor(laz$tr,levels=c("Control","Water","Sanitation","Handwashing","WSH","Nutrition","Nutrition + WSH")) #Run paired ttest function for water vs. control comparison: washb_ttest(Y=laz$laz,tr=laz$tr,strat=laz$block, contrast=c("Control","Water")) # }