Skip to content

Commit 9c56201

Browse files
committed
updated vignette to include data on analysis with replicates
1 parent 231b901 commit 9c56201

10 files changed

+197
-48
lines changed

DESCRIPTION

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ Suggests:
3333
ggplot2,
3434
ggforce,
3535
gridExtra,
36-
ggrepel
36+
ggrepel,
37+
patchwork
3738
LinkingTo:
3839
BH (>= 1.66.0),
3940
Rcpp (>= 0.12.0),

NEWS

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Changes in version 1.17
2-
+ model explanded for designs with biological replicates
2+
+ model expanded for designs with biological replicates
3+
+ model expanded for paired sample designs (also with replicates)
34

45
Changes in version 1.15
56
+ model for gene usage (GU) analysis

R/dgu.R

+34-31
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11

22
DGU <- function(ud,
3-
mcmc_warmup = 500,
4-
mcmc_steps = 1500,
5-
mcmc_chains = 4,
6-
mcmc_cores = 1,
7-
hdi_lvl = 0.95,
8-
adapt_delta = 0.95,
9-
max_treedepth = 12) {
3+
mcmc_warmup = 500,
4+
mcmc_steps = 1500,
5+
mcmc_chains = 4,
6+
mcmc_cores = 1,
7+
hdi_lvl = 0.95,
8+
adapt_delta = 0.95,
9+
max_treedepth = 12,
10+
paired = FALSE) {
1011

1112
# check inputs
1213
check_dgu_input(ud = ud,
13-
mcmc_chains = base::as.integer(x = mcmc_chains),
14-
mcmc_cores = base::as.integer(x = mcmc_cores),
15-
mcmc_steps = base::as.integer(x = mcmc_steps),
16-
mcmc_warmup = base::as.integer(x = mcmc_warmup),
17-
hdi_lvl = hdi_lvl)
14+
mcmc_chains = as.integer(x = mcmc_chains),
15+
mcmc_cores = as.integer(x = mcmc_cores),
16+
mcmc_steps = as.integer(x = mcmc_steps),
17+
mcmc_warmup = as.integer(x = mcmc_warmup),
18+
hdi_lvl = hdi_lvl,
19+
paired = paired)
1820

1921
udr <- ud
2022
ud <- get_usage(u = udr)
@@ -25,19 +27,20 @@ DGU <- function(ud,
2527

2628
# get model
2729
m <- get_model(has_conditions = ud$has_conditions,
28-
has_replicates = ud$has_replicates)
30+
has_replicates = ud$has_replicates,
31+
paired = paired)
2932

3033
# fit model
31-
glm <- rstan::sampling(object = m$model,
32-
data = ud,
33-
chains = mcmc_chains,
34-
cores = mcmc_cores,
35-
iter = mcmc_steps,
36-
warmup = mcmc_warmup,
37-
algorithm = "NUTS",
38-
control = control_list,
39-
pars = m$pars,
40-
refresh = 50)
34+
glm <- sampling(object = m$model,
35+
data = ud,
36+
chains = mcmc_chains,
37+
cores = mcmc_cores,
38+
iter = mcmc_steps,
39+
warmup = mcmc_warmup,
40+
algorithm = "NUTS",
41+
control = control_list,
42+
pars = m$pars,
43+
refresh = 50)
4144

4245
message("Computing summaries ... \n")
4346
gu <- get_condition_prop(glm = glm, hdi_lvl = hdi_lvl, ud = ud,
@@ -47,7 +50,7 @@ DGU <- function(ud,
4750
dgu_prob <- get_dgu_prob(glm = glm, hdi_lvl = hdi_lvl, ud = ud,
4851
model_type = m$model_type)
4952
theta <- get_sample_prop_gu(glm = glm, hdi_lvl = hdi_lvl, ud = ud)
50-
53+
5154

5255
# ppc
5356
message("Computing posterior predictions ... \n")
@@ -56,11 +59,11 @@ DGU <- function(ud,
5659
ppc_condition = get_ppc_condition(glm = glm, ud = ud, hdi_lvl = hdi_lvl))
5760

5861
# result pack
59-
return (list(dgu = dgu,
60-
dgu_prob = dgu_prob,
61-
gu = gu,
62-
theta = theta,
63-
ppc = ppc,
64-
ud = ud,
65-
fit = glm))
62+
return(list(dgu = dgu,
63+
dgu_prob = dgu_prob,
64+
gu = gu,
65+
theta = theta,
66+
ppc = ppc,
67+
ud = ud,
68+
fit = glm))
6669
}

R/loo.R

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ LOO <- function(ud,
88
mcmc_cores = 1,
99
hdi_lvl = 0.95,
1010
adapt_delta = 0.95,
11-
max_treedepth = 12) {
11+
max_treedepth = 12,
12+
paired = FALSE) {
1213

1314
# check inputs
1415
check_dgu_input(ud = ud,
1516
mcmc_chains = as.integer(x = mcmc_chains),
1617
mcmc_cores = as.integer(x = mcmc_cores),
1718
mcmc_steps = as.integer(x = mcmc_steps),
1819
mcmc_warmup = as.integer(x = mcmc_warmup),
19-
hdi_lvl = hdi_lvl)
20+
hdi_lvl = hdi_lvl,
21+
paired = paired)
2022

2123
# process data
2224
udp <- get_usage(u = ud)
@@ -57,7 +59,8 @@ LOO <- function(ud,
5759
mcmc_cores = mcmc_cores,
5860
hdi_lvl = hdi_lvl,
5961
adapt_delta = adapt_delta,
60-
max_treedepth = max_treedepth)
62+
max_treedepth = max_treedepth,
63+
paired = paired)
6164

