##########################################################
# Load and process data set
##########################################################
data(bmiData)
#----------------------------------------------------#
# Recast treatment variables to (-1,1) --- required.
#----------------------------------------------------#
bmiData$A1[which (bmiData$A1=="MR")] <- 1L
bmiData$A1[which (bmiData$A1=="CD")] <- -1L
bmiData$A2[which (bmiData$A2=="MR")] <- 1L
bmiData$A2[which (bmiData$A2=="CD")] <- -1L
bmiData$A1 <- as.integer(bmiData$A1)
bmiData$A2 <- as.integer(bmiData$A2)
#----------------------------------------------------#
# define response y to be the negative 12 month
# change in BMI from baseline
#----------------------------------------------------#
bmiData$y <- -100*(bmiData[,6] - bmiData[,4])/bmiData[,4]
##########################################################
# Second-stage regression
##########################################################
#----------------------------------------------------#
# Create modelObj object for main effect component
#----------------------------------------------------#
moMain <- buildModelObj(model = ~ gender + parentBMI + month4BMI,
solver.method = 'lm')
#----------------------------------------------------#
# Create modelObj object for contrast component
#----------------------------------------------------#
moCont <- buildModelObj(model = ~ parentBMI + month4BMI,
solver.method = 'lm')
iqSS <- iqLearnSS(moMain = moMain,
moCont = moCont,
data = bmiData,
response = bmiData$y,
txName = "A2",
iter = 0)
##########################################################
# Model conditional mean of contrast function
##########################################################
#----------------------------------------------------#
# Create modelObj object for main effect component
#----------------------------------------------------#
moMain <- buildModelObj(model = ~ gender + race + parentBMI + baselineBMI,
solver.method = 'lm')
#----------------------------------------------------#
# Create modelObj object for contrast component
#----------------------------------------------------#
moCont <- buildModelObj(model = ~ gender + parentBMI + month4BMI,
solver.method = 'lm')
iqFSC <- iqLearnFSC(moMain = moMain,
moCont = moCont,
data = bmiData,
response = iqSS,
txName = "A1",
iter = 0)
##########################################################
# Variance Modeling
##########################################################
#----------------------------------------------------#
# homoskedastic variance
#----------------------------------------------------#
iqV1 <- iqLearnFSV(iqFSC)
residuals(iqV1)
#----------------------------------------------------#
# heteroskedastic variance
#----------------------------------------------------#
# Create modelObj object for main effect component
#----------------------------------------------------#
moMain <- buildModelObj(model = ~ gender + race + parentBMI + baselineBMI,
solver.method = 'lm')
#----------------------------------------------------#
# Create modelObj object for contrast component
#----------------------------------------------------#
moCont <- buildModelObj(model = ~ parentBMI + baselineBMI,
solver.method = 'lm')
iqV2 <- iqLearnFSV(object = iqFSC,
moMain = moMain,
moCont = moCont,
data = bmiData,
txName = "A1",
iter = 0)
# Estimated Value functions
vals <- qFuncs(iqV2)
head(vals)
# Residuals
res <- residuals(iqV2)
head(res)
# Model parameter estimates
coef(iqV2)
# Summary information for fit object
#summary(iqV2)
# QQ-plot
plot(iqV2)
# Value objects returned by modeling function
fitObj <- fitObject(iqV2)
fitObj
# All standard lm methods can be applied to the elements of this list.
summary(fitObj[[ "Combined" ]])
coef(fitObj[[ "Combined" ]])
head(residuals(fitObj[[ "Combined" ]]))
head(fitted.values(fitObj[[ "Combined" ]]))
plot(fitObj[[ "Combined"]])
Run the code above in your browser using DataLab