library(purrr)
set.seed(2020)
means <- 1:4
bp <- bench::press(
n = c(100, 1000, 10000, 100000),
{
bench::mark(
map = {set.seed(2020); map(means, rnorm, n = n, sd = 1)},
lapply = {set.seed(2020); lapply(means, rnorm, n = n, sd = 1)}
👷♂️
pi_mat <- matrix(c(0.5, 0.5))
z_mat <- matrix(c(32, 1))
bm <- bench::mark(
t = t(pi_mat) %*% z_mat,
crossprod = crossprod(pi_mat, z_mat)
)
bm
choice_set_hours <- function(hour_increments, n_hour_options) {
choice_set <- seq(
from = 0,
to = (n_hour_options - 1) * hour_increments,
by = hour_increments
)
choice_set
}
## requires pass by position?
fr_pos <- function(x) { ## Rosenbrock Banana function
x1 <- x[1]
x2 <- x[2]
100 * (x2 - x1 * x1)^2 + (1 - x1)^2
}
pars <- list(a = -1.2, b = 1)
This file contains hidden or 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
# example code from test_posteriors_geweke | |
devtools::load_all(".") | |
n <- 10 | |
# mu1 <- rnorm(1, 0, 3) | |
# sd1 <- rlnorm(1) | |
# sd2 <- rlnorm(1) | |
mu1 <- 0 | |
sd1 <- 2 | |
sd2 <- 1 |
e <- new.env()
e$x <- 10
e$y <- 20
eval(quote(x + y), envir = e)
#> [1] 30
e2 <- new.env()
# Warming up the sampler and running extra samples on the model with the initial dataset (ie. not changing it each iteration) should tell us whether the sampler is correctly adapted.
library(greta)
#>
#> Attaching package: 'greta'
#> The following objects are masked from 'package:stats':
#>
#> binomial, cov2cor, poisson
#> The following objects are masked from 'package:base':
#>
library(rlang)
preserved_goods_none <- function(goods = c("cucumber", "lemon", "pear")) {
goods
}
preserved_goods_rlang <- function(goods = c("cucumber", "lemon", "pear")) {
goods <- rlang::arg_match(
arg = goods
mat1 <- matrix(1:10, ncol = 2)
mat2 <- matrix(2:11, ncol = 2)
list_matrices <- list(mat1, mat2)
list_matrices
#> [[1]]
#> [,1] [,2]
#> [1,] 1 6
#> [2,] 2 7
mat <- matrix(
sample(x = c(1, 0), size = 9, replace = TRUE),
nrow = 3,
ncol = 3
)
mat
#> [,1] [,2] [,3]
#> [1,] 1 1 0
NewerOlder