# 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]
#### Full Interactive Q-Learning Algorithm
### Second-Stage Analysis
# outcome model
moMain <- buildModelObj(model = ~parentBMI+month4BMI,
solver.method = 'lm')
moCont <- buildModelObj(model = ~race + parentBMI+month4BMI,
solver.method = 'lm')
fitSS <- iqLearnSS(moMain = moMain, moCont = moCont,
data = bmiData, response = y12, txName = 'A2')
### First-Stage Analysis Main Effects Term
# main effects model
moMain <- buildModelObj(model = ~parentBMI+baselineBMI,
solver.method = 'lm')
moCont <- buildModelObj(model = ~race + parentBMI+baselineBMI,
solver.method = 'lm')
fitFSM <- iqLearnFSM(moMain = moMain, moCont = moCont,
data = bmiData, response = fitSS, txName = 'A1')
### First-Stage Analysis Contrasts Term
# contrasts model
moMain <- buildModelObj(model = ~parentBMI+baselineBMI,
solver.method = 'lm')
moCont <- buildModelObj(model = ~race + parentBMI+baselineBMI,
solver.method = 'lm')
fitFSC <- iqLearnFSC(moMain = moMain, moCont = moCont,
data = bmiData, response = fitSS, txName = 'A1')
### First-Stage Analysis Contrasts Variance - Log-linear
# contrasts variance model
moMain <- buildModelObj(model = ~baselineBMI,
solver.method = 'lm')
moCont <- buildModelObj(model = ~baselineBMI,
solver.method = 'lm')
fitFSV <- iqLearnFSV(object = fitFSC, moMain = moMain, moCont = moCont,
data = bmiData)
####Available methods
### Estimated value
estimator(x = fitFSC, y = fitFSM, z = fitFSV, w = fitSS, dens = 'nonpar')
## Estimated optimal treatment and decision functions for training data
## Second stage optimal treatments
optTx(x = fitSS)
## First stage optimal treatments when contrast variance is modeled.
optTx(x = fitFSM, y = fitFSC, z = fitFSV, dens = 'nonpar')
## First stage optimal treatments when contrast variance is constant.
optTx(x = fitFSM, y = fitFSC, dens = 'nonpar')
## Estimated optimal treatment and decision functions for new data
## Second stage optimal treatments
optTx(x = fitSS, bmiData)
## First stage optimal treatments when contrast variance is modeled.
optTx(x = fitFSM, y = fitFSC, z = fitFSV, dens = 'nonpar', bmiData)
## First stage optimal treatments when contrast variance is constant.
optTx(x = fitFSM, y = fitFSC, dens = 'nonpar', bmiData)
### The following methods are available for all objects: fitSS, fitFSM,
### fitFSC and fitFSV. We include only one here for illustration.
# Coefficients of the outcome regression objects
coef(object = fitSS)
# Description of method used to obtain object
DTRstep(object = fitFSM)
# Value object returned by outcome regression method
fitObject(object = fitFSC)
# Value object returned by outcome regression method
outcome(object = fitFSV)
# Plots if defined by outcome regression method
dev.new()
par(mfrow = c(2,4))
plot(x = fitSS)
plot(x = fitSS, suppress = TRUE)
# Show main results of method
show(object = fitFSM)
# Show summary results of method
summary(object = fitFSV)
Run the code above in your browser using DataLab