library(tibble)
library(dplyr)
library(testthat)
library(gt)
devtools::load_all()

Tests of gridpts

default (N(0,1))

approximate variance of standard normal (i.e., 1)

x1 <- gridpts_(mu = 0, a = -20, b = 20, r = 18)
x2 <- gridpts(mu = 0, a = -20, b = 20, r = 18)
x3a <- gsDesign::normalGrid(bounds = c(-10, 10), mu = 0, sigma = 1, r = 18)
x3b <- gsDesign::normalGrid(bounds = c(-20, 20), mu = 0, sigma = 1, r = 18)
x3c <- gsDesign::normalGrid(bounds = c(-80, 80), mu = 0, sigma = 1, r = 18)
tibble(Rcpp = length(x1$z), 
       R = length(x2$z),
       `C with (a, b) = (-10, 10)` = length(x3a$z),
       `C with (a, b) = (-20, 20)` = length(x3b$z),
       `C with (a, b) = (-80, 80)` = length(x3c$z)) %>% gt() %>% tab_header("Number of grid points")
tibble(diff_z = sum(abs(x1$z - x2$z)),
       diff_w = sum(abs(x1$w - x2$w))) %>% gt() %>% tab_header(title = "Difference between Rcpp and R", subtitle = "in gsdmvn")
tibble(diff_z = sum(abs(x1$z - x3a$z)),
       diff_w = sum(abs(x1$w - x3a$gridwgts))) %>% gt() %>% tab_header(title = "Difference between gsDesign (C) and gsdmvn (Rcpp)", subtitle = "under (a, b) = (-10, 10)")
tibble(diff_z = sum(abs(x1$z - x3b$z)),
       diff_w = sum(abs(x1$w - x3b$gridwgts))) %>% gt() %>% tab_header(title = "Difference between gsDesign and gsdmvn", subtitle = "under (a, b) = (-20, 20)")
tibble(diff_z = sum(abs(x1$z - x3b$z)),
       diff_w = sum(abs(x1$w - x3b$gridwgts))) %>% gt() %>% tab_header(title = "Difference between gsDesign and gsdmvn", subtitle = "under (a, b) = (-80, 80)")

approximate probability of N(0,1) above .95 quantile (i.e., .05)

x1 <- gridpts_(mu = 0, a = qnorm(0.95), b = Inf, r = 18)
x2 <- gridpts(mu = 0, a = qnorm(0.95), b = Inf, r = 18)
x3a <- gsDesign::normalGrid(bounds = c(qnorm(0.95), 10), mu = 0, sigma = 1, r = 18)
x3b <- gsDesign::normalGrid(bounds = c(qnorm(0.95), 20), mu = 0, sigma = 1, r = 18)
x3c <- gsDesign::normalGrid(bounds = c(qnorm(0.95), 80), mu = 0, sigma = 1, r = 18)
tibble(Rcpp = length(x1$z), 
       R = length(x2$z),
       `C with (a, b) = (-10, 10)` = length(x3a$z),
       `C with (a, b) = (-20, 20)` = length(x3b$z),
       `C with (a, b) = (-80, 80)` = length(x3c$z)) %>% gt() %>% tab_header("Number of grid points")
tibble(diff_z = sum(abs(x1$z - x2$z)),
       diff_w = sum(abs(x1$w - x2$w))) %>% gt() %>% tab_header(title = "Difference between Rcpp and R", subtitle = "in gsdmvn")
tibble(diff_z = sum(abs(x2$z - x3a$z)),
       diff_w = sum(abs(x2$w - x3a$gridwgts))) %>% gt() %>% tab_header(title = "Difference between gsDesign (C) and gsdmvn (Rcpp)", subtitle = "under (a, b) = (-10, 10)")
tibble(diff_z = sum(abs(x2$z - x3b$z)),
       diff_w = sum(abs(x2$w - x3b$gridwgts))) %>% gt() %>% tab_header(title = "Difference between gsDesign and gsdmvn", subtitle = "under (a, b) = (-20, 20)")
tibble(diff_z = sum(abs(x2$z - x3b$z)),
       diff_w = sum(abs(x2$w - x3b$gridwgts))) %>% gt() %>% tab_header(title = "Difference between gsDesign and gsdmvn", subtitle = "under (a, b) = (-80, 80)")

approximate probability of N(0.5, 1) above .95 quantile (i.e., .05)

x1 <- gridpts_(mu = 0.5, a = qnorm(0.95), b = Inf, r = 18)
x2 <- gridpts(mu = 0.5, a = qnorm(0.95), b = Inf, r = 18)
x3a <- gsDesign::normalGrid(bounds = c(qnorm(0.95), 10), mu = 0.5, sigma = 1, r = 18)
x3b <- gsDesign::normalGrid(bounds = c(qnorm(0.95), 20), mu = 0.5, sigma = 1, r = 18)
x3c <- gsDesign::normalGrid(bounds = c(qnorm(0.95), 80), mu = 0.5, sigma = 1, r = 18)
tibble(Rcpp = length(x1$z), 
       R = length(x2$z),
       `C with (a, b) = (-10, 10)` = length(x3a$z),
       `C with (a, b) = (-20, 20)` = length(x3b$z),
       `C with (a, b) = (-80, 80)` = length(x3c$z)) %>% gt() %>% tab_header("Number of grid points")
tibble(diff_z = sum(abs(x1$z - x2$z)),
       diff_w = sum(abs(x1$w - x2$w))) %>% gt() %>% tab_header(title = "Difference between Rcpp and R", subtitle = "in gsdmvn")
tibble(diff_z = sum(abs(x1$z - x3a$z)),
       diff_w = sum(abs(x1$w - x3a$gridwgts))) %>% gt() %>% tab_header(title = "Difference between gsDesign (C) and gsdmvn (Rcpp)", subtitle = "under (a, b) = (-10, 10)")
tibble(diff_z = sum(abs(x1$z - x3b$z)),
       diff_w = sum(abs(x1$w - x3b$gridwgts))) %>% gt() %>% tab_header(title = "Difference between gsDesign and gsdmvn", subtitle = "under (a, b) = (-20, 20)")
tibble(diff_z = sum(abs(x1$z - x3b$z)),
       diff_w = sum(abs(x1$w - x3b$gridwgts))) %>% gt() %>% tab_header(title = "Difference between gsDesign and gsdmvn", subtitle = "under (a, b) = (-80, 80)")


keaven/gsDesign2 documentation built on Oct. 13, 2022, 8:42 p.m.