Last data update: 2014.03.03

R: IQ-Learning: Variance of First-Stage Regression of...
iqLearnFSVR Documentation

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 the 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.

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().

Value

Returns an object that inherits directly from class DynTxRegime.

Author(s)

Kristin A. Linn, Eric B. Laber, Leonard A. Stefanski, and Shannon T. Holloway <sthollow@ncsu.edu>

References

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

See Also

iqLearnFSM, iqLearnFSC, iqLearnSS

Examples

  ##########################################################
  # 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"]])

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(DynTxRegime)
Loading required package: modelObj
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/DynTxRegime/iqLearnVar.Rd_%03d_medium.png", width=480, height=480)
> ### Name: iqLearnFSV
> ### Title: IQ-Learning: Variance of First-Stage Regression of Second-Stage
> ###   Contrast (IQ3)
> ### Aliases: iqLearnFSV
> 
> ### ** Examples
> 
>   ##########################################################
>   # 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)

 *** Combined Fit ***

Call:
lm(formula = YinternalY ~ gender + parentBMI + month4BMI + A2 + 
    parentBMI:A2 + month4BMI:A2, data = data)

Coefficients:
 (Intercept)        gender     parentBMI     month4BMI            A2  
    41.28845      -0.64891      -0.15509      -0.82067      -7.38709  
parentBMI:A2  month4BMI:A2  
     0.20223       0.02816  


Mean of Value Function:  7.646356 

>  
>   ##########################################################
>   # 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)

 *** Combined Fit ***

Call:
lm(formula = YinternalY ~ gender + race + parentBMI + baselineBMI + 
    A1 + gender:A1 + parentBMI:A1 + A1:month4BMI, data = data)

Coefficients:
 (Intercept)        gender          race     parentBMI   baselineBMI  
   -7.347153     -0.003459      0.006199      0.210226      0.018137  
          A1     gender:A1  parentBMI:A1  A1:month4BMI  
   -0.109270     -0.008031      0.006886     -0.002987  

> 
>   ##########################################################
>   # Variance Modeling
>   ##########################################################
> 
>     #----------------------------------------------------#
>     # homoskedastic variance
>     #----------------------------------------------------#
>     iqV1 <- iqLearnFSV(iqFSC)

iqLearnVarHom(object = object)

Standard Deviation: 0.05751781
> 
>     residuals(iqV1)
  [1]  0.368385718  0.904649404  0.596364105 -0.544777460  0.485197051
  [6] -0.580053317 -0.129663278 -0.413226522  0.782050743 -0.011205541
 [11] -0.850810071 -0.568466336  0.365016075 -0.898728460 -1.155595880
 [16]  0.919358766  1.720072511  0.303084582 -1.138888211  2.677945967
 [21]  0.601420063  0.177692471  0.504860279 -0.200840703 -0.461000957
 [26]  0.804322534  0.561018840  0.352834512  0.422232574 -0.395813556
 [31] -0.501954286 -0.647385716 -0.460607370 -0.094430378  0.517878681
 [36]  1.167707232 -0.815979990 -0.608570938  1.737283573 -0.444078484
 [41]  0.683215449  1.282832977 -0.729420946 -0.724921229 -0.346680048
 [46] -0.845614793 -0.823888105 -0.724731064 -0.129544173 -0.022111698
 [51] -0.990371185  1.375959241 -0.006556678 -1.374574220  0.932507358
 [56] -1.467055361 -0.865084296  2.425657647 -1.187613126 -0.038719588
 [61] -1.087736963 -0.653783776 -1.180195359 -1.523549046  1.670565699
 [66]  0.806950799 -0.245434110  2.078000607 -0.492516466 -1.383068455
 [71] -0.174690166  0.068276031 -0.919064934 -1.675498238  1.208939630
 [76]  0.488864140  0.670495953  1.308031000  1.066327455  0.837731682
 [81] -0.671634650 -0.018254236 -0.936155956  0.619554953 -1.626594421
 [86]  1.339923495 -0.113713862 -0.712375454 -1.027123939  2.352867359
 [91] -0.574614035  0.714013946 -1.653711190  0.791168155  0.826285071
 [96]  0.565298171  0.417360176 -0.339597420  1.926753509 -0.198972243
