##code for Chapter 7 "Propensity Score Methods for Continuous Treatment Doses" of book:
#Leite, W. L. (2016). Practical propensity score methods using R.
#Thousand Oaks, CA: Sage.
#
#this is the code that was used to generate the example results in the book
#As the R software and the R packages used in this example are updated frequently
#some incompatibilities between the current code and new R versions or package versions
#may appear
#Any updates to the code will be posted at:
# http://www.practicalpropensityscore.com
#PART 4 ESTIMATION OF AVERAGE TREATMENT EFFECT WITH INVERSE PROBABILITY WEIGHTS
#this example estimates the effect of school participation
#in the Algebra Nation virtual learning environment
#on the mean student scores on Florida's Algebra I End-of-Course (EOC) Assessment.
#load data
#load data
load(file="Chapter7_data_with_IPW.Rdata")
#estimate the average treatment effect of logins per examinee
library(survey)
#define survey design
designIPW <- svydesign(ids=~1,weights=~IPW,data=data) #design with weights
#estimate outcome model
outcomeModel <- svyglm(formula= meanScale2014~logLoginsPerExaminee,
design = designIPW, family=gaussian)
summary(outcomeModel)
#obtain a standardized coefficient
coef(outcomeModel)[2]*sqrt(coef(svyvar(~logLoginsPerExaminee,designIPW)))/
sqrt(coef(svyvar(~meanScale2014,designIPW)))
#estimate the average treatment effect of logins per examinee
#with a model with polynomial terms
outcomeModelNl <- svyglm(formula= meanScale2014~logLoginsPerExaminee+
I(logLoginsPerExaminee^2) + I(logLoginsPerExaminee^3),
design = designIPW, family=gaussian)
summary(outcomeModelNl)
#compare linear and nonlinear models
anova(outcomeModelNl, outcomeModel)
#estimate the average treatment effect of logins per examinee
#using the IPW and controlling for charter school,
outcomeModelDR <- svyglm(formula= meanScale2014~logLoginsPerExaminee +
Charter + Charter:logLoginsPerExaminee,
design = designIPW, family=gaussian)
summary(outcomeModelDR)
#obtain a standardized coefficient
coef(outcomeModelDR)[2]*sqrt(coef(svyvar(~logLoginsPerExaminee,designIPW)))/
sqrt(coef(svyvar(~meanScale2014,designIPW)))