washb_mean | R Documentation |
Means estimated with robust standard errors for the WASH Benefits trials
washb_mean(Y, id, print = TRUE)
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. |
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).
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
#Example using the washb_mean function on child LAZ score
#Load in Bandladesh anthropometry data and enrollment data
data(washb_bangladesh_enrol)
washb_bangladesh_enrol <- washb_bangladesh_enrol
data(washb_bangladesh_anthro)
washb_bangladesh_anthro <- washb_bangladesh_anthro
# 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=F,all.y=T)
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)
#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)
#Subset data to only WSH arm:
WSH<-ad[which(ad$tr=="WSH"),]
#Run function:
washb_mean(Y=WSH$laz,id=WSH$clusterid,print=FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.