Skip to content

Commit

Permalink
set approx to TRUE by default
Browse files Browse the repository at this point in the history
  • Loading branch information
jchiquet committed Mar 26, 2024
1 parent 0df94b9 commit 2744eb1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion R/ZIPLN.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ ZIPLN_param <- function(
config_opt$trace <- trace
config_opt$ftol_out <- 1e-6
config_opt$maxit_out <- 100
config_opt$approx_ZI <- FALSE
config_opt$approx_ZI <- TRUE
config_opt[names(config_optim)] <- config_optim

structure(list(
Expand Down
4 changes: 2 additions & 2 deletions R/ZIPLNnetwork.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ ZIPLNnetwork_param <- function(
config_opt <- config_default_nlopt
config_opt$trace <- trace
config_opt$ftol_out <- 1e-6
config_opt$maxit_out <- 100
config_opt$approx_ZI <- FALSE
config_opt$maxit_out <- 50
config_opt$approx_ZI <- TRUE
config_opt[names(config_optim)] <- config_optim
inception_cov <- match.arg(inception_cov)

Expand Down
30 changes: 30 additions & 0 deletions inst/case_studies/scRNA.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,36 @@ scRNA$counts <- scRNA$counts[, 1:200]
myZIPLN <- ZIPLN(counts ~ 1 + offset(log(total_counts)), zi = "col", data = scRNA)
myPLN <- PLN(counts ~ 1 + offset(log(total_counts)), data = scRNA)

true_zeros <- scRNA$counts == 0
n_zeros <- sum(true_zeros)
n_nzeros <- sum(!true_zeros)

data.frame(
fitted = c(as.vector(fitted(myPLN)[true_zeros]), as.vector(fitted(myZIPLN)[true_zeros])),
obs = rep(1:n_zeros, 2),
method = factor(rep(c("PLN", "ZI (1 par per species)"), each = n_zeros))
) %>%
ggplot() +
geom_rug(aes(x = fitted, color = method)) +
geom_point(aes(x = obs, y = fitted, color = method), size = 0.3, alpha = 0.1) +
ggtitle("Distribution of observed zeros as fitted by the models") +
xlab(label = "observations #") +
scale_color_viridis_d() + theme_bw()

# distribution of non zero
data.frame(
fitted = c(as.vector(fitted(myPLN)[!true_zeros]), as.vector(fitted(myZIPLN)[!true_zeros])),
observed = rep(c(scRNA$counts[!true_zeros]), 2),
method = factor(rep(c("PLN", "ZI (1 par per species)"), each = n_nzeros))
) %>%
ggplot(aes(x = observed, y = fitted)) +
geom_point(size = .5, alpha =.25 ) +
facet_wrap( ~ method) +
scale_x_log10() +
scale_y_log10() +
theme_bw() + annotation_logticks()


data.frame(
fitted = c(as.vector(fitted(myZIPLN)), as.vector(fitted(myPLN))),
observed = rep(as.vector(scRNA$counts), 2),
Expand Down

0 comments on commit 2744eb1

Please sign in to comment.