6265
if(is.data.frame(out$gu)==TRUE) {
6366
out$gu$loo_id <- rs[r]

R/utils_input.R

+19-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ check_dgu_input <- function(ud,
88
mcmc_cores,
99
mcmc_steps,
1010
mcmc_warmup,
11-
hdi_lvl) {
11+
hdi_lvl,
12+
paired) {
1213

1314
if(missing(ud) || is.null(ud) ||
1415
missing(mcmc_chains) || is.null(mcmc_chains) ||
1516
missing(mcmc_steps) || is.null(mcmc_steps) ||
1617
missing(mcmc_warmup) || is.null(mcmc_warmup) ||
1718
missing(mcmc_cores) || is.null(mcmc_cores) ||
18-
missing(hdi_lvl) || is.null(hdi_lvl)) {
19+
missing(hdi_lvl) || is.null(hdi_lvl) ||
20+
missing(paired) || is.null(paired)) {
1921
stop("arguments must be specified")
2022
}
2123

@@ -25,6 +27,7 @@ check_dgu_input <- function(ud,
2527
check_mcmc_chains(mcmc_chains = mcmc_chains)
2628
check_mcmc_cores(mcmc_cores = mcmc_cores)
2729
check_hdi(hdi_lvl = hdi_lvl)
30+
check_paired(paired = paired)
2831
}
2932

3033

@@ -168,3 +171,17 @@ check_ud <- function(ud) {
168171
}
169172
}
170173
}
174+
175+
176+
177+
# Description:
178+
# paired input check
179+
check_paired <- function(paired) {
180+
if(length(paired) != 1) {
181+
stop('paired must be a logical (TRUE or FALSE)')
182+
}
183+
184+
if(is.logical(paired) == FALSE) {
185+
stop('paired must be a logical (TRUE or FALSE)')
186+
}
187+
}

R/utils_usage.R

+27-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,26 @@ get_usage <- function(u) {
9393
has_conditions = max(condition_ids)>1))
9494
}
9595

96-
get_model <- function(has_replicates, has_conditions, debug = FALSE) {
96+
97+
98+
# Description:
99+
# checks for structural problems in the data, and mismatch with given inputs
100+
check_ud_content <- function(ud, paired) {
101+
has_conditions <- ud$has_conditions
102+
has_replicates <- ud$has_replicates
103+
ud <- M$ud$proc_ud
104+
105+
table(ud$sample_id)
106+
diag(table(ud$sample_id, ud$individual_id))
107+
identical(diag(table(ud$sample_id, ud$individual_id)))
108+
}
109+
110+
111+
112+
113+
get_model <- function(has_replicates, has_conditions, paired, debug = FALSE) {
97114
model_type <- ifelse(test = has_conditions, yes = "DGU", no = "GU")
115+
98116
if(model_type == "GU") {
99117
if(has_replicates) {
100118
if(debug) {
@@ -136,6 +154,9 @@ get_model <- function(has_replicates, has_conditions, debug = FALSE) {
136154
"Yhat_rep", "Yhat_rep_prop", "Yhat_condition_prop",
137155
"log_lik", "dgu", "dgu_prob", "theta")
138156
model_name <- "DGU_rep"
157+
if(paired) {
158+
model_name <- "DGU_rep_paired"
159+
}
139160
}
140161
else {
141162
if(debug) {
@@ -149,6 +170,9 @@ get_model <- function(has_replicates, has_conditions, debug = FALSE) {
149170
"Yhat_rep", "Yhat_rep_prop", "Yhat_condition_prop",
150171
"log_lik", "dgu", "dgu_prob", "theta")
151172
model_name <- "DGU"
173+
if(paired) {
174+
model_name <- "DGU_paired"
175+
}
152176
}
153177
}
154178

@@ -157,5 +181,6 @@ get_model <- function(has_replicates, has_conditions, debug = FALSE) {
157181
model_type = model_type,
158182
pars = pars,
159183
has_replicates = has_replicates,
160-
has_conditions = has_conditions))
184+
has_conditions = has_conditions,
185+
paired = paired))
161186
}

man/d_zibb_1.Rd

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A small example dataset that has the following features:
88

99
\itemize{
1010
\item 1 conditions
11-
\item 5 replicates (samples) per condition
11+
\item 5 samples per condition
1212
\item 15 Ig genes
1313
}
1414
This dataset was simulated from zero-inflated beta-binomial (ZIBB)

man/d_zibb_2.Rd

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A small example dataset that has the following features:
88

99
\itemize{
1010
\item 2 conditions
11-
\item 5 replicates (samples) per condition
11+
\item 5 samples per condition
1212
\item 15 Ig genes
1313
}
1414
This dataset was simulated from zero-inflated beta-binomial (ZIBB)

man/d_zibb_3.Rd

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A small example dataset that has the following features:
88

99
\itemize{
1010
\item 3 conditions
11-
\item 5 replicates (samples) per condition
11+
\item 5 samples per condition
1212
\item 15 Ig genes
1313
}
1414
This dataset was simulated from zero-inflated beta-binomial (ZIBB)

0 commit comments

Comments
 (0)