Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

216 nonrandom distribution returns a single value when repeated values are expected #225

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixing environment in .gencustom
  • Loading branch information
Keith Goldfeld committed May 11, 2024
commit 197c9611ff87601ecdb74b707d2da3374e2d7470
2 changes: 1 addition & 1 deletion R/generate_dist.R
Original file line number Diff line number Diff line change
@@ -368,7 +368,7 @@
names(arg_list) <- var_vec
assertNotInVector("n", names(arg_list))
arg_list <- c(n = n, arg_list)
new <- do.call(fn, arg_list)
new <- do.call(fn, arg_list, envir = envir)

new
}
53 changes: 27 additions & 26 deletions tests/testthat/test-generate_dist.R
Original file line number Diff line number Diff line change
@@ -171,30 +171,31 @@ test_that("clusterSize data is generated as expected.", {

})


# .gencustom ----
# test_that("custom data is generated as expected.", {
# skip_on_cran()
#
# .trunc_norm <- function(n, lower, upper, mu = 0, s = 1.5) {
#
# F.a <- pnorm(lower, mean = mu, sd = s)
# F.b <- pnorm(upper, mean = mu, sd = s)
#
# u <- runif(n, min = F.a, max = F.b)
# qnorm(u, mean = mu, sd = s)
#
# }
#
# def <-
# defData(varname = "x", formula = 5, dist = "poisson") |>
# defData(varname = "y", formula = ".trunc_norm",
# variance = "s = 100, lower = x - 1, upper = x + 1",
# dist = "custom"
# )
#
# dd <- genData(10000, def)
#
# expect_true( dd[, min(y)] > dd[, min(x-1)])
# expect_true( dd[, max(y)] < dd[, max(x+1)])
#
# })
test_that("custom data is generated as expected.", {
skip_on_cran()

trunc_norm <- function(n, lower, upper, mu = 0, s = 1.5) {

F.a <- pnorm(lower, mean = mu, sd = s)
F.b <- pnorm(upper, mean = mu, sd = s)

u <- runif(n, min = F.a, max = F.b)
qnorm(u, mean = mu, sd = s)

}

def <-
defData(varname = "x", formula = 5, dist = "poisson") |>
defData(varname = "y", formula = "trunc_norm",
variance = "s = 100, lower = x - 1, upper = x + 1",
dist = "custom"
)

dd <- genData(10000, def)

expect_true( dd[, min(y)] > dd[, min(x-1)])
expect_true( dd[, max(y)] < dd[, max(x+1)])

})
Loading