Means estimated with robust standard errors for the WASH Benefits trials

washb_mean(Y, id, print = TRUE)

Arguments

Y

Outcome variable

id

ID variable for independent units (in WASH Benefits: cluster ID)

print

Logical. If print=TRUE (default) the function will print the results.

Value

Returns a 1x6 matrix that includes the number of observations, outcome mean, standard deviation, robust SE for the mean, lower 95% CI, upper 95% CI

Details

Calculate means for a variable along with robust sandwich SEs and 95% confidence intervals that account for clustering within id

This function is most useful for calculating variable means and confidence intervals -- for example, calculating average compliance (uptake) within a given intervention arm, or calculating the average LAZ by arm or measurement round. In the WASH Benefits trials, the independent unit is typically the cluster, so the 'id' argument should identify the cluster ID. If you wish to actually compare means between groups using a difference, prevalence ratio, or incidence ratio (depending on the outcome), use washb_glm, washb_ttest(for continuous outcomes), or washb_mh (for binary outcomes).

Examples

#Example using the washb_mean function on child LAZ score #Load in Bandladesh anthropometry data and enrollment data data(washb_bangladesh_anthro) washb_bangladesh_anthro <- washb_bangladesh_anthro data(washb_bangladesh_enrol) washb_bangladesh_enrol <- washb_bangladesh_enrol # drop svydate and month because they are superceded in the child level diarrhea data washb_bangladesh_enrol$svydate <- NULL washb_bangladesh_enrol$month <- NULL ad <- merge(washb_bangladesh_enrol,washb_bangladesh_anthro,by=c("dataid","clusterid","block","tr"),all.x=FALSE,all.y=TRUE) ad <- subset(ad,svy==2) ad <- subset(ad,tchild=="Target child") ad <- subset(ad,laz_x!=1) #Make sure the treatment group variables are set as factors: ad$tr <- factor(ad$tr,levels=c("Control","Water","Sanitation","Handwashing","WSH","Nutrition","Nutrition + WSH")) #Run washb_mean function on child LAZ score outcome: washb_mean(Y=ad$laz,id=ad$clusterid,print=FALSE)
#> N Mean SD Robust SE Lower 95%CI Upper 95%CI #> [1,] 4584 -1.755888 1.026709 0.01723355 -1.789666 -1.72211
#Run the function to calculate child LAZ by select intervention arms #Subset data to only handwashing arm: H<-ad[which(ad$tr=="Handwashing"),] #Run function: washb_mean(Y=H$laz,id=H$clusterid,print=FALSE)
#> N Mean SD Robust SE Lower 95%CI Upper 95%CI #> [1,] 570 -1.85407 0.9942592 0.04910706 -1.95032 -1.75782
#Subset data to only WSH arm: WSH<-ad[which(ad$tr=="WSH"),] #Run function: washb_mean(Y=WSH$laz,id=WSH$clusterid,print=FALSE)
#> N Mean SD Robust SE Lower 95%CI Upper 95%CI #> [1,] 579 -1.758549 1.011105 0.04296567 -1.842762 -1.674337