GenericModel: Generic R6 class for modeling (fitting and predicting)...

Description Usage Format Details Methods Active Bindings See Also Examples

Description

GenericModel defines and models the conditional density P(A=a|W=w,E=e), where a are generated under g_star or g_0. By calling self$new(reg), it utilizes estimation options defined in RegressionClass class, and automatically factorizes the multivariate conditional probability model P(A|W,E) into M univariate conditional probability models (can be binary, categorical or continuous) and finally an entire tree of binary regression models (see details in tmleCommunity), where a new instance of BinaryOutModel class will be initialized for each binary regression (If one outcome variable A[m] is already binary, then immediately call a new instance of BinaryOutModel). By calling self$fit(data) and self$predict(newdata), where data and newdata are DatKeepClass class objects, it fits P(A|W,E) and predicts P(A=1|W=w,E=e), where values of (w,e) are from newdata. Moreover, it predicts likelihood function P(A=a| W=w,E=e) through self$predictAeqa(newdata), where (a,w,e) are from newdata (also a DatKeepClass class).

Usage

1

Format

An R6Class generator object

Details

Methods

new(reg, ...)

Use reg (a RegressionClass object) to instantiate an new object of GenericModel

length

Get the number of regression models (i.e., the number of exposure viarables)

getPsAsW.models

Get all model objects (one model object per outcome var A[m])

getcumprodAeqa

Get joint prob as a vector of the cumulative prod over j for P(A[m]=a[m]|W,E)

fit(data, savespace = TRUE)

...

copy.fit(Generic.Model)

...

predict(newdata, savespace = TRUE)

...

predictAeqa(newdata, savespace = TRUE, wipeProb = TRUE, ...)

...

Active Bindings

wipe.alldat(wipeProb = TRUE)

...

See Also

DatKeepClass, RegressionClass, ContinModel, CategorModel, BinaryOutModel

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
## Not run: 
#***************************************************************************************
# Example 1: Defining and modeling P(A | W) with continuous A
data(indSample.iid.cA.cY_list)
indSample.iid.cA.cY <- indSample.iid.cA.cY_list$indSample.iid.cA.cY
nodes <- list(Ynode = "Y", Anodes = "A", WEnodes = c("W1", "W2", "W3", "W4"))
tmleCom_Options(gestimator = "speedglm__glm", maxNperBin = nrow(indSample.iid.cA.cY),
                bin.method = "equal.mass", nbins = 10)
options(tmleCommunity.verbose = FALSE)  # Don't print status messages
#***************************************************************************************

#***************************************************************************************
# 1.1 Defining new R6 objects of DatKeepClass and RegressionClass and GenericModel
#***************************************************************************************
OData.g0 <- DatKeepClass$new(Odata = indSample.iid.cA.cY, nodes = nodes)
h.g0.sVars <- tmleCommunity:::define_regform(NULL, Anodes.lst = nodes$Anodes, 
                                             Wnodes.lst = nodes$WEnodes)
subsets_expr <- lapply(h.g0.sVars$outvars, function(var) {var}) 
regclass.g0 <- RegressionClass$new(outvar = h.g0.sVars$outvars,
                                   predvars = h.g0.sVars$predvars,
                                   subset_vars = subsets_expr,
                                   outvar.class = OData.g0$type.sVar[h.g0.sVars$outvars])
genericmodels.g0 <- GenericModel$new(reg = regclass.g0, DatKeepClass.g0 = OData.g0)

#***************************************************************************************
# 1.2 Details regarding the GenericModel of the first exposure variable  
#***************************************************************************************
genericmodels.g0.A1 <- genericmodels.g0$getPsAsW.models()$`P(A|W).1` 
genericmodels.g0$getPsAsW.models()$`P(A|W).2`  # NULL as only one A in the input data
# Defining the number and positions of the bins via arguments in tmleCom_Options()
genericmodels.g0.A1$intrvls  
# Creating a matrix of dummy bin indicators for continuous A
OData.g0$binirize.sVar(name.sVar = genericmodels.g0.A1$outvar, 
                       intervals = genericmodels.g0.A1$intrvls, 
                       nbins = genericmodels.g0.A1$reg$nbins, 
                       bin.nms = genericmodels.g0.A1$bin_nms)  
bin.ind.mat <- OData.g0$dat.bin.sVar
colSums(bin.ind.mat, na.rm = TRUE)   # Each bin has 1000 obs as "equal.mass" with 10 bins

#***************************************************************************************
# 1.3 Fitting regression models for the first exposure variable  
#***************************************************************************************
genericmodels.g0.A1$fit(data = OData.g0)
genericmodels.g0.A1.B2 <- genericmodels.g0.A1$getPsAsW.models()$`P(A|W).2`  # 2nd bin
genericmodels.g0.A1.B2$getfit$coef

## End(Not run)

chizhangucb/tmleCommunity documentation built on May 20, 2019, 3:34 p.m.