Learn R Programming

DynTxRegime (version 2.1)

iqLearnFSV: IQ-Learning: Variance of First-Stage Regression of Second-Stage Contrast (IQ3)

Description

Estimates the variance function of the first-stage regression of the estimated second-stage contrast by fitting a constant variance function or a log-linear model to the residuals.

Usage

iqLearnFSV(object, ..., moMain = NULL, moCont = NULL, data = NULL, iter = 0, suppress = FALSE)

Arguments

object
an object of class DynTxRegime: The value object returned from a previous call to iqLearnFSC()
...
ignored
moMain
For constant variance, NULL. If a log-linear model is to be used, an object of class modelObj defining the regression model and procedures to be used for the main effects component of this regression step. The object must be created by a call to modelObj::buildModelObj(). The method chosen to obtain predictions must return the prediction on the scale of the response variable. See ?modelObj for details.
moCont
For constant variance, NULL. If a log-linear model is to be used, an object of class modelObj defining the regression model and procedures to be used for the contrast component of this regression step. The object must be created by a call to modelObj::buildModelObj(). The method chosen to obtain predictions must return the prediction on the scale of the response variable. See ?modelObj for details.
data
For constant variance, NULL. If a log-linear model is to be used, an object of class data.frame containing the covariates and treatment history. Treatment must be an integer (or able to be cast to an integer) and take values {-1,1}.
iter
For constant variance, NULL. If a log-linear model is to be used, an object of class integer.

>=1 if moMain and moCont are to be fitted separately, iter is the maximum number of iterations. Assume Y = Ymain + Ycont; the iterative algorithm is as follows: (1) hat(Ycont) = 0; (2) Ymain = Y - hat(Ycont); (3) fit Ymain ~ moMain; (4) set Ycont = Y - hat(Ymain); (5) fit Ycont ~ A*moCont; (6) Repeat steps (2) - (5) until convergence or a maximum of iter iterations.

<=0 if="" the="" components="" of="" conditional="" expectation="" moMain and moCont will be combined and fit as a single object. Note that if iter <= 0,="" all="" non-model="" components="" of="" the="" moMain and moCont must be identical. By default, the choices in moMain are used.

suppress
an object of class logical. If TRUE, final screen prints are suppressed.

Value

Returns an object that inherits directly from class DynTxRegime.

Details

There are standard regression analysis tools available for the object returned by this function. In general, these tools simply extend the methods defined by the regression function. If defined, coef() returns the model parameter estimates; plot() generates the standard x-y plots; residuals returns model residuals for the combined model; and summary returns summary information.

Other tools, such as fitted() for the lm regression function, can be accessed using fitObject(). fitObject() retrieves the standard value object returned by the regression method, which can be passed as input to other functions. See ?fitObject for details.

For homoskedastic variance, the standard deviation can be retrieved using method stdDev().

References

Laber, E. B., Linn, K. A., and Stefanski, L. A. (2014). Interactive Q-learning. Biometrika, in press.

See Also

iqLearnFSM, iqLearnFSC, iqLearnSS

Examples

Run this code
  ##########################################################
  # 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