[101] -0.706536873  0.185341683 -0.177631540 -0.055759434  0.163593620
[106] -0.360909702 -0.209968187  1.515880115  0.661102219 -0.870060797
[111] -0.042335746  0.197738910  0.397425580 -0.951071288 -1.955272638
[116] -0.628034515 -1.440082696  0.457794551  0.833712700  0.098484740
[121] -0.774260166  0.693351079  0.385970394  1.319334923 -0.797196725
[126] -0.860361543  0.682801165 -0.154809779  0.060139733  0.737323754
[131]  0.476560390  0.078654393 -0.773606461  0.249855543 -0.905698278
[136] -1.272720957  0.558060342  1.027654518  0.145353466  1.421329208
[141] -0.225710372  1.782348411 -0.362520258  0.697811493  1.704760337
[146] -0.464590321 -0.293695428 -2.080484643 -1.097147447 -1.014073185
[151]  1.232283672  0.876463111  0.378181605  1.173575673  1.071788821
[156] -2.719528085 -0.900682882 -0.449738856  0.072774745 -0.901128509
[161]  1.459186226 -0.264269935  0.106529441 -0.981121593 -0.812745882
[166] -0.335884772  1.527984532 -0.858332130  0.362137194  0.309130427
[171] -0.348730418  1.814341863 -2.078963192  0.220715588  1.466918585
[176]  1.495090086  0.204738409  0.019196649  0.195276173 -1.419631275
[181]  0.288115073 -1.278553852  0.161648645 -3.066711274  0.146078087
[186] -0.959550938 -0.598935016 -1.165462593 -0.419906574  0.651047423
[191] -0.069611567 -1.402338852  1.861505024 -0.338825853 -1.211667246
[196]  1.167268561  0.682943529  2.082099875  2.216145861 -0.534574444
[201] -0.730960438 -0.590766655 -0.414446854 -0.077441782 -0.354556950
[206] -1.304412291  1.653669399  0.186477896 -0.715784770  0.144401717
> 
>     #----------------------------------------------------#
>     # 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)

 *** Combined Fit ***

Call:
lm(formula = YinternalY ~ gender + race + parentBMI + baselineBMI + 
    A1 + parentBMI:A1 + baselineBMI:A1, data = data)

Coefficients:
   (Intercept)          gender            race       parentBMI     baselineBMI  
      -9.67829         0.12936        -0.14287        -0.01321         0.08463  
            A1    parentBMI:A1  baselineBMI:A1  
       2.28865        -0.04067        -0.01825  

> 
>     # Estimated Value functions
>     vals <- qFuncs(iqV2)
>     head(vals)
            -1         1
[1,] -7.554845 -6.856196
[2,] -7.171035 -6.410209
[3,] -7.216036 -6.446657
[4,] -7.306161 -6.305271
[5,] -7.670237 -6.514311
[6,] -7.387716 -6.533904
> 
>     # Residuals
>     res <- residuals(iqV2)
>     head(res)
[1] -0.1537261  1.2592978 -0.2984719  0.3800842  0.5125149 -0.2666877
> 
>     # Model parameter estimates
>     coef(iqV2)
$Combined
   (Intercept)         gender           race      parentBMI    baselineBMI 
   -9.67828628     0.12936481    -0.14287473    -0.01320953     0.08462656 
            A1   parentBMI:A1 baselineBMI:A1 
    2.28864523    -0.04067470    -0.01825134 

> 
>     # Summary information for fit object
>     #summary(iqV2)
> 
>     # QQ-plot
>     plot(iqV2)
> 
>     # Value objects returned by modeling function
>     fitObj <- fitObject(iqV2)
>     fitObj
$Combined

Call:
lm(formula = YinternalY ~ gender + race + parentBMI + baselineBMI + 
    A1 + parentBMI:A1 + baselineBMI:A1, data = data)

Coefficients:
   (Intercept)          gender            race       parentBMI     baselineBMI  
      -9.67829         0.12936        -0.14287        -0.01321         0.08463  
            A1    parentBMI:A1  baselineBMI:A1  
       2.28865        -0.04067        -0.01825  


> 
>     # All standard lm  methods can be applied to the elements of this list.
>     summary(fitObj[[ "Combined" ]])

Call:
lm(formula = YinternalY ~ gender + race + parentBMI + baselineBMI + 
    A1 + parentBMI:A1 + baselineBMI:A1, data = data)

Residuals:
    Min      1Q  Median      3Q     Max 
-8.1801 -0.9656  0.4299  1.4495  3.0512 

Coefficients:
               Estimate Std. Error t value Pr(>|t|)    
(Intercept)    -9.67829    1.52671  -6.339 1.48e-09 ***
gender          0.12936    0.29329   0.441   0.6596    
race           -0.14287    0.29477  -0.485   0.6284    
parentBMI      -0.01321    0.02769  -0.477   0.6338    
baselineBMI     0.08463    0.04207   2.011   0.0456 *  
A1              2.28865    1.52066   1.505   0.1339    
parentBMI:A1   -0.04067    0.02781  -1.463   0.1452    
baselineBMI:A1 -0.01825    0.04238  -0.431   0.6672    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 2.092 on 202 degrees of freedom
Multiple R-squared:  0.05064,	Adjusted R-squared:  0.01774 
F-statistic: 1.539 on 7 and 202 DF,  p-value: 0.1558

>     coef(fitObj[[ "Combined" ]])
   (Intercept)         gender           race      parentBMI    baselineBMI 
   -9.67828628     0.12936481    -0.14287473    -0.01320953     0.08462656 
            A1   parentBMI:A1 baselineBMI:A1 
    2.28864523    -0.04067470    -0.01825134 
>     head(residuals(fitObj[[ "Combined" ]]))
         1          2          3          4          5          6 
-0.1537261  1.2592978 -0.2984719  0.3800842  0.5125149 -0.2666877 
>     head(fitted.values(fitObj[[ "Combined" ]]))
        1         2         3         4         5         6 
-7.554845 -7.171035 -6.446657 -7.306161 -7.670237 -6.533904 
>     plot(fitObj[[ "Combined"]])
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>