[727782]: / R / fit_Tweedieverse.R

Download this file

98 lines (87 with data), 2.9 kB

 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
fit.Tweedieverse <- function(features,
metadata,
base_model = 'CPLM',
link = "log",
formula = NULL,
random_effects_formula = NULL,
cutoff_ZSCP = 0.3,
criteria_ZACP = 'BIC',
adjust_offset = TRUE,
correction = 'BH',
cores = 4,
optimizer = 'nlminb',
na.action = na.exclude) {
################################################################
# Set the formula default to all fixed effects if not provided #
################################################################
if ("offset" %in% colnames(metadata)) {
all_available_metadata <- setdiff(colnames(metadata), "offset")
if (is.null(formula))
formula <-
as.formula(paste("expr ~ ", paste(all_available_metadata, collapse = "+")))
if (adjust_offset)
formula <- update(formula, . ~ . - offset(log(offset)))
} else{
if (is.null(formula))
formula <-
as.formula(paste("expr ~ ", paste(colnames(metadata), collapse = "+")))
}
##############################################################
# Call per-feature base models and return results for output #
##############################################################
if (base_model == 'CPLM') {
fit <- fit.CPLM(
features = features,
metadata = metadata,
link = link,
formula = formula,
random_effects_formula = random_effects_formula,
correction = correction,
cores = cores,
optimizer = optimizer,
na.action = na.action
)
}
if (base_model == 'ZICP') {
fit <- fit.ZICP(
features = features,
metadata = metadata,
link = link,
formula = formula,
random_effects_formula = random_effects_formula,
correction = correction,
cores = cores,
optimizer = optimizer,
na.action = na.action
)
}
if (base_model == 'ZSCP') {
fit <- fit.ZSCP(
features = features,
metadata = metadata,
link = link,
formula = formula,
random_effects_formula = random_effects_formula,
cutoff_ZSCP = cutoff_ZSCP,
correction = correction,
cores = cores,
optimizer = optimizer,
na.action = na.action
)
}
if (base_model == 'ZACP') {
fit <- fit.ZACP(
features = features,
metadata = metadata,
link = link,
formula = formula,
random_effects_formula = random_effects_formula,
criteria_ZACP = criteria_ZACP,
correction = correction,
cores = cores,
optimizer = optimizer,
na.action = na.action
)
}
return(fit)
}