-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
everything is new!
- Loading branch information
0 parents
commit 3ce28ac
Showing
54 changed files
with
5,456 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
^.*\.Rproj$ | ||
^\.Rproj\.user$ | ||
^LICENSE\.md$ | ||
^README\.Rmd$ | ||
^\.github$ | ||
^cran-comments\.md$ | ||
^\.travis\.yml$ | ||
^CRAN-SUBMISSION$ | ||
^codecov\.yml$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples | ||
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help | ||
on: | ||
push: | ||
branches: [main, master] | ||
pull_request: | ||
branches: [main, master] | ||
|
||
name: R-CMD-check | ||
|
||
jobs: | ||
R-CMD-check: | ||
runs-on: ${{ matrix.config.os }} | ||
|
||
name: ${{ matrix.config.os }} (${{ matrix.config.r }}) | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
config: | ||
- {os: macos-latest, r: 'release'} | ||
- {os: windows-latest, r: 'release'} | ||
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} | ||
- {os: ubuntu-latest, r: 'release'} | ||
- {os: ubuntu-latest, r: 'oldrel-1'} | ||
|
||
env: | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
R_KEEP_PKG_SOURCE: yes | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: r-lib/actions/setup-pandoc@v2 | ||
|
||
- uses: r-lib/actions/setup-r@v2 | ||
with: | ||
r-version: ${{ matrix.config.r }} | ||
http-user-agent: ${{ matrix.config.http-user-agent }} | ||
use-public-rspm: true | ||
|
||
- uses: r-lib/actions/setup-r-dependencies@v2 | ||
with: | ||
extra-packages: any::rcmdcheck | ||
needs: check | ||
|
||
- uses: r-lib/actions/check-r-package@v2 | ||
with: | ||
upload-snapshots: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData | ||
.Ruserdata | ||
src/*.o | ||
src/*.so | ||
src/*.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Package: SANple | ||
Type: Package | ||
Title: Fitting Common and Shared Atoms Nested Models via MCMC | ||
Version: 0.0.1 | ||
Date: 2023-09-09 | ||
Author: Laura D'Angelo and Francesco Denti | ||
Maintainer: Laura D'Angelo <laura.dangelo@live.com> | ||
Description: An R package for estimating Bayesian nested mixture models via MCMC methods. Specifically, the package implements the common atoms model (Denti et al., 2023), its finite version (D'Angelo et al., 2023), and a hybrid finite-infinite model. All models use Gaussian mixtures with a normal-inverse-gamma prior distribution on the parameters. Additional functions are provided to help analyzing the results of the fitting procedure. | ||
License: MIT + file LICENSE | ||
Imports: | ||
Rcpp, RcppArmadillo, salso | ||
Depends: | ||
scales, RColorBrewer | ||
LinkingTo: | ||
Rcpp, RcppArmadillo, RcppProgress | ||
RoxygenNote: 7.2.3 | ||
Encoding: UTF-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
YEAR: 2023 | ||
COPYRIGHT HOLDER: SANple authors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# MIT License | ||
|
||
Copyright (c) 2023 SANple authors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
S3method(plot,SANmcmc) | ||
S3method(print,SANclusters) | ||
S3method(print,SANmcmc) | ||
export(estimate_clusters) | ||
export(sample_CAM) | ||
export(sample_fSAN) | ||
export(sample_fSAN_sparsemix) | ||
export(sample_fiSAN) | ||
export(sample_fiSAN_sparsemix) | ||
export(traceplot) | ||
import(Rcpp) | ||
import(RcppArmadillo) | ||
importFrom(RColorBrewer,brewer.pal) | ||
importFrom(grDevices,colorRampPalette) | ||
importFrom(grDevices,devAskNewPage) | ||
importFrom(graphics,abline) | ||
importFrom(graphics,boxplot) | ||
importFrom(graphics,lines) | ||
importFrom(graphics,par) | ||
importFrom(graphics,points) | ||
importFrom(salso,salso) | ||
importFrom(scales,alpha) | ||
importFrom(stats,cor) | ||
importFrom(stats,cutree) | ||
importFrom(stats,density) | ||
importFrom(stats,dist) | ||
importFrom(stats,ecdf) | ||
importFrom(stats,hclust) | ||
importFrom(stats,rgamma) | ||
importFrom(stats,var) | ||
useDynLib(SANple) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by using Rcpp::compileAttributes() -> do not edit by hand | ||
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 | ||
|
||
sample_cam_arma <- function(nrep, y, group, maxK, maxL, m0, tau0, lambda0, gamma0, fixed_alpha, fixed_beta, alpha, beta, hyp_alpha1, hyp_alpha2, hyp_beta1, hyp_beta2, mu_start, sigma2_start, M_start, S_start, alpha_start, beta_start, progressbar) { | ||
.Call('_SANple_sample_cam_arma', PACKAGE = 'SANple', nrep, y, group, maxK, maxL, m0, tau0, lambda0, gamma0, fixed_alpha, fixed_beta, alpha, beta, hyp_alpha1, hyp_alpha2, hyp_beta1, hyp_beta2, mu_start, sigma2_start, M_start, S_start, alpha_start, beta_start, progressbar) | ||
} | ||
|
||
sample_fcam_arma <- function(nrep, y, group, maxK, maxL, m0, tau0, lambda0, gamma0, fixed_alpha, fixed_beta, alpha, beta, hyp_alpha1, hyp_alpha2, hyp_beta1, hyp_beta2, mu_start, sigma2_start, M_start, S_start, alpha_start, beta_start, eps_alpha, eps_beta, progressbar) { | ||
.Call('_SANple_sample_fcam_arma', PACKAGE = 'SANple', nrep, y, group, maxK, maxL, m0, tau0, lambda0, gamma0, fixed_alpha, fixed_beta, alpha, beta, hyp_alpha1, hyp_alpha2, hyp_beta1, hyp_beta2, mu_start, sigma2_start, M_start, S_start, alpha_start, beta_start, eps_alpha, eps_beta, progressbar) | ||
} | ||
|
||
sample_ficam_arma <- function(nrep, y, group, maxK, maxL, m0, tau0, lambda0, gamma0, fixed_alpha, fixed_beta, alpha, beta, hyp_alpha1, hyp_alpha2, hyp_beta1, hyp_beta2, mu_start, sigma2_start, M_start, S_start, alpha_start, beta_start, eps_beta, progressbar) { | ||
.Call('_SANple_sample_ficam_arma', PACKAGE = 'SANple', nrep, y, group, maxK, maxL, m0, tau0, lambda0, gamma0, fixed_alpha, fixed_beta, alpha, beta, hyp_alpha1, hyp_alpha2, hyp_beta1, hyp_beta2, mu_start, sigma2_start, M_start, S_start, alpha_start, beta_start, eps_beta, progressbar) | ||
} | ||
|
||
sample_overcam_arma <- function(nrep, y, group, maxK, maxL, m0, tau0, lambda0, gamma0, fixed_alpha, fixed_beta, alpha, beta, hyp_alpha, hyp_beta, mu_start, sigma2_start, M_start, S_start, alpha_start, beta_start, eps_alpha, eps_beta, progressbar) { | ||
.Call('_SANple_sample_overcam_arma', PACKAGE = 'SANple', nrep, y, group, maxK, maxL, m0, tau0, lambda0, gamma0, fixed_alpha, fixed_beta, alpha, beta, hyp_alpha, hyp_beta, mu_start, sigma2_start, M_start, S_start, alpha_start, beta_start, eps_alpha, eps_beta, progressbar) | ||
} | ||
|
||
sample_overficam_arma <- function(nrep, y, group, maxK, maxL, m0, tau0, lambda0, gamma0, fixed_alpha, fixed_beta, alpha, beta, hyp_alpha1, hyp_alpha2, hyp_beta, mu_start, sigma2_start, M_start, S_start, alpha_start, beta_start, eps_beta, progressbar) { | ||
.Call('_SANple_sample_overficam_arma', PACKAGE = 'SANple', nrep, y, group, maxK, maxL, m0, tau0, lambda0, gamma0, fixed_alpha, fixed_beta, alpha, beta, hyp_alpha1, hyp_alpha2, hyp_beta, mu_start, sigma2_start, M_start, S_start, alpha_start, beta_start, eps_beta, progressbar) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
#' Estimate observational and distributional clusters | ||
#' @description Given the MCMC output, estimate the observational and distributional partitions using \code{\link[salso:salso]{salso::salso()}}. | ||
#' | ||
#' @param object object of class \code{SANmcmc} (the result of a call to \code{\link{sample_fiSAN}}, \code{\link{sample_fiSAN_sparsemix}}, | ||
#' \code{\link{sample_fSAN}}, \code{\link{sample_fSAN_sparsemix}}, or \code{\link{sample_CAM}}). | ||
#' @param burnin the length of the burn-in to be discarded before estimating the clusters (default is 2/3 of the iterations). | ||
#' @param ncores the number of CPU cores to use, i.e., the number of simultaneous runs at any given time. A value of zero indicates to use all cores on the system. | ||
#' | ||
#' @return Object of class \code{SANclusters}. The object contains: | ||
#' @returns \code{est_oc} estimated partition at the observational level. It is an object of class \code{salso.estimate}. | ||
#' @returns \code{est_dc} estimated partition at the distributional level. It is an object of class \code{salso.estimate}. | ||
#' @returns \code{clus_means} cluster-specific sample means of the estimated partition. | ||
#' @returns \code{clus_vars} cluster-specific sample variances of the estimated partition. | ||
#' | ||
#' @seealso \code{\link[salso:salso]{salso::salso()}}, \code{\link{print.SANmcmc}}, \code{\link{plot.SANmcmc}}, \code{\link{print.SANclusters}} | ||
#' | ||
#' @examples | ||
#' set.seed(123) | ||
#' y <- c(rnorm(170),rnorm(70,5)) | ||
#' g <- c(rep(1,100), rep(2, 140)) | ||
#' out <- sample_fiSAN(nrep = 3000, y = y, group = g, beta = 1) | ||
#' estcl <- estimate_clusters(out) | ||
#' estcl | ||
#' | ||
#' | ||
#' @export | ||
#' @importFrom salso salso | ||
#' @useDynLib SANple | ||
estimate_clusters = function(object, burnin = NULL, ncores = 0) | ||
{ | ||
|
||
if(is.null(burnin)) { burnin = 1:round(object$params$nrep/3*2) } | ||
estimated_oc = suppressWarnings(salso::salso(object$sim$obs_cluster[-burnin,], nCores = ncores)) | ||
estimated_dc = suppressWarnings(salso::salso(object$sim$distr_cluster[-burnin,], nCores = ncores)) | ||
|
||
n_oc = length(unique(estimated_oc)) | ||
n_dc = length(unique(estimated_dc)) | ||
|
||
means = matrix(NA, n_oc, n_dc) | ||
vars = matrix(NA, n_oc, n_dc) | ||
|
||
dc_long = estimated_dc[object$params$group] | ||
|
||
for(j in 1:n_dc) { | ||
|
||
suby = object$params$y[dc_long == j] | ||
subcl = estimated_oc[dc_long == j] | ||
|
||
for(k in unique(subcl)) { | ||
means[k,j] = mean(suby[(subcl == k)]) | ||
if(length(suby[subcl == k])>1) { | ||
vars[k,j] = var(suby[subcl == k]) } | ||
} | ||
} | ||
|
||
|
||
|
||
out = (list("est_oc" = estimated_oc, | ||
"est_dc" = estimated_dc, | ||
"clus_means" = means, | ||
"clus_vars" = vars)) | ||
|
||
structure(out, class = c("SANclusters", class(out))) | ||
} |
Oops, something went wrong.