|
a |
|
b/R/fit_Tweedieverse.R |
|
|
1 |
fit.Tweedieverse <- function(features, |
|
|
2 |
metadata, |
|
|
3 |
base_model = 'CPLM', |
|
|
4 |
link = "log", |
|
|
5 |
formula = NULL, |
|
|
6 |
random_effects_formula = NULL, |
|
|
7 |
cutoff_ZSCP = 0.3, |
|
|
8 |
criteria_ZACP = 'BIC', |
|
|
9 |
adjust_offset = TRUE, |
|
|
10 |
correction = 'BH', |
|
|
11 |
cores = 4, |
|
|
12 |
optimizer = 'nlminb', |
|
|
13 |
na.action = na.exclude) { |
|
|
14 |
|
|
|
15 |
################################################################ |
|
|
16 |
# Set the formula default to all fixed effects if not provided # |
|
|
17 |
################################################################ |
|
|
18 |
|
|
|
19 |
if ("offset" %in% colnames(metadata)) { |
|
|
20 |
all_available_metadata <- setdiff(colnames(metadata), "offset") |
|
|
21 |
if (is.null(formula)) |
|
|
22 |
formula <- |
|
|
23 |
as.formula(paste("expr ~ ", paste(all_available_metadata, collapse = "+"))) |
|
|
24 |
if (adjust_offset) |
|
|
25 |
formula <- update(formula, . ~ . - offset(log(offset))) |
|
|
26 |
} else{ |
|
|
27 |
if (is.null(formula)) |
|
|
28 |
formula <- |
|
|
29 |
as.formula(paste("expr ~ ", paste(colnames(metadata), collapse = "+"))) |
|
|
30 |
} |
|
|
31 |
|
|
|
32 |
|
|
|
33 |
############################################################## |
|
|
34 |
# Call per-feature base models and return results for output # |
|
|
35 |
############################################################## |
|
|
36 |
|
|
|
37 |
if (base_model == 'CPLM') { |
|
|
38 |
fit <- fit.CPLM( |
|
|
39 |
features = features, |
|
|
40 |
metadata = metadata, |
|
|
41 |
link = link, |
|
|
42 |
formula = formula, |
|
|
43 |
random_effects_formula = random_effects_formula, |
|
|
44 |
correction = correction, |
|
|
45 |
cores = cores, |
|
|
46 |
optimizer = optimizer, |
|
|
47 |
na.action = na.action |
|
|
48 |
) |
|
|
49 |
|
|
|
50 |
} |
|
|
51 |
|
|
|
52 |
if (base_model == 'ZICP') { |
|
|
53 |
fit <- fit.ZICP( |
|
|
54 |
features = features, |
|
|
55 |
metadata = metadata, |
|
|
56 |
link = link, |
|
|
57 |
formula = formula, |
|
|
58 |
random_effects_formula = random_effects_formula, |
|
|
59 |
correction = correction, |
|
|
60 |
cores = cores, |
|
|
61 |
optimizer = optimizer, |
|
|
62 |
na.action = na.action |
|
|
63 |
) |
|
|
64 |
} |
|
|
65 |
|
|
|
66 |
|
|
|
67 |
if (base_model == 'ZSCP') { |
|
|
68 |
fit <- fit.ZSCP( |
|
|
69 |
features = features, |
|
|
70 |
metadata = metadata, |
|
|
71 |
link = link, |
|
|
72 |
formula = formula, |
|
|
73 |
random_effects_formula = random_effects_formula, |
|
|
74 |
cutoff_ZSCP = cutoff_ZSCP, |
|
|
75 |
correction = correction, |
|
|
76 |
cores = cores, |
|
|
77 |
optimizer = optimizer, |
|
|
78 |
na.action = na.action |
|
|
79 |
) |
|
|
80 |
} |
|
|
81 |
|
|
|
82 |
if (base_model == 'ZACP') { |
|
|
83 |
fit <- fit.ZACP( |
|
|
84 |
features = features, |
|
|
85 |
metadata = metadata, |
|
|
86 |
link = link, |
|
|
87 |
formula = formula, |
|
|
88 |
random_effects_formula = random_effects_formula, |
|
|
89 |
criteria_ZACP = criteria_ZACP, |
|
|
90 |
correction = correction, |
|
|
91 |
cores = cores, |
|
|
92 |
optimizer = optimizer, |
|
|
93 |
na.action = na.action |
|
|
94 |
) |
|
|
95 |
} |
|
|
96 |
return(fit) |
|
|
97 |
} |