diff --git a/.Rhistory b/.Rhistory index cc14ccb..1973fb8 100644 --- a/.Rhistory +++ b/.Rhistory @@ -1,175 +1,3 @@ -expect_equal(fit$n, n) -expect_equal(fit$resolution, floor(sqrt(n))) -expect_equal(colSums(fit$mass_matrix), rowSums(fit$mass_matrix)) -expect_equal(NROW(fit$data), n) -expect_equal(NCOL(fit$data), 2) -}) -qad -qad:::qad.data.frame() -qad:::qad.data.frame -n <- 100 -x <- runif(n) -y <- runif(n) -fit <- qad(x,y, print = FALSE) -coef(fit) -expect_s3_class(fit, "S3") -test_that("coef", { -n <- 100 -x <- runif(n) -y <- runif(n) -fit <- qad(x,y, print = FALSE) -expect_s3_class(fit, "S3") -coef(fit) -}) -test_that("coef", { -n <- 100 -x <- runif(n) -y <- runif(n) -fit <- qad(x,y, print = FALSE) -expect_s3_class(fit, "qad") -}) -coef(fit) -coef(fit) == fit$results$coef -fit$results -coef(fit) == c(fit$results$coef, fit$results$p.values) -test_that("coef", { -n <- 100 -x <- runif(n) -y <- runif(n) -fit <- qad(x,y, print = FALSE) -expect_s3_class(fit, "qad") -expect_equal(coef(fit),c(fit$results$coef, fit$results$p.values)) -}) -test_that("coef", { -n <- 100 -x <- runif(n) -y <- runif(n) -fit <- qad(x,y, print = FALSE) -expect_s3_class(fit, "qad") -expect_equal(unname(coef(fit)),c(fit$results$coef, fit$results$p.values)) -}) -coef -coef.qad() -coef.qad -n <- 100 -x <- runif(n) -y <- runif(n) -fit <- qad(x,y, print = FALSE) -test_that("coef", { -expect_s3_class(fit, "qad") -expect_equal(unname(qad::coef(fit)),c(fit$results$coef, fit$results$p.values)) -}) -test_that("coef", { -expect_s3_class(fit, "qad") -expect_equal(unname(coef(fit)),c(fit$results$coef, fit$results$p.values)) -}) -summary(fit) -summary(fit) -test <- summary(fit) -test -fit$results -test_that("summary", { -test <- summary(fit) -expect_equal(test$SampleSize, n) -expect_equal(test$resolution, 10) -expect_equal(test$dependence_values, fit$results) -}) -p <- plot(fit) -class(p) -test_that("plot.qad", { -expect_equal(class(plot(fit)), c("gg", "ggplot")) -expect_equal(class(plot(fit, addSample = TRUE)), c("gg", "ggplot")) -expect_equal(class(plot(fit, copula = TRUE)), c("gg", "ggplot")) -expect_equal(class(plot(fit, density = TRUE)), c("gg", "ggplot")) -expect_equal(class(plot(fit, margins = TRUE)), c("gg", "ggplot")) -expect_equal(class(plot(fit, panel.grid = FALSE)), c("gg", "ggplot")) -}) -browseVignettes("lubridate") -browseVignettes() -qad(x,y) -test_that("class of qad", { -n <- 20 -x <- runif(n) -y <- runif(n) -expect_output(qad::qad(x,y)) -fit <- qad::qad(x,y, print = FALSE) -expect_identical(class(fit), "qad") -expect_equal(fit$n, n) -expect_equal(fit$resolution, floor(sqrt(n))) -expect_equal(colSums(fit$mass_matrix), rowSums(fit$mass_matrix)) -expect_equal(NROW(fit$data), n) -expect_equal(NCOL(fit$data), 2) -}) -test_that("coef.qad", { -expect_s3_class(fit, "qad") -expect_equal(unname(coef(fit)),c(fit$results$coef, fit$results$p.values)) -expect_output(coef(fit)) -}) -test_that("summary.qad", { -test <- summary(fit) -expect_equal(test$SampleSize, n) -expect_equal(test$resolution, 10) -expect_equal(test$dependence_values, fit$results) -expect_output(summary(fit)) -}) -n <- 100 -x <- runif(n) -y <- runif(n) -z <- runif(n) -df <- data.frame(x,y,z) -pw_fit <- pairwise.qad(df) -class(pw_fit) -test_that("heatmap.qad", { -expect_equal(heatmap.qad(pw_fit), c("gg", "ggplot2")) -}) -test_that("heatmap.qad", { -expect_equal(heatmap.qad(pw_fit), c("gg", "ggplot")) -}) -heatmap.qad(pw_fit) -test_that("heatmap.qad", { -expect_equal(class(heatmap.qad(pw_fit)), c("gg", "ggplot")) -}) -test_that("heatmap.qad", { -expect_equal(class(qad::heatmap.qad(pw_fit)), c("gg", "ggplot")) -}) -test_that("heatmap.qad", { -expect_equal(class(qad::heatmap.qad(pw_fit, select = "dependence")), c("gg", "ggplot")) -}) -test_that("heatmap.qad", { -expect_equal(class(qad::heatmap.qad(pw_fit, select = "dependence")), c("gg", "ggplot")) -expect_equal(class(qad::heatmap.qad(pw_fit, select = "dependence", -fontsize = 5, significance = T, scale = "rel", color = "viridis", title = "test")), c("gg", "ggplot")) -}) -test_that("heatmap.qad", { -n <- 100 -x <- runif(n) -y <- runif(n) -z <- runif(n) -df <- data.frame(x,y,z) -pw_fit <- pairwise.qad(df) -expect_equal(class(qad::heatmap.qad(pw_fit, select = "dependence")), c("gg", "ggplot")) -expect_equal(class(qad::heatmap.qad(pw_fit, select = "dependence", -fontsize = 5, significance = T, scale = "rel", color = "viridis", title = "test")), c("gg", "ggplot")) -}) -fit$mass_matrix -test_that("plot_density", { -expect_equal(class(plot_density(fit$mass_matrix)), c("gg", "ggplot")) -}) -plot_density(fit$mass_matrix) -expect_gt(pqad(0.4, 100, R = 10, resolution = 10), 0) -test_that("pqad", { -expect_gt(pqad(0.4, 100, R = 10, resolution = 10), 0) -}) -pqad(0.4, 100, R = 10, resolution = 10) -pqad(0.2, 100, R = 10, resolution = 10) -test_that("pqad", { -expect_gt(pqad(0.2, 100, R = 10, resolution = 10), 0) -}) -typeof(pqad(0.2, 100, R = 10, resolution = 10)) -test_that("pqad", { -expect_type(pqad(0.2, 100, R = 10, resolution = 10), "double") -}) -qqad(0.2, 100, R = 10, resolution = 10) test_that("pqad", { expect_type(pqad(0.2, 100, R = 10, resolution = 10), "double") expect_type(qqad(0.2, 100, R = 10, resolution = 10), "double") @@ -510,3 +338,175 @@ vignette("qad") cut Sys.setenv(PATH = paste(Sys.getenv("PATH"), "C:\RTools40", "C:\RTools40\mingw64\bin", sep = ";")) devtools::install(build_vignettes = TRUE) +n <- 100 +x <- rnorm(n) +y <- x^2 + rnorm(n, 0, 0.1) +plot(x,y) +y <- x^2 + rnorm(n, 0, 1) +plot(x,y) +qad(x,y) +n <- 100 +x <- rnorm(n) +y <- x^2 + rnorm(n, 0, 1) +plot(x,y) +qad(x,y) +library(qad) +qad(x,y) +fit <- qad(x,y) +coef(fit) +#Comparison with correlation +cor(x,y, method = "pearson") +cor(x,y, method = "spearman") +cor(x,y, method = "kendall") +set.seed(20211115) +set.seed(31415) +n <- 100 +x <- rnorm(n) +y <- x^2 + rnorm(n, 0, 1) +plot(x,y) +fit <- qad(x,y) +set.seed(3141) +n <- 100 +x <- rnorm(n) +y <- x^2 + rnorm(n, 0, 1) +plot(x,y) +set.seed(314) +n <- 100 +x <- rnorm(n) +y <- x^2 + rnorm(n, 0, 1) +plot(x,y) +fit <- qad(x,y) +coef(fit) +#Comparison with correlation +cor(x,y, method = "pearson") +cor(x,y, method = "spearman") +cor(x,y, method = "kendall") +test_that("zeta1 returns exact values", { +#Example 1 +x <- c(1,2,3,4,5) +y <- c(1,2,3,4,5) +expect_equal(qad::zeta1(x, y, resolution = 5), 0.9) +expect_equal(qad::zeta1(x, y, resolution = 2), 0.6) +expect_equal(qad::zeta1(x, y, resolution = 1), 0) +expect_equal(qad::zeta1(x, y, resolution = 10), 0.9) +expect_equal(qad::zeta1(x,y), qad::zeta1(y,x)) +#Example 2 +x <- c(1,2,3,4,5,6,7,8,9,10) +y <- c(1,1,1,1,3,3,1,1,1,1) +expect_equal(qad::zeta1(x, y, resolution = 10), 0.48) +expect_equal(qad::zeta1(y, x, resolution = 10), 0.24) +}) +library(testthat) +library(qad) +test_that("zeta1 returns exact values", { +#Example 1 +x <- c(1,2,3,4,5) +y <- c(1,2,3,4,5) +expect_equal(qad::zeta1(x, y, resolution = 5), 0.9) +expect_equal(qad::zeta1(x, y, resolution = 2), 0.6) +expect_equal(qad::zeta1(x, y, resolution = 1), 0) +expect_equal(qad::zeta1(x, y, resolution = 10), 0.9) +expect_equal(qad::zeta1(x,y), qad::zeta1(y,x)) +#Example 2 +x <- c(1,2,3,4,5,6,7,8,9,10) +y <- c(1,1,1,1,3,3,1,1,1,1) +expect_equal(qad::zeta1(x, y, resolution = 10), 0.48) +expect_equal(qad::zeta1(y, x, resolution = 10), 0.24) +}) +test_that("zeta1 returns exact values", { +#Example 1 +x <- c(1,2,3,4,5) +y <- c(1,2,3,4,5) +expect_equal(qad::zeta1(x, y, resolution = 5), 0.9) +expect_equal(qad::zeta1(x, y, resolution = 2), 0.6) +expect_equal(qad::zeta1(x, y, resolution = 1), 0) +expect_equal(qad::zeta1(x, y, resolution = 10), 0.9) +expect_equal(qad::zeta1(x,y), qad::zeta1(y,x)) +#Example 2 +x <- c(1,2,3,4,5,6,7,8,9,10) +y <- c(1,1,1,1,3,3,1,1,1,1) +expect_equal(qad::zeta1(x, y, resolution = 10), 0.48) +expect_equal(qad::zeta1(y, x, resolution = 10), 0.24) +#Example (checkmin copula) +N <- 10 +x <- 1:N +y <- 1:N +expect_equal(qad::zeta1(x,y, resolution = N), 1-1/(2*N)) +}) +test_that("zeta1 returns exact values", { +#Example 1 +x <- c(1,2,3,4,5) +y <- c(1,2,3,4,5) +expect_equal(qad::zeta1(x, y, resolution = 5), 0.9) +expect_equal(qad::zeta1(x, y, resolution = 2), 0.6) +expect_equal(qad::zeta1(x, y, resolution = 1), 0) +expect_equal(qad::zeta1(x, y, resolution = 10), 0.9) +expect_equal(qad::zeta1(x,y), qad::zeta1(y,x)) +#Example 2 +x <- c(1,2,3,4,5,6,7,8,9,10) +y <- c(1,1,1,1,3,3,1,1,1,1) +expect_equal(qad::zeta1(x, y, resolution = 10), 0.48) +expect_equal(qad::zeta1(y, x, resolution = 10), 0.24) +#Example (checkmin copula) +NN <- c(2,10,22,44,122,200) +for(N in NN){ +N <- NN[i] +x <- 1:N +y <- 1:N +expect_equal(qad::zeta1(x,y, resolution = N), 1-1/(2*N)) +expect_equal(qad::zeta1(y,x, resolution = N), 1-1/(2*N)) +} +}) +test_that("zeta1 returns exact values", { +#Example 1 +x <- c(1,2,3,4,5) +y <- c(1,2,3,4,5) +expect_equal(qad::zeta1(x, y, resolution = 5), 0.9) +expect_equal(qad::zeta1(x, y, resolution = 2), 0.6) +expect_equal(qad::zeta1(x, y, resolution = 1), 0) +expect_equal(qad::zeta1(x, y, resolution = 10), 0.9) +expect_equal(qad::zeta1(x,y), qad::zeta1(y,x)) +#Example 2 +x <- c(1,2,3,4,5,6,7,8,9,10) +y <- c(1,1,1,1,3,3,1,1,1,1) +expect_equal(qad::zeta1(x, y, resolution = 10), 0.48) +expect_equal(qad::zeta1(y, x, resolution = 10), 0.24) +#Example (checkmin copula) +NN <- c(2,10,22,44,122,200) +for(N in NN){ +x <- 1:N +y <- 1:N +expect_equal(qad::zeta1(x,y, resolution = N), 1-1/(2*N)) +expect_equal(qad::zeta1(y,x, resolution = N), 1-1/(2*N)) +} +}) +test_that("predictions sum to one", { +n <- 8 +x <- 1:n +y <- x^2 +sample <- data.frame(x, y) +qad.fit <- qad::qad(sample, print = FALSE, resolution = 4) +pred <-qad:: predict.qad(qad.fit, values = c(1, 3, 5, 7), conditioned = "x1", pred_plot = FALSE) +expect_equal(pred$prediction$`x1=1`, c(1,0,0,0)) +expect_equal(pred$prediction$`x1=3`, c(0,1,0,0)) +expect_equal(pred$prediction$`x1=5`, c(0,0,1,0)) +expect_equal(pred$prediction$`x1=7`, c(0,0,0,1)) +n <- 250 +x <- runif(n, -1, 1) +y <- x^2 + runif(n, -0.1,0.1) +qad.fit <- qad::qad(x,y, print = FALSE) +pred <- qad::predict.qad(qad.fit, values = c(0, 0.5, -0.5), conditioned = "x1", pred_plot = FALSE) +expect_equal(sum(pred$prediction$`x1=0`), 1) +expect_equal(sum(pred$prediction$`x1=0.5`), 1) +expect_equal(sum(pred$prediction$`x1=-0.5`), 1) +}) +usethis::use_readme_rmd() +roxygen2::roxygenise() +check() +library(qad) +?qad +library(devtools) +build_vignettes() +devtools:build(vignettes = TRUE) +devtools::build(vignettes = TRUE) +devtools::build() diff --git a/README.Rmd b/README.Rmd index ecf6030..2567c76 100644 --- a/README.Rmd +++ b/README.Rmd @@ -18,10 +18,12 @@ library(qad) ``` -# qad +# qad [![CRAN status](https://www.r-pkg.org/badges/version/qad)](https://cran.r-project.org/package=qad) +[![](https://cranlogs.r-pkg.org/badges/qad)](https://cran.r-project.org/package=qad) + diff --git a/README.md b/README.md index f8b6f31..c7d3e82 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ -# qad +# qad [![CRAN status](https://www.r-pkg.org/badges/version/qad)](https://cran.r-project.org/package=qad) +[![](https://cranlogs.r-pkg.org/badges/qad)](https://cran.r-project.org/package=qad) + ------------------------------------------------------------------------ diff --git a/vignettes/qad-vignette.Rmd b/vignettes/qad-vignette.Rmd index 1becef2..e3de76a 100644 --- a/vignettes/qad-vignette.Rmd +++ b/vignettes/qad-vignette.Rmd @@ -266,7 +266,7 @@ p6 ## Install qad -The R-package qad is (freely) available on CRAN. You can download and install the current version of qad from [CRAN](https://CRAN.R-project.org) via: +The R-package qad is (freely) available on CRAN. You can download and install the current version of qad from [CRAN](https://CRAN.R-project.org) via: ```{r eval = F, echo = T} install.packages("qad")