Skip to content

Commit

Permalink
pass CRAN submission
Browse files Browse the repository at this point in the history
  • Loading branch information
Duc Tran committed Jun 24, 2021
1 parent 721c3e0 commit 49e4b6b
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 7 deletions.
11 changes: 6 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ Version: 0.11.1
Authors@R:
c(person(given = "Alex",
family = "Knudson",
role = c("aut", "cre"),
role = "aut",
email = "[email protected]"),
person(given = "Grant",
family = "Schissler",
role = "aut"))
Maintainer: Alex Knudson <aknudson@nevada.unr.edu>
role = c("aut", "cre"),
email = "aschissler@unr.edu"))
Description: Simulate multivariate data with arbitrary marginal distributions.
'bigsimr' is an package for simulating high-dimensional multivariate data with a target correlation and arbitrary marginal distributions via Gaussian copula.
It utilizes a Julia package named 'Bigsimr.jl' for its core routines.
URL: https://github.com/SchisslerGroup/r-bigsimr
BugReports: https://github.com/SchisslerGroup/Bigsimr.jl/issues
Depends:
R (>= 3.6.0)
License: MIT + file LICENSE
License: GPL-3
Encoding: UTF-8
LazyData: true
SystemRequirements: Julia (>= 1.5), Bigsimr.jl, Distributions.jl
RoxygenNote: 7.1.1
Imports:
Expand Down
2 changes: 0 additions & 2 deletions LICENSE

This file was deleted.

17 changes: 17 additions & 0 deletions R/bigsimr.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@
#' @param pkg_check logical, check for Bigsimr.jl package and install if necessary
#' @param ... Parameters are passed down to JuliaCall::julia_setup
#'
#' @return Return the imported wrapper of Bigsimr.jl Julia package
#' @examples
#' \donttest{
#' library(bigsimr)
#' bs <- bigsimr::bigsimr_setup()
#' dist <- bigsimr::distributions_setup()
#'
#' JuliaCall::julia_eval('using Random; Random.seed!(1);')
#' # Generate random target correlation matrix
#' target_corr <- bs$cor_randPD(3)
#' # Set the margins of variables
#' margins <- c(dist$Binomial(20, 0.2), dist$Beta(2, 3), dist$LogNormal(3, 1))
#' # Adjust target correlation matrix using Pearson matching
#' adjusted_corr <- bs$pearson_match(target_corr, margins)
#' # Generate random vectors
#' x <- bs$rvec(10000, adjusted_corr, margins)
#' }
#' @export
bigsimr_setup <- function (pkg_check = TRUE, ...){
julia <- JuliaCall::julia_setup(installJulia = TRUE, ...)
Expand Down
17 changes: 17 additions & 0 deletions R/distributions.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
#' This function initializes the Distributions package that many of the bigsimr
#' functions work with.
#'
#' @return Return the imported wrapper of Distributions.jl Julia package
#' @examples
#' \donttest{
#' library(bigsimr)
#' bs <- bigsimr::bigsimr_setup()
#' dist <- bigsimr::distributions_setup()
#'
#' JuliaCall::julia_eval('using Random; Random.seed!(1);')
#' # Generate random target correlation matrix
#' target_corr <- bs$cor_randPD(3)
#' # Set the margins of variables
#' margins <- c(dist$Binomial(20, 0.2), dist$Beta(2, 3), dist$LogNormal(3, 1))
#' # Adjust target correlation matrix using Pearson matching
#' adjusted_corr <- bs$pearson_match(target_corr, margins)
#' # Generate random vectors
#' x <- bs$rvec(10000, adjusted_corr, margins)
#' }
#' @export
distributions_setup <- function() {
JuliaCall::julia_install_package_if_needed("Distributions")
Expand Down
21 changes: 21 additions & 0 deletions inst/COPYRIGHTS
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Overall license
===============

bigsimr: Fast Generation of High-Dimensional Random Vectors
Copyright (C) 2021-2021 Grant Schissler

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

The years in the copyright notice above are to be understood as a
range, including the years on both ends.
20 changes: 20 additions & 0 deletions man/bigsimr_setup.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions man/distributions_setup.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions tests/testthat/test-bigsimr.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,35 @@ test_that("Bigsimr.jl loads", {
bs <- bigsimr::bigsimr_setup()
dist <- bigsimr::distributions_setup()
})



test_that("Pearson matching is working", {
skip_on_cran()

bs <- bigsimr::bigsimr_setup()
dist <- bigsimr::distributions_setup()

JuliaCall::julia_eval('using Random; Random.seed!(1);')
target_corr <- bs$cor_randPD(3)
margins <- c(dist$Binomial(20, 0.2), dist$Beta(2, 3), dist$LogNormal(3, 1))
adjusted_corr <- bs$pearson_match(target_corr, margins)
x <- bs$rvec(100000, adjusted_corr, margins)

expect_equal(mean(bs$cor(x, bs$Pearson)), mean(target_corr), tolerance = 0.05)
})

test_that("Spearman matching is working", {
skip_on_cran()

bs <- bigsimr::bigsimr_setup()
dist <- bigsimr::distributions_setup()

JuliaCall::julia_eval('using Random; Random.seed!(1);')
spearman_corr <- bs$cor_randPD(3)
margins <- c(dist$Binomial(20, 0.2), dist$Beta(2, 3), dist$LogNormal(3, 1))
adjusted_corr <- bs$cor_convert(spearman_corr, bs$Spearman, bs$Pearson)
x <- bs$rvec(100000, adjusted_corr, margins)

expect_equal(mean(bs$cor(x, bs$Spearman)), mean(spearman_corr), tolerance = 0.05)
})

0 comments on commit 49e4b6b

Please sign in to comment.