# NOT RUN {
data(danes)
db <- as.matrix(danes[rep(1L:nrow(danes), danes$n), 1L:(ncol(danes) - 1L)])
set.seed(1)
true_contribs <- sample(1L:nrow(db), 2L)
h1 <- db[true_contribs[1L], ]
h2 <- db[true_contribs[2L], ]
db_ref <- db[-true_contribs, ]
h1h2 <- c(paste(h1, collapse = ";"), paste(h2, collapse = ";"))
tab_db <- table(apply(db, 1, paste, collapse = ";"))
tab_db_ref <- table(apply(db_ref, 1, paste, collapse = ";"))
tab_db[h1h2]
tab_db_ref[h1h2]
rm(db) # To avoid use by accident
mixture <- generate_mixture(list(h1, h2))
possible_contributors <- contributor_pairs(mixture)
possible_contributors
fits <- lapply(1L:5L, function(clus) disclapmix(db_ref, clusters = clus))
best_fit_BIC <- fits[[which.min(sapply(fits, function(fit) fit$BIC_marginal))]]
best_fit_BIC
ranked_contributors_BIC <- rank_contributor_pairs(possible_contributors, best_fit_BIC)
ranked_contributors_BIC
plot(ranked_contributors_BIC, top = 10L, type = "b")
get_rank(ranked_contributors_BIC, h1)
# }
Run the code above in your browser using DataLab