R Under development (unstable) (2023-10-04 r85267 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(matrixTests) > source("utils/capture.r") > > #--- x has less than 2 observations -------------------------------------------- > > wrn <- 'row_f_var: 1 of the rows had less than 1 "x" observation.\nFirst occurrence at row 1' > nacolumns <- c("df.num", "df.denom", "statistic", "pvalue", "conf.low", "conf.high") > > # 0 observations > res <- capture(row_f_var(numeric(), 1:2)) > stopifnot(all.equal(res$warning, wrn)) > stopifnot(all(is.na(res$value[,nacolumns]))) > stopifnot(all.equal(res$value$obs.x, 0)) > stopifnot(all.equal(res$value$obs.y, 2)) > stopifnot(all.equal(res$value$obs.tot, 2)) > > # 1 observations > res <- capture(row_f_var(1, 1:2)) > stopifnot(all.equal(res$warning, wrn)) > stopifnot(all(is.na(res$value[,nacolumns]))) > stopifnot(all.equal(res$value$obs.x, 1)) > stopifnot(all.equal(res$value$obs.y, 2)) > stopifnot(all.equal(res$value$obs.tot, 3)) > > # 1 observation + NA > res <- capture(row_f_var(c(1, NA), 1:2)) > stopifnot(all.equal(res$warning, wrn)) > stopifnot(all(is.na(res$value[,nacolumns]))) > stopifnot(all.equal(res$value$obs.x, 1)) > stopifnot(all.equal(res$value$obs.y, 2)) > stopifnot(all.equal(res$value$obs.tot, 3)) > > # only NAs > res <- capture(row_f_var(c(NA_integer_, NA_integer_), 1:2)) > stopifnot(all.equal(res$warning, wrn)) > stopifnot(all(is.na(res$value[,nacolumns]))) > stopifnot(all.equal(res$value$obs.x, 0)) > stopifnot(all.equal(res$value$obs.y, 2)) > stopifnot(all.equal(res$value$obs.tot, 2)) > > > #--- y has less than 2 observations -------------------------------------------- > > wrn <- 'row_f_var: 1 of the rows had less than 1 "y" observation.\nFirst occurrence at row 1' > nacolumns <- c("df.num", "df.denom", "statistic", "pvalue", "conf.low", "conf.high") > > # 0 observations > res <- capture(row_f_var(1:2, numeric())) > stopifnot(all.equal(res$warning, wrn)) > stopifnot(all(is.na(res$value[,nacolumns]))) > stopifnot(all.equal(res$value$obs.x, 2)) > stopifnot(all.equal(res$value$obs.y, 0)) > stopifnot(all.equal(res$value$obs.tot, 2)) > > # 1 observations > res <- capture(row_f_var(1:2, 1)) > stopifnot(all.equal(res$warning, wrn)) > stopifnot(all(is.na(res$value[,nacolumns]))) > stopifnot(all.equal(res$value$obs.x, 2)) > stopifnot(all.equal(res$value$obs.y, 1)) > stopifnot(all.equal(res$value$obs.tot, 3)) > > # 1 observation + NA > res <- capture(row_f_var(1:2, c(1, NA))) > stopifnot(all.equal(res$warning, wrn)) > stopifnot(all(is.na(res$value[,nacolumns]))) > stopifnot(all.equal(res$value$obs.x, 2)) > stopifnot(all.equal(res$value$obs.y, 1)) > stopifnot(all.equal(res$value$obs.tot, 3)) > > # only NAs > res <- capture(row_f_var(1:2, c(NA_integer_, NA_integer_))) > stopifnot(all.equal(res$warning, wrn)) > stopifnot(all(is.na(res$value[,nacolumns]))) > stopifnot(all.equal(res$value$obs.x, 2)) > stopifnot(all.equal(res$value$obs.y, 0)) > stopifnot(all.equal(res$value$obs.tot, 2)) > > > #--- x has 0 variance ---------------------------------------------------------- > > wrn <- 'row_f_var: 1 of the rows had zero variance in "x".\nFirst occurrence at row 1' > > # constant values > res <- capture(row_f_var(rep(1,5), 1:5)) > stopifnot(all.equal(res$warning, wrn)) > stopifnot(all.equal(res$value$var.x, 0)) > stopifnot(all.equal(res$value$var.ratio, 0)) > > # constant values with NAs > res <- capture(row_f_var(c(NA,rep(1,5),NA), 1:5)) > stopifnot(all.equal(res$warning, wrn)) > stopifnot(all.equal(res$value$var.x, 0)) > stopifnot(all.equal(res$value$var.ratio, 0)) > > > #--- y has 0 variance ---------------------------------------------------------- > > wrn <- 'row_f_var: 1 of the rows had zero variance in "y".\nFirst occurrence at row 1' > > # constant values > res <- capture(row_f_var(1:5, rep(1,5))) > stopifnot(all.equal(res$warning, wrn)) > stopifnot(all.equal(res$value$var.y, 0)) > stopifnot(all.equal(res$value$var.ratio, Inf)) > > # constant values with NAs > res <- capture(row_f_var(1:5, c(NA,rep(1,5),NA))) > stopifnot(all.equal(res$warning, wrn)) > stopifnot(all.equal(res$value$var.y, 0)) > stopifnot(all.equal(res$value$var.ratio, Inf)) > > > #--- both have 0 variance ------------------------------------------------------ > > wrnx <- 'row_f_var: 1 of the rows had zero variance in "x".\nFirst occurrence at row 1' > wrny <- 'row_f_var: 1 of the rows had zero variance in "y".\nFirst occurrence at row 1' > nacolumns <- c("df.num", "df.denom", "statistic", "pvalue", "conf.low", "conf.high") > > # x and y have constant values > res <- capture(row_f_var(rep(1,5), rep(2,5))) > stopifnot(all.equal(res$warning, c(wrnx, wrny))) > stopifnot(all(is.na(res$value[,nacolumns]))) > stopifnot(all.equal(res$value$var.x, 0)) > stopifnot(all.equal(res$value$var.y, 0)) > stopifnot(all.equal(res$value$var.ratio, NaN)) > > > proc.time() user system elapsed 0.18 0.04 0.21