diff --git a/R/poiss_boostrap_em.R b/R/poiss_boostrap_em.R index ca20b322fcd2ca8e178d0f248447cf384698cc6e..82022c8471653ae81fc38548b5c6284c1dc8fff1 100644 --- a/R/poiss_boostrap_em.R +++ b/R/poiss_boostrap_em.R @@ -4,12 +4,14 @@ #' #' @param x a matrix of male female kmers counts #' @param params a list of init parameters +#' @param gamma a vector of kappa prior #' @param threshold theshold to stop the EM algorithm +#' @param nbatch (default: 10) the number of batch #' @param nboot number of boostrap sample -#' @param frac (default: 1.) fraction of the data to use at each step #' @param bootsize size of the boostrap sample (if < 0 we take a percentage of x) #' @param core number of cpus to use for the computation #' @param max_iter (default: 100) maximum number of iteration +#' @param max_error (default: 5) maximum number of try #' @return tibble of the statistics #' @importFrom dplyr sample_n sample_frac #' @importFrom parallel mclapply @@ -20,73 +22,23 @@ #' extraDistr::rbvpois(100, 20, 0, 5) # Y #' ) %>% pois_boostrap_EM(nboot = 10) #' @noRd -poiss_boostrap_EM <- function(x, sex = "XY", threshold = 1, nboot = 100, frac = 1, bootsize = 1, core = 1, max_iter = 100) { +poiss_boostrap_EM <- function(x, sex = "XY", threshold = 1, nboot = 100, nbatch = nbatch, bootsize = 1, core = 1, max_iter = 100, max_error = 5) { params = list( A = list(kappa = 0.4, l1 = mean(x), l2 = mean(x), l3 = mean(x)) ) - if (sex %in% c("XO", "XY")) { - params$X <- list(kappa = 0.3, l1 = 1, l2 = mean(x), l3 = mean(x)) - } - if (sex == "XY") { - params$Y <- list(kappa = 0.3, l1 = mean(x), l2 = 1, l3 = mean(x)) - } + gamma <- c(round(nrow(x) * bootsize)) + if (sex %in% c("XO", "XY")) { + params$X <- list(kappa = 0.3, l1 = 1, l2 = mean(x), l3 = mean(x)) + gamma <- c(round(nrow(x) * bootsize) * .8, round(nrow(x) * bootsize) * .2) + } + if (sex == "XY") { + params$Y <- list(kappa = 0.3, l1 = mean(x), l2 = 1, l3 = mean(x)) + gamma <- c(round(nrow(x) * bootsize) * .8, round(nrow(x) * bootsize) * .15, round(nrow(x) * bootsize) * .05) + } if (core == 1) { - res <- lapply(as.list(1:nboot), function(iter, x, bootsize) { - res <- x %>% - as_tibble() %>% - sample_frac(bootsize, replace = T) %>% - as.matrix() %>% - em_bipoiss_clust(params = params, frac = frac, max_iter = max_iter) - print(tibble(loglik = res$loglik, BIC = res$BIC)) - return(tibble(loglik = res$loglik, BIC = res$BIC)) - }, x = x, bootsize = bootsize) + res <- lapply(as.list(1:nboot), FUN = poiss_boostrap_EM_sub, x = x, bootsize = bootsize, nbatch = nbatch, params = params, gamma = gamma, max_iter = max_iter, max_error = max_error) } else { - res <- parallel::mclapply(as.list(1:nboot), function(iter, x, bootsize) { - res <- tryCatch({ - x %>% - as_tibble() %>% - sample_frac(bootsize, replace = T) %>% - as.matrix() %>% - em_bipoiss_clust(params, frac = frac, max_iter = max_iter) - }, error = function(e) { - x %>% - as_tibble() %>% - sample_frac(bootsize, replace = T) %>% - as.matrix() %>% - em_bipoiss_clust(params, frac = frac, max_iter = max_iter) - }) - return(tibble(loglik = res$loglik, BIC = res$BIC)) - }, x = x, bootsize = bootsize, mc.cores = core) + res <- parallel::mclapply(as.list(1:nboot), FUN = poiss_boostrap_EM_sub, x = x, bootsize = bootsize, nbatch = nbatch, params = params, gamma = gamma, max_iter = max_iter, max_error = max_error, mc.cores = core) } return(res) } - -#' Function to compile statistics differences between model XY and XO on boostrap -#' samples of the data -#' -#' @param x a matrix of male female kmers counts -#' @param threshold theshold to stop the EM algorithm -#' @param nboot number of boostrap sample -#' @param bootsize size of the boostrap sample (if < 0 we take a percentage of x) -#' @param frac (default: 1.) fraction of the data to use at each step -#' @param core number of cpus to use for the computation -#' @param max_iter (default: 100) maximum number of iteration -#' @return tibble with the statistics -#' @importFrom tidyr pivot_longer -#' @export -#' @examples -#' res <- rbind( -#' extraDistr::rbvpois(1000, 10, 10, 20), # A -#' extraDistr::rbvpois(1000, 0, 20, 20), # X -#' extraDistr::rbvpois(1000, 20, 0, 5) # Y -#' ) %>% -#' poiss_compare_models(nboot = 3, core = 1) -poiss_compare_models <- function(x, threshold = 1, nboot = 100, bootsize = 1, frac = 1, core = 1, max_iter = 100) { - tibble( - model_XY = poiss_boostrap_EM(x, sex = "XY", threshold = threshold, nboot = nboot, frac = 1, bootsize = bootsize, core = core, max_iter = max_iter), - model_XO = poiss_boostrap_EM(x, sex = "XO", threshold = threshold, nboot = nboot, frac = 1, bootsize = bootsize, core = core, max_iter = max_iter), - model_OO = poiss_boostrap_EM(x, sex = "OO", threshold = threshold, nboot = nboot, frac = 1, bootsize = bootsize, core = core, max_iter = max_iter) - ) %>% - pivot_longer(cols = c(model_XY, model_XO, model_OO)) %>% - unnest(c(value)) -} diff --git a/R/poiss_boostrap_em_sub.R b/R/poiss_boostrap_em_sub.R index d59aed85fbd47de1dcb47ac6d89f42c423f50fb2..09f0ef91ba7f1299edc8558ab10831230c58a9cb 100644 --- a/R/poiss_boostrap_em_sub.R +++ b/R/poiss_boostrap_em_sub.R @@ -7,6 +7,7 @@ #' @param gamma a vector of kappa prior #' @param threshold theshold to stop the EM algorithm #' @param nboot number of boostrap sample +#' @param nbatch (default: 10) the number of batch #' @param bootsize size of the boostrap sample (if < 0 we take a percentage of x) #' @param core number of cpus to use for the computation #' @param max_iter (default: 100) maximum number of iteration @@ -21,7 +22,7 @@ #' extraDistr::rbvpois(100, 20, 0, 5) # Y #' ) %>% pois_boostrap_EM(nboot = 10) #' @noRd -poiss_boostrap_EM_sub <- function(iter, x, bootsize, params, gamma, max_iter, max_error) { +poiss_boostrap_EM_sub <- function(iter, x, bootsize, nbatch = nbatch, params, gamma, max_iter, max_error) { res <- list() res$loglik <- c(NA) iter <- 0 @@ -30,80 +31,8 @@ poiss_boostrap_EM_sub <- function(iter, x, bootsize, params, gamma, max_iter, ma as_tibble() %>% sample_frac(bootsize, replace = T) %>% as.matrix() %>% - em_bipoiss_clust(params = params, gamma = gamma, max_iter = max_iter) + em_bipoiss_clust(params = params, gamma = gamma, max_iter = max_iter, nbatch = nbatch) iter <- iter + 1 } return(tibble(loglik = res$loglik, BIC = res$BIC)) } - -#' Function to compile statistics bootstrap samples of the data -#' -#' @param x a matrix of male female kmers counts -#' @param params a list of init parameters -#' @param gamma a vector of kappa prior -#' @param threshold theshold to stop the EM algorithm -#' @param nboot number of boostrap sample -#' @param bootsize size of the boostrap sample (if < 0 we take a percentage of x) -#' @param core number of cpus to use for the computation -#' @param max_iter (default: 100) maximum number of iteration -#' @param max_error (default: 5) maximum number of try -#' @return tibble of the statistics -#' @importFrom dplyr sample_n sample_frac -#' @importFrom parallel mclapply -#' @examples -#' rbind( -#' extraDistr::rbvpois(1000, 10, 10, 20), # A -#' extraDistr::rbvpois(500, 0, 20, 20), # X -#' extraDistr::rbvpois(100, 20, 0, 5) # Y -#' ) %>% pois_boostrap_EM(nboot = 10) -#' @noRd -poiss_boostrap_EM <- function(x, sex = "XY", threshold = 1, nboot = 100, bootsize = 1, core = 1, max_iter = 100, max_error = 5) { - params = list( - A = list(kappa = 0.4, l1 = mean(x), l2 = mean(x), l3 = mean(x)) - ) - gamma <- c(round(nrow(x) * bootsize)) - if (sex %in% c("XO", "XY")) { - params$X <- list(kappa = 0.3, l1 = 1, l2 = mean(x), l3 = mean(x)) - gamma <- c(round(nrow(x) * bootsize) * .8, round(nrow(x) * bootsize) * .2) - } - if (sex == "XY") { - params$Y <- list(kappa = 0.3, l1 = mean(x), l2 = 1, l3 = mean(x)) - gamma <- c(round(nrow(x) * bootsize) * .8, round(nrow(x) * bootsize) * .15, round(nrow(x) * bootsize) * .05) - } - if (core == 1) { - res <- lapply(as.list(1:nboot), FUN = poiss_boostrap_EM_sub, x = x, bootsize = bootsize, params = params, gamma = gamma, max_iter = max_iter, max_error = max_error) - } else { - res <- parallel::mclapply(as.list(1:nboot), FUN = poiss_boostrap_EM_sub, x = x, bootsize = bootsize, params = params, gamma = gamma, max_iter = max_iter, max_error = max_error, mc.cores = core) - } - return(res) -} - -#' Function to compile statistics differences between model XY and XO on boostrap -#' samples of the data -#' -#' @param x a matrix of male female kmers counts -#' @param threshold theshold to stop the EM algorithm -#' @param nboot number of boostrap sample -#' @param bootsize size of the boostrap sample (if < 0 we take a percentage of x) -#' @param core number of cpus to use for the computation -#' @param max_iter (default: 100) maximum number of iteration -#' @param max_error (default: 5) maximum number of try -#' @return tibble with the statistics -#' @importFrom tidyr pivot_longer -#' @export -#' @examples -#' res <- rbind( -#' extraDistr::rbvpois(1000, 10, 10, 20), # A -#' extraDistr::rbvpois(1000, 0, 20, 20), # X -#' extraDistr::rbvpois(1000, 20, 0, 5) # Y -#' ) %>% -#' poiss_compare_models(nboot = 3, core = 1) -poiss_compare_models <- function(x, threshold = 1, nboot = 100, bootsize = 1, core = 1, max_iter = 100, max_error = 5) { - tibble( - model_XY = poiss_boostrap_EM(x, sex = "XY", threshold = threshold, nboot = nboot, bootsize = bootsize, core = core, max_iter = max_iter, max_error = max_error), - model_XO = poiss_boostrap_EM(x, sex = "XO", threshold = threshold, nboot = nboot, bootsize = bootsize, core = core, max_iter = max_iter, max_error = max_error), - model_OO = poiss_boostrap_EM(x, sex = "OO", threshold = threshold, nboot = nboot, bootsize = bootsize, core = core, max_iter = max_iter, max_error = max_error) - ) %>% - pivot_longer(cols = c(model_XY, model_XO, model_OO)) %>% - unnest(c(value)) -} diff --git a/R/poiss_compare_models.R b/R/poiss_compare_models.R new file mode 100644 index 0000000000000000000000000000000000000000..31b80336d139d405181a6ca3140bb4d81050466f --- /dev/null +++ b/R/poiss_compare_models.R @@ -0,0 +1,32 @@ +# WARNING - Generated by {fusen} from dev/flat_full_poisson.Rmd: do not edit by hand + +#' Function to compile statistics differences between model XY and XO on boostrap +#' samples of the data +#' +#' @param x a matrix of male female kmers counts +#' @param threshold theshold to stop the EM algorithm +#' @param nboot number of boostrap sample +#' @param nbatch (default: 10) the number of batch +#' @param bootsize size of the boostrap sample (if < 0 we take a percentage of x) +#' @param core number of cpus to use for the computation +#' @param max_iter (default: 100) maximum number of iteration +#' @param max_error (default: 5) maximum number of try +#' @return tibble with the statistics +#' @importFrom tidyr pivot_longer +#' @export +#' @examples +#' res <- rbind( +#' extraDistr::rbvpois(1000, 10, 10, 20), # A +#' extraDistr::rbvpois(1000, 0, 20, 20), # X +#' extraDistr::rbvpois(1000, 20, 0, 5) # Y +#' ) %>% +#' poiss_compare_models(nboot = 3, core = 1) +poiss_compare_models <- function(x, threshold = 1, nboot = 100, nbatch = 10, bootsize = 1, core = 1, max_iter = 100, max_error = 5) { + tibble( + model_XY = poiss_boostrap_EM(x, sex = "XY", threshold = threshold, nboot = nboot, nbatch = nbatch, bootsize = bootsize, core = core, max_iter = max_iter, max_error = max_error), + model_XO = poiss_boostrap_EM(x, sex = "XO", threshold = threshold, nboot = nboot, nbatch = nbatch, bootsize = bootsize, core = core, max_iter = max_iter, max_error = max_error), + model_OO = poiss_boostrap_EM(x, sex = "OO", threshold = threshold, nboot = nboot, nbatch = nbatch, bootsize = bootsize, core = core, max_iter = max_iter, max_error = max_error) + ) %>% + pivot_longer(cols = c(model_XY, model_XO, model_OO)) %>% + unnest(c(value)) +} diff --git a/dev/config_fusen.yaml b/dev/config_fusen.yaml index f7a28e87a26900ce9de95f26f57ac10c3997d0b8..d84d1641adba95d2214e4302df0cff8806bd51b1 100644 --- a/dev/config_fusen.yaml +++ b/dev/config_fusen.yaml @@ -60,8 +60,12 @@ flat_full_poisson.Rmd: - R/loglik_bipoiss_clust.R - R/bic_bipoiss_clust.R - R/param_diff_poiss.R + - R/get_cluster_poiss.R + - R/e_bipoiss_clust_batch.R - R/em_bipoiss_clust.R + - R/poiss_boostrap_em_sub.R - R/poiss_boostrap_em.R + - R/poiss_compare_models.R tests: [] vignettes: vignettes/getting-started-poisson-version.Rmd inflate: diff --git a/dev/flat_full_poisson.Rmd b/dev/flat_full_poisson.Rmd index fdfc0ba69e58f9ac5047c2fd8c597227876b2dac..858565cdf595252a01ffe736320384a762479659 100644 --- a/dev/flat_full_poisson.Rmd +++ b/dev/flat_full_poisson.Rmd @@ -679,6 +679,7 @@ extraDistr::rbvpois(1000*res[[1]]$kappa, res[[1]]$l1, res[[1]]$l2, res[[1]]$l3) # Model comparaison +## boostrap EM sub ```{r fun-poiss_boostrap_EM_sub} #' Function to compile statistics bootstrap samples of the data #' @@ -687,6 +688,7 @@ extraDistr::rbvpois(1000*res[[1]]$kappa, res[[1]]$l1, res[[1]]$l2, res[[1]]$l3) #' @param gamma a vector of kappa prior #' @param threshold theshold to stop the EM algorithm #' @param nboot number of boostrap sample +#' @param nbatch (default: 10) the number of batch #' @param bootsize size of the boostrap sample (if < 0 we take a percentage of x) #' @param core number of cpus to use for the computation #' @param max_iter (default: 100) maximum number of iteration @@ -700,7 +702,7 @@ extraDistr::rbvpois(1000*res[[1]]$kappa, res[[1]]$l1, res[[1]]$l2, res[[1]]$l3) #' extraDistr::rbvpois(500, 0, 20, 20), # X #' extraDistr::rbvpois(100, 20, 0, 5) # Y #' ) %>% pois_boostrap_EM(nboot = 10) -poiss_boostrap_EM_sub <- function(iter, x, bootsize, params, gamma, max_iter, max_error) { +poiss_boostrap_EM_sub <- function(iter, x, bootsize, nbatch = nbatch, params, gamma, max_iter, max_error) { res <- list() res$loglik <- c(NA) iter <- 0 @@ -709,13 +711,14 @@ poiss_boostrap_EM_sub <- function(iter, x, bootsize, params, gamma, max_iter, ma as_tibble() %>% sample_frac(bootsize, replace = T) %>% as.matrix() %>% - em_bipoiss_clust(params = params, gamma = gamma, max_iter = max_iter) + em_bipoiss_clust(params = params, gamma = gamma, max_iter = max_iter, nbatch = nbatch) iter <- iter + 1 } return(tibble(loglik = res$loglik, BIC = res$BIC)) } ``` +## Bootstrap EM ```{r fun-poiss_boostrap_EM} #' Function to compile statistics bootstrap samples of the data #' @@ -723,6 +726,7 @@ poiss_boostrap_EM_sub <- function(iter, x, bootsize, params, gamma, max_iter, ma #' @param params a list of init parameters #' @param gamma a vector of kappa prior #' @param threshold theshold to stop the EM algorithm +#' @param nbatch (default: 10) the number of batch #' @param nboot number of boostrap sample #' @param bootsize size of the boostrap sample (if < 0 we take a percentage of x) #' @param core number of cpus to use for the computation @@ -737,7 +741,7 @@ poiss_boostrap_EM_sub <- function(iter, x, bootsize, params, gamma, max_iter, ma #' extraDistr::rbvpois(500, 0, 20, 20), # X #' extraDistr::rbvpois(100, 20, 0, 5) # Y #' ) %>% pois_boostrap_EM(nboot = 10) -poiss_boostrap_EM <- function(x, sex = "XY", threshold = 1, nboot = 100, bootsize = 1, core = 1, max_iter = 100, max_error = 5) { +poiss_boostrap_EM <- function(x, sex = "XY", threshold = 1, nboot = 100, nbatch = nbatch, bootsize = 1, core = 1, max_iter = 100, max_error = 5) { params = list( A = list(kappa = 0.4, l1 = mean(x), l2 = mean(x), l3 = mean(x)) ) @@ -751,14 +755,15 @@ poiss_boostrap_EM <- function(x, sex = "XY", threshold = 1, nboot = 100, bootsiz gamma <- c(round(nrow(x) * bootsize) * .8, round(nrow(x) * bootsize) * .15, round(nrow(x) * bootsize) * .05) } if (core == 1) { - res <- lapply(as.list(1:nboot), FUN = poiss_boostrap_EM_sub, x = x, bootsize = bootsize, params = params, gamma = gamma, max_iter = max_iter, max_error = max_error) + res <- lapply(as.list(1:nboot), FUN = poiss_boostrap_EM_sub, x = x, bootsize = bootsize, nbatch = nbatch, params = params, gamma = gamma, max_iter = max_iter, max_error = max_error) } else { - res <- parallel::mclapply(as.list(1:nboot), FUN = poiss_boostrap_EM_sub, x = x, bootsize = bootsize, params = params, gamma = gamma, max_iter = max_iter, max_error = max_error, mc.cores = core) + res <- parallel::mclapply(as.list(1:nboot), FUN = poiss_boostrap_EM_sub, x = x, bootsize = bootsize, nbatch = nbatch, params = params, gamma = gamma, max_iter = max_iter, max_error = max_error, mc.cores = core) } return(res) } ``` +# Model compare ```{r fun-poiss_compare_models} #' Function to compile statistics differences between model XY and XO on boostrap #' samples of the data @@ -766,6 +771,7 @@ poiss_boostrap_EM <- function(x, sex = "XY", threshold = 1, nboot = 100, bootsiz #' @param x a matrix of male female kmers counts #' @param threshold theshold to stop the EM algorithm #' @param nboot number of boostrap sample +#' @param nbatch (default: 10) the number of batch #' @param bootsize size of the boostrap sample (if < 0 we take a percentage of x) #' @param core number of cpus to use for the computation #' @param max_iter (default: 100) maximum number of iteration @@ -780,11 +786,11 @@ poiss_boostrap_EM <- function(x, sex = "XY", threshold = 1, nboot = 100, bootsiz #' extraDistr::rbvpois(1000, 20, 0, 5) # Y #' ) %>% #' poiss_compare_models(nboot = 3, core = 1) -poiss_compare_models <- function(x, threshold = 1, nboot = 100, bootsize = 1, core = 1, max_iter = 100, max_error = 5) { +poiss_compare_models <- function(x, threshold = 1, nboot = 100, nbatch = 10, bootsize = 1, core = 1, max_iter = 100, max_error = 5) { tibble( - model_XY = poiss_boostrap_EM(x, sex = "XY", threshold = threshold, nboot = nboot, bootsize = bootsize, core = core, max_iter = max_iter, max_error = max_error), - model_XO = poiss_boostrap_EM(x, sex = "XO", threshold = threshold, nboot = nboot, bootsize = bootsize, core = core, max_iter = max_iter, max_error = max_error), - model_OO = poiss_boostrap_EM(x, sex = "OO", threshold = threshold, nboot = nboot, bootsize = bootsize, core = core, max_iter = max_iter, max_error = max_error) + model_XY = poiss_boostrap_EM(x, sex = "XY", threshold = threshold, nboot = nboot, nbatch = nbatch, bootsize = bootsize, core = core, max_iter = max_iter, max_error = max_error), + model_XO = poiss_boostrap_EM(x, sex = "XO", threshold = threshold, nboot = nboot, nbatch = nbatch, bootsize = bootsize, core = core, max_iter = max_iter, max_error = max_error), + model_OO = poiss_boostrap_EM(x, sex = "OO", threshold = threshold, nboot = nboot, nbatch = nbatch, bootsize = bootsize, core = core, max_iter = max_iter, max_error = max_error) ) %>% pivot_longer(cols = c(model_XY, model_XO, model_OO)) %>% unnest(c(value)) @@ -801,7 +807,7 @@ data <- rbind( extraDistr::rbvpois(n, 0, 200, 200), # X extraDistr::rbvpois(n, 200, 0, 5) # Y ) -res <- data %>% poiss_compare_models(nboot = 5, core = 1, max_iter = 30) +res <- data %>% poiss_compare_models(nboot = 5, core = 1, max_iter = 30, nbatch = 20) res %>% pivot_longer(cols = -c("name"), names_to = "metric") %>% ggplot(aes(x = name, y = value)) + @@ -819,7 +825,7 @@ data <- rbind( extraDistr::rbvpois(n, 100, 100, 200), # A extraDistr::rbvpois(n, 0, 200, 200) # X ) -res <- data %>% poiss_compare_models(nboot = 5, core = 1, max_iter = 30) +res <- data %>% poiss_compare_models(nboot = 5, core = 1, max_iter = 30, nbatch = 20) res %>% pivot_longer(cols = -c("name"), names_to = "metric") %>% ggplot(aes(x = name, y = value)) + @@ -836,7 +842,7 @@ We simulate 1 clusters from bi-Poisson distribution data <- rbind( extraDistr::rbvpois(10000, 100, 100, 200) # A ) -res <- data %>% poiss_compare_models(nboot = 10, core = 1, max_iter = 30) +res <- data %>% poiss_compare_models(nboot = 5, core = 1, max_iter = 30, nbatch = 20) res %>% pivot_longer(cols = -c("name"), names_to = "metric") %>% ggplot(aes(x = name, y = value)) + diff --git a/man/poiss_compare_models.Rd b/man/poiss_compare_models.Rd index 852b3fd9242c6ae00b6af80543f3105e448706c8..9bd09992b06e4f0fc3daefbf96fd3aa7024e6b59 100644 --- a/man/poiss_compare_models.Rd +++ b/man/poiss_compare_models.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/poiss_boostrap_em.R, R/poiss_boostrap_em_sub.R +% Please edit documentation in R/poiss_compare_models.R \name{poiss_compare_models} \alias{poiss_compare_models} \title{Function to compile statistics differences between model XY and XO on boostrap @@ -9,16 +9,7 @@ poiss_compare_models( x, threshold = 1, nboot = 100, - bootsize = 1, - core = 1, - max_iter = 100, - max_error = 5 -) - -poiss_compare_models( - x, - threshold = 1, - nboot = 100, + nbatch = 10, bootsize = 1, core = 1, max_iter = 100, @@ -32,6 +23,8 @@ poiss_compare_models( \item{nboot}{number of boostrap sample} +\item{nbatch}{(default: 10) the number of batch} + \item{bootsize}{size of the boostrap sample (if < 0 we take a percentage of x)} \item{core}{number of cpus to use for the computation} @@ -39,28 +32,15 @@ poiss_compare_models( \item{max_iter}{(default: 100) maximum number of iteration} \item{max_error}{(default: 5) maximum number of try} - -\item{frac}{(default: 1.) fraction of the data to use at each step} } \value{ -tibble with the statistics - tibble with the statistics } \description{ -Function to compile statistics differences between model XY and XO on boostrap -samples of the data - Function to compile statistics differences between model XY and XO on boostrap samples of the data } \examples{ -res <- rbind( - extraDistr::rbvpois(1000, 10, 10, 20), # A - extraDistr::rbvpois(1000, 0, 20, 20), # X - extraDistr::rbvpois(1000, 20, 0, 5) # Y - ) \%>\% - poiss_compare_models(nboot = 3, core = 1) res <- rbind( extraDistr::rbvpois(1000, 10, 10, 20), # A extraDistr::rbvpois(1000, 0, 20, 20), # X diff --git a/vignettes/getting-started-poisson-version.Rmd b/vignettes/getting-started-poisson-version.Rmd index bc6461f46bf0edbd6855dcd2d0a77e434fa84125..7dc86b2419286b2db2c2e616500cb438fc980853 100644 --- a/vignettes/getting-started-poisson-version.Rmd +++ b/vignettes/getting-started-poisson-version.Rmd @@ -190,6 +190,12 @@ extraDistr::rbvpois(1000*res[[1]]$kappa, res[[1]]$l1, res[[1]]$l2, res[[1]]$l3) # Model comparaison +## boostrap EM sub + +## Bootstrap EM + +# Model compare + ## XY We simulate 3 clusters from bi-Poisson distribution @@ -201,7 +207,7 @@ data <- rbind( extraDistr::rbvpois(n, 0, 200, 200), # X extraDistr::rbvpois(n, 200, 0, 5) # Y ) -res <- data %>% poiss_compare_models(nboot = 5, core = 1, max_iter = 30) +res <- data %>% poiss_compare_models(nboot = 5, core = 1, max_iter = 30, nbatch = 20) res %>% pivot_longer(cols = -c("name"), names_to = "metric") %>% ggplot(aes(x = name, y = value)) + @@ -220,7 +226,7 @@ data <- rbind( extraDistr::rbvpois(n, 100, 100, 200), # A extraDistr::rbvpois(n, 0, 200, 200) # X ) -res <- data %>% poiss_compare_models(nboot = 5, core = 1, max_iter = 30) +res <- data %>% poiss_compare_models(nboot = 5, core = 1, max_iter = 30, nbatch = 20) res %>% pivot_longer(cols = -c("name"), names_to = "metric") %>% ggplot(aes(x = name, y = value)) + @@ -238,7 +244,7 @@ We simulate 1 clusters from bi-Poisson distribution data <- rbind( extraDistr::rbvpois(10000, 100, 100, 200) # A ) -res <- data %>% poiss_compare_models(nboot = 10, core = 1, max_iter = 30) +res <- data %>% poiss_compare_models(nboot = 5, core = 1, max_iter = 30, nbatch = 20) res %>% pivot_longer(cols = -c("name"), names_to = "metric") %>% ggplot(aes(x = name, y = value)) +