Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init seed with random value #487

Merged
merged 2 commits into from
Nov 26, 2024
Merged

Conversation

koenderks
Copy link
Collaborator

@koenderks
Copy link
Collaborator Author

@lottemensink What do you think about initialising the seeds (in selection, model fairness and number bunching) with random values?

@koenderks
Copy link
Collaborator Author

koenderks commented Nov 21, 2024

@JorisGoosen I think this set.seed(1) that is added to all unit tests is a problem in jaspTools. If I make the unit test using:

options <- jaspTools::analysisOptions("auditSelection")
options$id <- "ID"
options$values <- "bookValue"
options$n <- 200
options$explanatoryText <- TRUE
options$tableSample <- TRUE
options$export_sample <- FALSE
options$file <- ""
options$units <- "values"
options$sampling_method <- "interval"
options$startMethod <- "fixedStart"
options$randomize <- FALSE
options$rank <- ""
options$tableDescriptives <- FALSE
options$start <- 1
options$name_indicator <- ""
options$seed <- 1
results <- jaspTools::runAnalysis("auditSelection", "BuildIt_Monetary.csv", options, makeTests = T)

Then I get this test code from jaspResults:

options <- analysisOptions("auditSelection")
options$n <- 200
options$id <- "ID"
options$values <- "bookValue"
options$explanatoryText <- TRUE
options$tableSample <- TRUE
options$export_sample <- FALSE
options$file <- ""
options$units <- "values"
options$sampling_method <- "interval"
options$startMethod <- "fixedStart"
options$randomize <- FALSE
options$rank <- ""
options$tableDescriptives <- FALSE
options$start <- 1
options$name_indicator <- ""
options$seed <- 1
set.seed(1) # COMMENT: NOTE THIS
results <- runAnalysis("auditSelection", "BuildIt_Monetary.csv", options)


test_that("<b>Table 2.</b> Information about Monetary Interval Selection results match", {
	table <- results[["results"]][["selectionContainer"]][["collection"]][["selectionContainer_tableInterval"]][["data"]]
	jaspTools::expect_equal_tables(table,
		list(3500, 1403220.82, 200, 200, "7.5%", "Total", 105247.58, 0, 0,
			 0, 0, "0%", "Top stratum", 0, 3500, 1403220.82, 200, 200, "7.5%",
			 "Bottom stratum", 105247.58))
})

