Skip to content

Commit 75c5576

Browse files
committed
fix ppv.qmd app
1 parent f7c7088 commit 75c5576

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

blog/ppv.qmd

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,30 @@ viewof specificity = Inputs.range([50, 100], {
8787
grid = {
8888
const totalDots = 100;
8989
const diseaseCount = Math.round(totalDots * (prevalence / 100));
90-
90+
const noDiseaseCount = totalDots - diseaseCount;
91+
9192
const expectedTruePositives = Math.round(diseaseCount * (sensitivity / 100));
92-
const expectedFalsePositives = Math.round((totalDots - diseaseCount) * ((100 - specificity) / 100));
93-
93+
const expectedFalsePositives = Math.round(noDiseaseCount * ((100 - specificity) / 100));
94+
95+
// Create an array of indices for the population
96+
const indices = Array.from({ length: totalDots }, (_, index) => index);
97+
98+
// Shuffle the indices randomly
99+
const shuffledIndices = indices.sort(() => Math.random() - 0.5);
100+
101+
// Assign disease status based on the first `diseaseCount` indices
102+
const hasDisease = new Set(shuffledIndices.slice(0, diseaseCount));
103+
104+
// Separate true positives and false positives
105+
const truePositiveIndices = Array.from(hasDisease).slice(0, expectedTruePositives);
106+
const falsePositiveIndices = shuffledIndices
107+
.filter(index => !hasDisease.has(index))
108+
.slice(0, expectedFalsePositives);
109+
110+
// Create the dots array with proper properties
94111
const dots = Array(totalDots).fill(null).map((_, index) => ({
95-
hasDisease: index < diseaseCount,
96-
testPositive: index < (expectedTruePositives + expectedFalsePositives)
112+
hasDisease: hasDisease.has(index),
113+
testPositive: truePositiveIndices.includes(index) || falsePositiveIndices.includes(index),
97114
}));
98115
99116
// Calculate statistics

0 commit comments

Comments
 (0)