diff --git a/.Rhistory b/.Rhistory index c2643fe..243847d 100644 --- a/.Rhistory +++ b/.Rhistory @@ -1,512 +1,512 @@ -rpois(n, lambda) + rbinom(n, size = 1, prob = phi) +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 } -n <- 1000 -phi <- 0.2 -lambda <- 0.5 -yvec <- rberpo(n, phi, lambda) -Xmat <- matrix(1L, n, 1) -hist(yvec) -fit <- anova_bnp_berpoi(yvec, Xmat, iter = 20000L, warmup = 10000L) -fit$f_post |> -dplyr::rename(fh = f) |> -dplyr::mutate(f0 = dberpo(y, phi, lambda)) |> -tidyr::pivot_longer(cols = fh:f0) |> -ggplot2::ggplot( -ggplot2::aes(x = y, color = name, y = value) -) + -ggplot2::geom_line() -devtools::load_all(".") -library(ANOVABNPTestR) -library(dplyr) -library(ggplot2) -library(tidyr) -ANOVABNPTestR::setup() -options(download.file.method = "wininet") -ANOVABNPTestR::setup() -1+1 -library(ANOVABNPTestR) -library(dplyr) -library(ggplot2) -library(tidyr) -options(download.file.method = "wininet") -ANOVABNPTestR::setup() +# Fit our ANOVA BNP model +fit <- anova_bnp_normal(yvec, Xmat) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like a tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like a tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like a tan(). +setup() +# Simulate a sample +{ +N <- 1000 +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) +Xmat <- matrix(x, nrow = N, ncol = 2) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +} +# Fit our ANOVA BNP model +fit <- anova_bnp_normal(yvec, Xmat) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like a tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like a tan(). +# Simulate a sample +{ +N <- 1000 +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) +Xmat <- matrix(x, nrow = N, ncol = 2) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +} +setup() +# Simulate a sample +{ +N <- 1000 +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) +Xmat <- matrix(x, nrow = N, ncol = 2) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +} +# Fit our ANOVA BNP model +fit <- anova_bnp_normal(yvec, Xmat) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like a tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like a tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like a tan(). +shift_plot(fit, group = 3) # this should be a straight line. devtools::load_all(".") -library(ANOVABNPTestR) -library(dplyr) -library(ggplot2) -library(tidyr) -options(download.file.method = "wininet") -ANOVABNPTestR::setup() +# Simulate a sample +{ +N <- 1000 +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) +Xmat <- matrix(x, nrow = N, ncol = 2) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +} +# Fit our ANOVA BNP model +fit <- anova_bnp_normal(yvec, Xmat) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like a tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like a tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like a tan(). devtools::load_all(".") -library(ANOVABNPTestR) -library(dplyr) -library(ggplot2) -library(tidyr) -ANOVABNPTestR::setup() -library(ANOVABNPTestR) -library(dplyr) -library(ggplot2) -library(tidyr) +# Simulate a sample +{ +N <- 1000 +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) +Xmat <- matrix(x, nrow = N, ncol = 2) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +} +# Fit our ANOVA BNP model +fit <- anova_bnp_normal(yvec, Xmat) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like a tan(). +shift_plot(fit, group = 3) # this should be a straight line. devtools::load_all(".") -# Probability mass function Bernoulli Poisson distribution -dberpo <- function(x, phi, lambda) { -phi * dpois(x - 1, lambda) + (1 - phi) * dpois(x, lambda) +# Simulate a sample +{ +N <- 1000 +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) +Xmat <- matrix(x, nrow = N, ncol = 2) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +} +# Fit our ANOVA BNP model +fit <- anova_bnp_normal(yvec, Xmat) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like a tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Simulate a sample +{ +N <- 1000 +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) +Xmat <- matrix(x, nrow = N, ncol = 2) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +# yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +yvec <- rnorm(N) / 2 } -# Generates random draws from a Bernoulli Poisson distribution -rberpo <- function(n, phi, lambda) { -rpois(n, lambda) + rbinom(n, size = 1, prob = phi) +# Fit our ANOVA BNP model +fit <- anova_bnp_normal(yvec, Xmat) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should be a straight line. +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should be a straight line. +# Simulate a sample +{ +N <- 1000 +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) +Xmat <- matrix(x, nrow = N, ncol = 2) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +# yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +yvec <- rnorm(N) / 2 } -n <- 1000 -phi <- 0.2 -lambda <- 0.5 -yvec <- rberpo(n, phi, lambda) -Xmat <- matrix(1L, n, 1) -hist(yvec) -fit <- anova_bnp_berpoi(yvec, Xmat, iter = 20000L, warmup = 10000L) -fit$f_post |> -dplyr::rename(fh = f) |> -dplyr::mutate(f0 = dberpo(y, phi, lambda)) |> -tidyr::pivot_longer(cols = fh:f0) |> -ggplot2::ggplot( -ggplot2::aes(x = y, color = name, y = value) -) + -ggplot2::geom_line() -n <- 1000 -phi <- 0.8 -lambda <- 0.5 -yvec <- rberpo(n, phi, lambda) -Xmat <- matrix(1L, n, 1) -hist(yvec) -fit <- anova_bnp_berpoi(yvec, Xmat, iter = 20000L, warmup = 10000L) -fit$f_post |> -dplyr::rename(fh = f) |> -dplyr::mutate(f0 = dberpo(y, phi, lambda)) |> -tidyr::pivot_longer(cols = fh:f0) |> -ggplot2::ggplot( -ggplot2::aes(x = y, color = name, y = value) -) + -ggplot2::geom_line() -n <- 2000 -phi <- 0.8 -lambda <- 0.5 -yvec <- rberpo(n, phi, lambda) -Xmat <- matrix(1L, n, 1) -hist(yvec) -fit <- anova_bnp_berpoi(yvec, Xmat, iter = 20000L, warmup = 10000L) -fit$f_post |> -dplyr::rename(fh = f) |> -dplyr::mutate(f0 = dberpo(y, phi, lambda)) |> -tidyr::pivot_longer(cols = fh:f0) |> -ggplot2::ggplot( -ggplot2::aes(x = y, color = name, y = value) -) + -ggplot2::geom_line() -n <- 10000 -phi <- 0.8 -lambda <- 0.5 -yvec <- rberpo(n, phi, lambda) -Xmat <- matrix(1L, n, 1) -hist(yvec) -fit <- anova_bnp_berpoi(yvec, Xmat, iter = 20000L, warmup = 10000L) -fit$f_post |> -dplyr::rename(fh = f) |> -dplyr::mutate(f0 = dberpo(y, phi, lambda)) |> -tidyr::pivot_longer(cols = fh:f0) |> -ggplot2::ggplot( -ggplot2::aes(x = y, color = name, y = value) -) + -ggplot2::geom_line() -library(ANOVABNPTestR) -library(dplyr) -library(ggplot2) -library(tidyr) -# Probability mass function Bernoulli Poisson distribution -dberpo <- function(x, phi, lambda) { -phi * dpois(x - 1, lambda) + (1 - phi) * dpois(x, lambda) +# Fit our ANOVA BNP model +fit <- anova_bnp_normal(yvec, Xmat) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should be a straight line. +shift_plot(fit, group = 3) # this should look like an inverted tan(). +predictive_plot_simple(fit) +predictive_plot_simple(fit, 2) +predictive_plot_simple(fit, 3) +predictive_plot_simple(fit, 1) +predictive_plot_simple(fit, 4) +predictive_plot_simple(fit, 1) +predictive_plot_simple(fit, 2) +devtools::load_all(".") +# Simulate a sample +{ +N <- 1000 +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) +Xmat <- matrix(x, nrow = N, ncol = 2) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +# yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +yvec <- rnorm(N) / 2 } -# Generates random draws from a Bernoulli Poisson distribution -rberpo <- function(n, phi, lambda) { -rpois(n, lambda) + rbinom(n, size = 1, prob = phi) +# Fit our ANOVA BNP model +fit <- anova_bnp_normal(yvec, Xmat) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should be a straight line. +shift_plot(fit, group = 3) # this should look like an inverted tan(). +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should be a straight line. +devtools::load_all(".") +devtools::load_all(".") +# Simulate a sample +{ +N <- 1000 +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) +Xmat <- matrix(x, nrow = N, ncol = 2) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +# yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +yvec <- rnorm(N) / 2 } -n <- 10000 -phi <- 0.8 -lambda <- 0.5 -yvec <- rberpo(n, phi, lambda) -Xmat <- matrix(1L, n, 1) -hist(yvec) -fit <- -anova_bnp_berpoi( -yvec, -Xmat, -iter = 2000L, -warmup = 1000L, -rho = 1.0, -a = 0.1, -b = 0.1, -a1 = mean(yvec), -b1 = 1, -alpha0 = 1.0, -beta0 = 1.0, -lb = 0, -ub = 10 -) -fit <- -anova_bnp_berpoi( -yvec, -Xmat, -iter = 2000L, -warmup = 1000L, -rho = 1.0, -a = 0.1, -b = 0.1, -a1 = mean(yvec), -b1 = 1, -alpha0 = 1.0, -beta0 = 1.0, -) -n <- 10000 -phi <- 0.8 -lambda <- 0.5 -yvec <- rberpo(n, phi, lambda) -Xmat <- matrix(1L, n, 1) -hist(yvec) -fit <- -anova_bnp_berpoi( -yvec, -Xmat, -iter = 2000L, -warmup = 1000L, -rho = 1.0, -a = 0.1, -b = 0.1, -a1 = numeric(mean(yvec)), -b1 = numeric(1), -alpha0 = 1.0, -beta0 = 1.0, -) -fit <- -anova_bnp_berpoi( -yvec, -Xmat, -iter = 2000L, -warmup = 1000L, -rho = 1.0, -a = 0.1, -b = 0.1, -a1 = numeric(mean(yvec)) + 1, -b1 = numeric(1), -alpha0 = 1.0, -beta0 = 1.0, -) -fit <- -anova_bnp_berpoi( -yvec, -Xmat, -iter = 2000L, -warmup = 1000L, -rho = 1.0, -a = 0.1, -b = 0.1, -a1 = numeric(mean(yvec)) + 1, -b1 = numeric(1), -alpha0 = 1.0, -beta0 = 1.0, -) -?anova_bnp_berpoi -fit <- -anova_bnp_berpoi( -yvec, -Xmat, -iter = 2000L, -warmup = 1000L, -rho = 1.0, -a = 1, -b = 1, -a1 = numeric(mean(yvec)) + 1, -b1 = numeric(1), -alpha0 = 1.0, -beta0 = 1.0, -) -fit <- -anova_bnp_berpoi( -yvec, -Xmat, -iter = 2000L, -warmup = 1000L, -rho = 1.0, -a = 1, -b = 1, -a1 = round(mean(yvec)) + 1, -b1 = 1L, -alpha0 = 1.0, -beta0 = 1.0, -) -fit <- -anova_bnp_berpoi( -yvec, -Xmat, -iter = 2000L, -warmup = 1000L, -rho = 1.0, -a = 1, -b = 1, -a1 = mean(yvec), -b1 = 1, -alpha0 = 1.0, -beta0 = 1.0, -) -fit <- -anova_bnp_berpoi( -yvec, -Xmat, -iter = 2000L, -warmup = 1000L, -rho = 1.0, -a = 1.0, -b = 1.0, -a1 = 1.0, -b1 = 1.0, -alpha0 = 1.0, -beta0 = 1.0, -) -fit$f_post |> -dplyr::rename(fh = f) |> -dplyr::mutate(f0 = dberpo(y, phi, lambda)) |> -tidyr::pivot_longer(cols = fh:f0) |> -ggplot2::ggplot( -ggplot2::aes(x = y, color = name, y = value) -) + -ggplot2::geom_line() -fit <- -anova_bnp_berpoi( -yvec, -Xmat, -iter = 2000L, -warmup = 1000L, -rho = 1.0, -a = 0.1, -b = 0.1, -a1 = 1.0, -b1 = 1.0, -alpha0 = 1.0, -beta0 = 1.0, -) -fit$f_post |> -dplyr::rename(fh = f) |> -dplyr::mutate(f0 = dberpo(y, phi, lambda)) |> -tidyr::pivot_longer(cols = fh:f0) |> -ggplot2::ggplot( -ggplot2::aes(x = y, color = name, y = value) -) + -ggplot2::geom_line() -fit <- -anova_bnp_berpoi( -yvec, -Xmat, -iter = 2000L, -warmup = 1000L, -rho = 1.0, -a = 0.1, -b = 0.1, -a1 = mean(yvec), -b1 = 1.0, -alpha0 = 1.0, -beta0 = 1.0, -) +# Fit our ANOVA BNP model +fit <- anova_bnp_normal(yvec, Xmat) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. devtools::load_all(".") -setup() +# Simulate a sample +{ +N <- 1000 +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) +Xmat <- matrix(x, nrow = N, ncol = 2) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +# yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +yvec <- rnorm(N) / 2 +} +# Fit our ANOVA BNP model +fit <- anova_bnp_normal(yvec, Xmat) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +devtools::load_all(".") +# Simulate a sample +{ N <- 1000 -x <- as.integer(1 + (runif(2 * N) < 0.5)) +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) Xmat <- matrix(x, nrow = N, ncol = 2) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +# yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +yvec <- rnorm(N) / 2 +} +# Fit our ANOVA BNP model +fit <- anova_bnp_normal(yvec, Xmat) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Simulate a sample +{ N <- 1000 -x <- as.integer(1 + (runif(2 * N) < 0.5)) +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) Xmat <- matrix(x, nrow = N, ncol = 2) -yvec <- rnorm(N) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +} +# Fit our ANOVA BNP model fit <- anova_bnp_normal(yvec, Xmat) -hypothesis_post_simple(fit) -hypothesis_post_interaction(fit) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. devtools::load_all(".") +# Simulate a sample +{ N <- 1000 -x <- as.integer(1 + (runif(2 * N) < 0.5)) +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) Xmat <- matrix(x, nrow = N, ncol = 2) -yvec <- rnorm(N) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +} +# Fit our ANOVA BNP model fit <- anova_bnp_normal(yvec, Xmat) -hypothesis_post_simple(fit) -yvec <- rnorm(N) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +devtools::load_all(".") +# Simulate a sample +{ +N <- 1000 +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) +Xmat <- matrix(x, nrow = N, ncol = 2) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +} +# Fit our ANOVA BNP model fit <- anova_bnp_normal(yvec, Xmat) -fit$shift_post +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +shift_post(fit) +devtools::load_all(".") +devtools::load_all(".") +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +devtools::load_all(".") +# Simulate a sample +{ N <- 1000 -x <- as.integer(1 + (runif(2 * N) < 0.5)) +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) Xmat <- matrix(x, nrow = N, ncol = 2) -yvec <- rnorm(N) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +} +# Fit our ANOVA BNP model fit <- anova_bnp_normal(yvec, Xmat) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. devtools::load_all(".") +# Simulate a sample +{ N <- 1000 -x <- as.integer(1 + (runif(2 * N) < 0.5)) +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) Xmat <- matrix(x, nrow = N, ncol = 2) -yvec <- rnorm(N) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +} +# Fit our ANOVA BNP model fit <- anova_bnp_normal(yvec, Xmat) -tbl_shift <- shift_post(fit) -tbl_shift -tbl_shift -# tbl_shift |> -group_codes(fit) -# tbl_shift |> -tbl_shift |> -dplyr::mutate(group = paste("group:", group)) -# tbl_shift |> -group <- 2 -tbl_shift |> -dplyr::filter(group == {{ group }}) |> -ggplot2::ggplot(ggplot2::aes(x = y, y = shift)) + -ggplot2::geom_line() -predictive_plot_simple(fit, 1) -tbl_shift |> -dplyr::filter(group == {{ group }}) |> -ggplot2::ggplot(ggplot2::aes(x = y, y = shift)) + -ggplot2::geom_line() -x <- sample(1:3, N, replace = TRUE) -x -shift_plot <- function(fit, group) { -tbl_shift |> -dplyr::filter(.data$group == group) |> -ggplot2::ggplot(ggplot2::aes_string(x = "y", y = "shift")) + -ggplot2::geom_line() +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +devtools::load_all(".") +# Simulate a sample +{ +N <- 1000 +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) +Xmat <- matrix(x, nrow = N, ncol = 2) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 } -shift_plot <- function(fit, group) { -tbl_shift |> -shift_post() |> -dplyr::filter(.data$group == group) |> -ggplot2::ggplot(ggplot2::aes_string(x = "y", y = "shift")) + -ggplot2::geom_line() +# Fit our ANOVA BNP model +fit <- anova_bnp_normal(yvec, Xmat) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +devtools::load_all(".") +# Simulate a sample +{ +N <- 1000 +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) +Xmat <- matrix(x, nrow = N, ncol = 2) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 } -shift_plot(fit, group = 2) -shift_plot <- function(fit, group) { -fit |> -shift_post() |> -dplyr::filter(.data$group == group) |> -ggplot2::ggplot(ggplot2::aes_string(x = "y", y = "shift")) + -ggplot2::geom_line() +# Fit our ANOVA BNP model +fit <- anova_bnp_normal(yvec, Xmat) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +devtools::load_all(".") +# Simulate a sample +{ +N <- 1000 +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) +Xmat <- matrix(x, nrow = N, ncol = 2) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 } -shift_plot(fit, group = 2) -shift_plot <- function(fit, group) { -fit |> -shift_post() |> -dplyr::filter(.data$group == group) |> -ggplot2::ggplot(ggplot2::aes(x = y, y = shift)) + -ggplot2::geom_line() +# Fit our ANOVA BNP model +fit <- anova_bnp_normal(yvec, Xmat) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Simulate a sample +{ +N <- 1000 +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) +Xmat <- matrix(x, nrow = N, ncol = 2) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 } -shift_plot(fit, group = 2) -a <- shift_plot(fit, group = 2) -a -a -shift_plot <- function(fit, group) { -out <- -fit |> -shift_post() |> -dplyr::filter(.data$group == group) |> -ggplot2::ggplot(ggplot2::aes(x = y, y = shift)) + -ggplot2::geom_line() -return(out) +# Fit our ANOVA BNP model +fit <- anova_bnp_normal(yvec, Xmat) +devtools::load_all(".") +# Simulate a sample +{ +N <- 1000 +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) +Xmat <- matrix(x, nrow = N, ncol = 2) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 } -shift_plot(fit, group = 2) -shift_plot <- function(fit, group) { -out <- -fit |> -shift_post() |> -dplyr::filter(.data$group == group) |> -ggplot2::ggplot(ggplot2::aes(x = y, y = shift)) + -ggplot2::geom_line() -return(out) +# Fit our ANOVA BNP model +fit <- anova_bnp_normal(yvec, Xmat) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Simulate a sample +{ +N <- 1000 +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) +Xmat <- matrix(x, nrow = N, ncol = 2) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 } -shift_plot(fit, group = 2) -fit |> -shift_post() |> -dplyr::filter(.data$group == group) #|> -fit |> -shift_post() |> -dplyr::filter(.data$group == group) |> -ggplot2::ggplot(ggplot2::aes(x = y, y = shift)) #+ -fit |> -shift_post() |> -dplyr::filter(.data$group == group) |> -ggplot2::ggplot(ggplot2::aes(x = y, y = shift)) + -ggplot2::geom_line() -a <- fit |> -shift_post() |> -dplyr::filter(.data$group == group) |> -ggplot2::ggplot(ggplot2::aes(x = y, y = shift)) + -ggplot2::geom_line() -a -a <- fit |> -shift_post() |> -dplyr::filter(group == 2) |> -ggplot2::ggplot(ggplot2::aes(x = y, y = shift)) + -ggplot2::geom_line() -a -fit |> -shift_post() |> -dplyr::filter(group == 2) |> -ggplot2::ggplot(ggplot2::aes(x = y, y = shift)) + -ggplot2::geom_line() -fit$shift_post |> -dplyr::filter(group == 2) |> -ggplot2::ggplot(ggplot2::aes(x = y, y = shift)) + -ggplot2::geom_line() +# Fit our ANOVA BNP model +fit <- anova_bnp_normal(yvec, Xmat) devtools::load_all(".") +# Simulate a sample +{ N <- 1000 -x <- as.integer(1 + (runif(2 * N) < 0.5)) +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) Xmat <- matrix(x, nrow = N, ncol = 2) -yvec <- rnorm(N) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +} +# Fit our ANOVA BNP model fit <- anova_bnp_normal(yvec, Xmat) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +devtools::load_all(".") +# Simulate a sample +{ N <- 1000 -x <- as.integer(1 + (runif(2 * N) < 0.5)) +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) Xmat <- matrix(x, nrow = N, ncol = 2) -yvec <- rnorm(N) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +} +# Fit our ANOVA BNP model fit <- anova_bnp_normal(yvec, Xmat) -tbl_shift <- shift_post(fit) -hypothesis_post_simple(fit) -hypothesis_post_interaction(fit) -# tbl_shift |> -group <- 2 -tbl_shift |> -dplyr::filter(group == {{ group }}) |> -ggplot2::ggplot(ggplot2::aes(x = y, y = shift)) + -ggplot2::geom_line() -fit$shift_post |> -dplyr::filter(group == 2) |> -ggplot2::ggplot(ggplot2::aes(x = y, y = shift)) + -ggplot2::geom_line() -shift_plot <- function(fit, group) { -out <- -fit |> -shift_post() |> -dplyr::filter(.data$group == group) |> -ggplot2::ggplot(ggplot2::aes(x = y, y = shift)) + -ggplot2::geom_line() -return(out) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +devtools::load_all(".") +# Simulate a sample +{ +N <- 1000 +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) +Xmat <- matrix(x, nrow = N, ncol = 2) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 } -shift_plot(fit, group = 2) +# Fit our ANOVA BNP model +fit <- anova_bnp_normal(yvec, Xmat) +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. devtools::load_all(".") +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +devtools::load_all(".") +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. +# Simulate a sample +{ N <- 1000 -x <- as.integer(1 + (runif(2 * N) < 0.5)) +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) Xmat <- matrix(x, nrow = N, ncol = 2) -yvec <- rnorm(N) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +} +# Fit our ANOVA BNP model fit <- anova_bnp_normal(yvec, Xmat) devtools::load_all(".") +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +# Simulate a sample +{ N <- 1000 -x <- as.integer(1 + (runif(2 * N) < 0.5)) +d <- sample(c(-1, +1), 1 * N, replace = TRUE, prob = c(0.3, 0.7)) +x <- sample(c(1L, 2L), 2 * N, replace = TRUE) Xmat <- matrix(x, nrow = N, ncol = 2) -yvec <- rnorm(N) +gvec1 <- Xmat[, 1] +gvec2 <- Xmat[, 2] +yvec <- 1.2 * d * (gvec1 == 1) * (gvec2 == 2) + rnorm(N) / 2 +} +# Fit our ANOVA BNP model fit <- anova_bnp_normal(yvec, Xmat) -shift_plot(fit, group = 2) -# Deploy locally -devtools::document() -pkgdown::build_site() -library(ANOVABNPTestR) -# Deploy locally -devtools::document() -pkgdown::build_site() -# Deploy locally -devtools::document() -pkgdown::build_site() +# Plot the shift function for the second cell +shift_plot(fit, group = 2) # this should look like an inverted tan(). +shift_plot(fit, group = 3) # this should be a straight line. diff --git a/extra/demo_normal.R b/extra/demo_normal.R index f419d04..c49e44c 100644 --- a/extra/demo_normal.R +++ b/extra/demo_normal.R @@ -13,5 +13,6 @@ fit <- anova_bnp_normal(yvec, Xmat) # Plot the shift function for the second cell -shift_plot(fit, group = 2) # this should look like a tan(). +shift_plot(fit, group = 2) # this should look like an sigmoid shift_plot(fit, group = 3) # this should be a straight line. +