# Load and process data set
data(bmiData)
# define the negative 12 month change in BMI from baseline
y12 <- -100*(bmiData[,6L] - bmiData[,4L])/bmiData[,4L]
# Define the propensity for treatment model and methods.
moPropen <- buildModelObj(model = ~ 1,
solver.method = 'glm',
solver.args = list('family'='binomial'),
predict.method = 'predict.glm',
predict.args = list(type='response'))
# classification model
library(rpart)
moClass <- buildModelObj(model = ~parentBMI+month4BMI+race+gender,
solver.method = 'rpart',
solver.args = list(method="class"),
predict.args = list(type='class'))
#### Second-Stage Analysis using IPW
fitSS_IPW <- optimalClass(moPropen = moPropen,
moClass = moClass,
data = bmiData, response = y12, txName = 'A2')
# outcome model
moMain <- buildModelObj(model = ~parentBMI+month4BMI,
solver.method = 'lm')
moCont <- buildModelObj(model = ~race + parentBMI+month4BMI,
solver.method = 'lm')
#### Second-Stage Analysis using AIPW
fitSS_AIPW <- optimalClass(moPropen = moPropen,
moMain = moMain, moCont = moCont,
moClass = moClass,
data = bmiData, response = y12, txName = 'A2')
##Available methods
# Retrieve the classification regression object
classif(object = fitSS_AIPW)
# Coefficients of the outcome regression objects
coef(object = fitSS_AIPW)
# Description of method used to obtain object
DTRstep(object = fitSS_AIPW)
# Estimated value of the optimal treatment regime for training set
estimator(x = fitSS_AIPW)
# Value object returned by outcome regression method
fitObject(object = fitSS_AIPW)
# Estimated optimal treatment and decision functions for training data
optTx(x = fitSS_AIPW)
# Estimated optimal treatment and decision functions for new data
optTx(x = fitSS_AIPW, newdata = bmiData)
# Value object returned by outcome regression method
outcome(object = fitSS_AIPW)
outcome(object = fitSS_IPW)
# Plots if defined by outcome regression method
dev.new()
par(mfrow = c(2,4))
plot(x = fitSS_AIPW)
plot(x = fitSS_AIPW, suppress = TRUE)
# Retrieve the value object returned by propensity regression method
propen(object = fitSS_AIPW)
# Show main results of method
show(object = fitSS_AIPW)
# Show summary results of method
summary(object = fitSS_AIPW)
#### First-stage Analysis using AIPW
# Define the propensity for treatment model and methods.
moPropen <- buildModelObj(model = ~ 1,
solver.method = 'glm',
solver.args = list('family'='binomial'),
predict.method = 'predict.glm',
predict.args = list(type='response'))
# classification model
moClass <- buildModelObj(model = ~parentBMI+baselineBMI+race+gender,
solver.method = 'rpart',
solver.args = list(method="class"),
predict.args = list(type='class'))
# outcome model
moMain <- buildModelObj(model = ~parentBMI+baselineBMI,
solver.method = 'lm')
moCont <- buildModelObj(model = ~race + parentBMI+baselineBMI,
solver.method = 'lm')
fitFS_AIPW <- optimalClass(moPropen = moPropen,
moMain = moMain, moCont = moCont,
moClass = moClass,
data = bmiData, response = fitSS_AIPW,
txName = 'A1')
##Available methods for fitFS_AIPW are as shown above for fitSS_AIPW
Run the code above in your browser using DataLab