Skip to content

Commit

Permalink
add a cube with no row/col differences
Browse files Browse the repository at this point in the history
  • Loading branch information
malecki committed Mar 13, 2019
1 parent b3877f5 commit ea7eb71
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 0 deletions.
190 changes: 190 additions & 0 deletions cubes/same-counts-3x4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
{
"element": "shoji:view",
"self": "/api/datasets/9c9001/cube/?query=%7B%22dimensions%22%3A%5B%7B%22variable%22%3A%22%2Fapi%2Fdatasets%2F9c9001%2Fvariables%2F000000%2F%22%7D%2C%7B%22variable%22%3A%22%2Fapi%2Fdatasets%2F9c9001%2Fvariables%2F000001%2F%22%7D%5D%2C%22measures%22%3A%7B%22count%22%3A%7B%22function%22%3A%22cube_count%22%2C%22args%22%3A%5B%5D%7D%7D%2C%22weight%22%3Anull%7D&filter=%7B%7D",
"value": {
"query": {
"measures": {
"count": {
"function": "cube_count",
"args": [

]
}
},
"dimensions": [
{
"variable": "/api/datasets/9c9001/variables/000000/"
},
{
"variable": "/api/datasets/9c9001/variables/000001/"
}
],
"weight": null
},
"query_environment": {
"filter": [

]
},
"result": {
"dimensions": [
{
"references": {
"alias": "Var1",
"name": "Var1"
},
"derived": false,
"type": {
"ordinal": false,
"class": "categorical",
"categories": [
{
"numeric_value": 1,
"id": 1,
"name": "1",
"missing": false
},
{
"numeric_value": 2,
"id": 2,
"name": "2",
"missing": false
},
{
"numeric_value": 3,
"id": 3,
"name": "3",
"missing": false
},
{
"numeric_value": null,
"id": -1,
"name": "No Data",
"missing": true
}
]
}
},
{
"references": {
"alias": "Var2",
"name": "Var2"
},
"derived": false,
"type": {
"ordinal": false,
"class": "categorical",
"categories": [
{
"numeric_value": 1,
"id": 1,
"name": "a",
"missing": false
},
{
"numeric_value": 2,
"id": 2,
"name": "b",
"missing": false
},
{
"numeric_value": 3,
"id": 3,
"name": "c",
"missing": false
},
{
"numeric_value": 4,
"id": 4,
"name": "d",
"missing": false
},
{
"numeric_value": null,
"id": -1,
"name": "No Data",
"missing": true
}
]
}
}
],
"missing": 0,
"measures": {
"count": {
"data": [
10,
10,
10,
10,
0,
20,
20,
20,
20,
0,
30,
30,
30,
30,
0,
0,
0,
0,
0,
0
],
"n_missing": 0,
"metadata": {
"references": {

},
"derived": true,
"type": {
"integer": true,
"missing_rules": {

},
"missing_reasons": {
"No Data": -1
},
"class": "numeric"
}
}
}
},
"n": 240,
"unfiltered": {
"unweighted_n": 240,
"weighted_n": 240
},
"filtered": {
"unweighted_n": 240,
"weighted_n": 240
},
"counts": [
10,
10,
10,
10,
0,
20,
20,
20,
20,
0,
30,
30,
30,
30,
0,
0,
0,
0,
0,
0
],
"element": "crunch:cube"
}
}
}
Binary file modified inst/cubes.tgz
Binary file not shown.
14 changes: 14 additions & 0 deletions tests/testthat/test-cube-pairwise.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ context("Cube pairwise multiple comparisons")
hirotsu <- loadCube("cubes/pairwise-hirotsu-illness-x-occupation.json")
hirotsuTranspose <- loadCube("cubes/pairwise-hirotsu-occupation-x-illness.json")
sampled <- loadCube("cubes/cube-random-3x4.json")
samecounts <- loadCube("cubes/same-counts-3x4.json")

test_that("Reference Chi-square from Z-tests.Rmd, 2017-10-26", {
reference <- structure(c(NA, 1.79366044505363, 1.44505144460352, 1.52650609891684,
Expand Down Expand Up @@ -150,3 +151,16 @@ test_that("Wishart P-values from reference in Hirotsu paper", {
out_t <- wishartPvalues(hirotsuTranspose, dim="row")
expect_equal(out, out_t)
})

test_that("a matrix where each row and column is the same", {
referenceChisq <- structure(rep(0, 16),
.Dim = c(4L, 4L),
.Dimnames = list(c("a", "b", "c", "d"), c("a", "b", "c", "d")))
referencePvals <- structure(rep(1, 16),
.Dim = c(4L, 4L),
.Dimnames = list(c("a", "b", "c", "d"), c("a", "b", "c", "d")))
out1 <- wishartMatrix(samecounts)
expect_equal(out1, referenceChisq)
out2 <- wishartPvalues(samecounts)
expect_equal(out2, referencePvals)
})

0 comments on commit ea7eb71

Please sign in to comment.