test_that("<b>Table 3.</b> Selected Items results match", {
	table <- results[["results"]][["selectionContainer"]][["collection"]][["selectionContainer_tableSample"]][["data"]]
	jaspTools::expect_equal_tables(table,
		list(82884, 1, 1, 242.61, 46163, 17, 1, 511.62, 57172, 38, 1, 329.3,
			 86073, 55, 1, 874.46, 90160, 73, 1, 205.69, 31740, 89, 1, 735.45,
			 4756, 110, 1, 295.96, 13081, 128, 1, 734.93, 90183, 146, 1,
			 333.28, 76263, 162, 1, 701.99, 96080, 183, 1, 449.07, 96029,
			 201, 1, 465.35, 11890, 218, 1, 296.31, 98624, 235, 1, 340.6,
			 78992, 252, 1, 686.1, 96292, 269, 1, 179.32, 22629, 289, 1,
			 488.41, 11569, 306, 1, 1025.03, 57791, 325, 1, 376, 15197, 344,
			 1, 536.77, 20711, 358, 1, 610.88, 58735, 377, 1, 620.96, 75887,
			 392, 1, 739, 497, 411, 1, 640.18, 24835, 430, 1, 237, 52055,
			 449, 1, 879.91, 26364, 462, 1, 740.25, 71824, 479, 1, 305.14,
			 8847, 497, 1, 397.11, 56756, 514, 1, 348.08, 61005, 536, 1,
			 233.97, 44391, 554, 1, 374.93, 88214, 574, 1, 214.61, 16689,
			 589, 1, 630.99, 27905, 606, 1, 868.59, 51619, 625, 1, 274.09,
			 58370, 641, 1, 182.14, 47485, 660, 1, 773.14, 20237, 679, 1,
			 669.75, 64305, 699, 1, 319.68, 99012, 715, 1, 313.75, 78676,
			 735, 1, 346.28, 4261, 752, 1, 214.07, 47596, 771, 1, 256.13,
			 72660, 795, 1, 366.19, 82711, 813, 1, 288.93, 80057, 828, 1,
			 762.64, 35269, 850, 1, 281.84, 83339, 867, 1, 614.68, 93477,
			 887, 1, 692.36, 98110, 902, 1, 617.6, 73208, 921, 1, 370.28,
			 68039, 939, 1, 684.79, 99419, 956, 1, 668.93, 64369, 972, 1,
			 382.49, 47424, 992, 1, 469.18, 92166, 1010, 1, 566.01, 83189,
			 1031, 1, 199.8, 59197, 1050, 1, 796.94, 37569, 1068, 1, 633.59,
			 65319, 1081, 1, 502.54, 85233, 1098, 1, 686.1, 28178, 1113,
			 1, 367.64, 38019, 1132, 1, 537.14, 37412, 1150, 1, 306.66, 59189,
			 1165, 1, 186.49, 10345, 1182, 1, 294.04, 90284, 1198, 1, 550.7,
			 12827, 1214, 1, 688.28, 5324, 1233, 1, 503.95, 57764, 1249,
			 1, 696.32, 6771, 1267, 1, 351.53, 45561, 1286, 1, 702.76, 60970,
			 1301, 1, 348.48, 28529, 1317, 1, 471.97, 77871, 1335, 1, 812.13,
			 19517, 1354, 1, 340.07, 8070, 1368, 1, 938.12, 83336, 1383,
			 1, 656.34, 55381, 1402, 1, 900.38, 88454, 1421, 1, 856.28, 13214,
			 1437, 1, 994.44, 60630, 1455, 1, 681.91, 83225, 1474, 1, 221.15,
			 81443, 1492, 1, 543.8, 48139, 1505, 1, 718.58, 7652, 1518, 1,
			 846.99, 36945, 1534, 1, 714.02, 4120, 1552, 1, 233.88, 26525,
			 1572, 1, 941.47, 97834, 1590, 1, 294.9, 60760, 1606, 1, 715.14,
			 98301, 1627, 1, 429.07, 6686, 1646, 1, 343.83, 39990, 1668,
			 1, 788, 20736, 1685, 1, 407.24, 83784, 1702, 1, 389.55, 35982,
			 1721, 1, 829.17, 24275, 1738, 1, 721.75, 10054, 1754, 1, 369.34,
			 87258, 1774, 1, 157.68, 6154, 1791, 1, 285.42, 40471, 1808,
			 1, 438.74, 65326, 1822, 1, 484.13, 37044, 1839, 1, 654.61, 78043,
			 1858, 1, 664.6, 78011, 1877, 1, 583.89, 2885, 1895, 1, 285,
			 94914, 1912, 1, 646.29, 27340, 1927, 1, 659.18, 98561, 1942,
			 1, 294.24, 27256, 1958, 1, 314.22, 85588, 1976, 1, 535.51, 2740,
			 1995, 1, 714.23, 5590, 2010, 1, 676.34, 21217, 2026, 1, 172.91,
			 13683, 2041, 1, 381.64, 35189, 2058, 1, 337.29, 29742, 2075,
			 1, 554.85, 89961, 2089, 1, 337.64, 48652, 2103, 1, 497.21, 99274,
			 2118, 1, 816.62, 72040, 2135, 1, 509.04, 25056, 2149, 1, 344.4,
			 16092, 2168, 1, 595.35, 39429, 2183, 1, 338.23, 87666, 2199,
			 1, 544.79, 53398, 2220, 1, 448.74, 60413, 2238, 1, 418.78, 80386,
			 2257, 1, 553.69, 60271, 2275, 1, 502.81, 34881, 2289, 1, 1041.99,
			 93548, 2306, 1, 439.82, 432, 2324, 1, 593.65, 9063, 2340, 1,
			 700.38, 1692, 2354, 1, 607.25, 49157, 2369, 1, 911.21, 23549,
			 2389, 1, 718.86, 65112, 2403, 1, 408.75, 58501, 2420, 1, 386.36,
			 37248, 2435, 1, 1041.44, 53304, 2452, 1, 346.7, 68187, 2470,
			 1, 289.23, 72681, 2486, 1, 651.26, 78346, 2505, 1, 478.69, 37458,
			 2522, 1, 554.27, 64553, 2540, 1, 432.18, 16188, 2558, 1, 649.78,
			 23322, 2575, 1, 378.66, 76001, 2590, 1, 1230.94, 97083, 2605,
			 1, 849.02, 95414, 2618, 1, 337.08, 32760, 2636, 1, 599.3, 39805,
			 2656, 1, 617.63, 35420, 2679, 1, 320.63, 225, 2698, 1, 507.18,
			 46509, 2719, 1, 353.72, 73254, 2736, 1, 343.81, 11585, 2755,
			 1, 157.51, 98790, 2768, 1, 558.36, 10925, 2787, 1, 377.1, 67454,
			 2806, 1, 218.2, 66041, 2824, 1, 684.86, 51035, 2843, 1, 337.96,
			 58155, 2860, 1, 229.59, 76649, 2880, 1, 465.22, 71135, 2900,
			 1, 334.26, 41792, 2920, 1, 202.58, 21214, 2941, 1, 430.11, 81544,
			 2961, 1, 427.78, 99150, 2982, 1, 514.03, 74281, 2998, 1, 215.46,
			 75272, 3014, 1, 510.93, 52121, 3029, 1, 993.57, 13359, 3047,
			 1, 1262.85, 6080, 3064, 1, 722.45, 20335, 3082, 1, 564.01, 78336,
			 3100, 1, 359.43, 31532, 3120, 1, 469, 72035, 3137, 1, 322.92,
			 71832, 3152, 1, 1001.82, 77405, 3169, 1, 907.06, 67180, 3187,
			 1, 254.39, 14754, 3205, 1, 212.81, 90783, 3222, 1, 543.95, 17096,
			 3237, 1, 606.61, 89779, 3255, 1, 295.77, 61391, 3273, 1, 136.1,
			 2111, 3292, 1, 215.07, 79729, 3313, 1, 882.54, 47872, 3330,
			 1, 444.67, 85306, 3349, 1, 674.63, 15, 3368, 1, 475.92, 26052,
			 3383, 1, 681.73, 99612, 3394, 1, 2244.4, 18796, 3409, 1, 414.75,
			 70852, 3428, 1, 606.14, 54606, 3444, 1, 377.4, 53902, 3465,
			 1, 400.3, 89394, 3483, 1, 698.2))
})

test_that("<b>Table 1.</b> Selection Summary results match", {
	table <- results[["results"]][["selectionContainer"]][["collection"]][["selectionContainer_tableSelection"]][["data"]]
	jaspTools::expect_equal_tables(table,
		list(200, "7.5%", 200, 105247.58))
})

So maybe it is a good idea to fix this in jaspTools. Because I just copy and paste the code that jaspTools gives me into the unit tests, and that should probably be the ideal workflow, right? Anyway, I don't think that set.seed(1) actually does something because in the R functions we call set.seed(options$seed).

@JorisGoosen
Copy link
Contributor

You missed the seed in sampling?

This is why its better yo (re)use a component instead of having random integerfields in places :p
Although I guess this code is from before SetSeed being a component anyway

@koenderks
Copy link
Collaborator Author

koenderks commented Nov 22, 2024

You missed the seed in sampling?

What do you mean?

@JorisGoosen JorisGoosen merged commit 57d4d25 into jasp-stats:master Nov 26, 2024
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants