combine_data_nplcm: combine multiple data_nplcm (useful when simulating data from...

Description Usage Arguments See Also Examples

View source: R/utils.R

Description

combine multiple data_nplcm (useful when simulating data from regression models)

Usage

1
combine_data_nplcm(data_nplcm_list)

Arguments

data_nplcm_list

a list of data_nplcm in nplcm

See Also

Other data operation functions: merge_lists(), subset_data_nplcm_by_index()

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
48
49
50
51
52
53
## Not run: 
rm(list=ls())
N=10000
Y = rep(c(1,0),times=5000) # simulate two cases and two controls.
out_list <- vector("list",length=N)
J = 3                          # number of causes
cause_list = c(LETTERS[1:J])   # cause list
K = 2                          # number of subclasses
lambda = c(.8,.2)                # subclass weights for control group
eta = c(.9,.1)                   # subclass weights for case group

for (i in 1:N){
  #setup parameters for the present individual:
  set_parameter <- list(
    cause_list      = cause_list,
    etiology        = c(0.5,0.2,0.3), # only meaningful for cases 
    pathogen_BrS    = LETTERS[1:J],
    pathogen_SS     = LETTERS[1:2],
    meas_nm         = list(MBS = c("MBS1"),MSS=c("MSS1")),
    Lambda          = lambda,         # for BrS   
    Eta             = t(replicate(J,eta)),  # case subclass weight for BrS
    PsiBS           = cbind(c(0.15,0.3,0.35),   
                            c(0.25,0.2,0.15)), # FPR
    PsiSS           = cbind(rep(0,J),rep(0,J)),
    ThetaBS         = cbind(c(0.95,0.9,0.85),    # TPR
                            c(0.95,0.9,0.85)),
    ThetaSS         = cbind(c(0.25,0.10),
                            c(0.25,0.10)),
    Nd      =     1,
    Nu      =     1 
  )
  simu_out   <- simulate_nplcm(set_parameter)
  out <- simu_out$data_nplcm
  out_list[[i]] <- out
}

# extract cases and controls and combine all the data into one:
data_nplcm_list <- lapply(1:N, function(s) subset_data_nplcm_by_index(out_list[[s]],2-Y[s]))
data_nplcm_unordered      <- combine_data_nplcm(data_nplcm_list) 
data_nplcm_unordered

colMeans(data_nplcm_unordered$Mobs$MBS$MBS1[Y==1,])
colMeans(data_nplcm_unordered$Mobs$MBS$MBS1[Y==0,])

set_parameter$PsiBS%*%matrix(lambda,ncol=1)
set_parameter$PsiBS%*%matrix(eta,ncol=1)*(1-set_parameter$etiology)+
  set_parameter$ThetaBS%*%matrix(eta,ncol=1)*set_parameter$etiology

# data_nplcm <- subset_data_nplcm_by_index(data_nplcm_unordered,
#                    order(-data_nplcm_unordered$Y)) #put cases on top.


## End(Not run)

oslerinhealth/baker documentation built on May 22, 2021, 12:05 p.m.