import {
  detectGte,
  detectOne
} from "./chunk-DJQTUDJM.js";
import {
  getRunPp
} from "./chunk-W55XSG6K.js";
import {
  require_tape
} from "./chunk-QWOE5YTB.js";
import "./chunk-74ZU4BT6.js";
import "./chunk-IW57W7EQ.js";
import "./chunk-ZTYNN6G5.js";
import "./chunk-DKVUOBIE.js";
import "./chunk-PRZWSBMA.js";
import "./chunk-LTOBEUM2.js";
import "./chunk-MKAF2BHB.js";
import "./chunk-WKNI3HRQ.js";
import "./chunk-VGYTAYFK.js";
import "./chunk-67DBIM6H.js";
import "./chunk-SA7APTJR.js";
import "./chunk-HJ6L54YS.js";
import "./chunk-LSEFWW72.js";
import "./chunk-SKREEF3H.js";
import "./chunk-HYOEWQ5P.js";
import "./chunk-HBW42TDT.js";
import "./chunk-G6O3URDN.js";
import "./chunk-FN5XPUPH.js";
import "./chunk-IIT367QZ.js";
import "./chunk-RZGEKL77.js";
import "./chunk-UI7OCM2A.js";
import "./chunk-YZK37YCC.js";
import "./chunk-7EMWHCVW.js";
import "./chunk-7IYJZZQI.js";
import "./chunk-M3J4MINX.js";
import "./chunk-PF4DSFDR.js";
import "./chunk-QH6W3NVF.js";
import "./chunk-NOEAT6CX.js";
import "./chunk-4UWS5Y3N.js";
import "./chunk-DD4R5P6W.js";
import "./chunk-JNITUVXP.js";
import "./chunk-KSGA62R2.js";
import "./chunk-LOZEKOES.js";
import "./chunk-TOU7EVFQ.js";
import "./chunk-OAWQ6LOO.js";
import "./chunk-TLT4YIG3.js";
import "./chunk-KYBIQBXE.js";
import "./chunk-I6Y4O3RR.js";
import "./chunk-OMR2DT66.js";
import "./chunk-DQC5FFGV.js";
import {
  __toESM
} from "./chunk-HFNDKYVF.js";

// plots/test/regression.integration.spec.js
var import_tape = __toESM(require_tape(), 1);
(0, import_tape.default)("\n", (test) => {
  test.comment("-***- plots/regression -***-");
  test.end();
});
(0, import_tape.default)('Linear: continuous outcome = "agedx", cat. independents = "sex" + "genetic_race"', (test) => {
  test.timeoutAfter(5e3);
  runpp({
    state: {
      plots: [
        {
          chartType: "regression",
          regressionType: "linear",
          outcome: {
            id: "agedx"
          },
          independent: [{ id: "sex" }, { id: "genetic_race" }]
        }
      ]
    },
    regression: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(regression) {
    const data = await getData(regression);
    const regDom = regression.Inner.dom;
    test.equal(
      regDom.inputs.selectAll("table").nodes().filter((t) => t.childNodes.length > 1).length,
      2,
      `Should render two tables for independent variables`
    );
    let table, tableLabel, results, testTerm;
    const sampleSizeDiv = regDom.results.selectAll('div[name^="Sample size"] span').nodes().filter((d) => d.innerText == data.sampleSize);
    test.ok(
      regDom.results.node().querySelector('div[name^="Sample size"]') && sampleSizeDiv,
      `Should render "Sample size: ${data.sampleSize}"`
    );
    tableLabel = "residuals table";
    table = regDom.results.selectAll('table[name^="sjpp-residuals-table"] tr').nodes();
    results = checkTableRow(table, 1, data.residuals.rows);
    test.equal(results, true, `Should render all residuals data in ${tableLabel}`);
    tableLabel = "coefficients table";
    table = regDom.results.selectAll('div[name^="Coefficients"] table tr').nodes();
    const coefHeader = structuredClone(data.coefficients.header);
    coefHeader.splice(3, 2, "95% CI");
    coefHeader[2] = coefHeader[2] + String.fromCharCode(160) + "\u24D8";
    results = checkTableRow(table, 0, coefHeader);
    test.equal(results, true, `Should render all coefficient headers in ${tableLabel}`);
    const linearHeaders = coefHeader.filter((d) => d === "Beta" + String.fromCharCode(160) + "\u24D8");
    test.equal(linearHeaders.length, 1, `Should render headers specific to linear regression`);
    const coefIntercept = [data.coefficients.intercept[0], data.coefficients.intercept[1]];
    coefIntercept.push(...getCoefData(data.coefficients.intercept.slice(2)));
    results = checkTableRow(table, 1, coefIntercept);
    test.equal(results, true, `Should render all intercept data in ${tableLabel}`);
    testTerm = "Sex";
    const checkValues1 = ["Sex\nREF\nFemale", "Male"];
    checkValues1.push(...getCoefData(data.coefficients.terms[tid2$id("sex", regression)].categories[1]));
    results = checkTableRow(table, 2, checkValues1);
    test.equal(results, true, `Should render all ${testTerm} data in ${tableLabel}`);
    testTerm = "African Ancestry";
    const checkValues2 = ["Genetically defined race\nREF\nEuropean Ancestry", testTerm];
    checkValues2.push(...getCoefData(data.coefficients.terms[tid2$id("genetic_race", regression)].categories[testTerm]));
    results = checkTableRow(table, 3, checkValues2);
    test.equal(results, true, `Should render all ${testTerm} data in ${tableLabel}`);
    testTerm = "Asian Ancestry";
    const checkValues3 = [testTerm];
    checkValues3.push(...getCoefData(data.coefficients.terms[tid2$id("genetic_race", regression)].categories[testTerm]));
    results = checkTableRow(table, 4, checkValues3);
    test.equal(results, true, `Should render all ${testTerm} data in ${tableLabel}`);
    tableLabel = "type3 table";
    table = regDom.results.selectAll('div[name^="Type III statistics"] table tr').nodes();
    results = checkTableRow(table, 0, data.type3.header);
    test.equal(results, true, `Should render all header data in ${tableLabel}`);
    results = checkTableRow(table, 1, data.type3.intercept);
    test.equal(results, true, `Should render all intercept data in ${tableLabel}`);
    testTerm = "Sex";
    const checkValues4 = [testTerm];
    data.type3.terms[tid2$id("sex", regression)].forEach((d) => checkValues4.push(d));
    results = checkTableRow(table, 2, checkValues4);
    test.equal(results, true, `Should render all ${testTerm} data in ${tableLabel}`);
    testTerm = "Genetically defined race";
    const checkValues5 = [testTerm];
    data.type3.terms[tid2$id("genetic_race", regression)].forEach((d) => checkValues5.push(d));
    results = checkTableRow(table, 3, checkValues5);
    test.equal(results, true, `Should render all ${testTerm} data in ${tableLabel}`);
    tableLabel = "other summary statistics table";
    table = regDom.results.selectAll('div[name^="Other summary statistics"] table tr').nodes();
    for (const [i, header] of data.other.header.entries()) {
      results = checkTableRow(table, i, [header, data.other.rows[i]]);
      test.equal(results, true, `Should render all ${header} data in ${tableLabel}`);
    }
    const elem = regDom.inputs.node();
    const violinDiv = await detectOne({ selector: ".sjpp-vp-violinDiv", elem });
    test.ok(violinDiv, `Should render violin plot for outcome variable`);
    if (test._ok) regression.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)('Linear: continuous outcome = "agedx", continuous independent = "aaclassic_5"', (test) => {
  test.timeoutAfter(3e3);
  runpp({
    state: {
      plots: [
        {
          chartType: "regression",
          regressionType: "linear",
          outcome: {
            id: "agedx"
          },
          independent: [{ id: "aaclassic_5", q: { mode: "continuous" } }]
        }
      ]
    },
    regression: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(regression) {
    const data = await getData(regression);
    const regDom = regression.Inner.dom;
    const violinDivs = await detectGte({ selector: ".sjpp-vp-violinDiv", elem: regDom.inputs.node(), count: 2 });
    test.equal(violinDivs.length, 2, `Should render violin plots for outcome and independent variables`);
    let tableLabel, table, results;
    tableLabel = "coefficients table";
    table = regDom.results.selectAll('div[name^="Coefficients"] table tr').nodes();
    test.equal(
      table[2].childNodes[1].innerText,
      "(continuous)",
      `Should correctly identify independent term as 'continuous' in ${tableLabel}`
    );
    const values2check = Array.from(table[2].childNodes).slice(3);
    results = checkOnlyRowValues(
      values2check,
      getCoefData(data.coefficients.terms[tid2$id("aaclassic_5", regression)].fields)
    );
    test.equal(results, true, `Should render all continous 'aaclassic_5' data in ${tableLabel}`);
    tableLabel = "type3 table";
    table = regDom.results.selectAll('div[name^="Type III statistics"] table tr').nodes();
    const values2check2 = Array.from(table[2].childNodes).slice(1);
    results = checkOnlyRowValues(values2check2, data.type3.terms[tid2$id("aaclassic_5", regression)]);
    test.equal(results, true, `Should render all continous 'aaclassic_5' data in ${tableLabel}`);
    if (test._ok) regression.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)('Linear: continuous outcome = "agedx", discrete independent = "aaclassic_5"', (test) => {
  test.timeoutAfter(5e3);
  runpp({
    state: {
      plots: [
        {
          chartType: "regression",
          regressionType: "linear",
          outcome: {
            id: "agedx"
          },
          independent: [{ id: "aaclassic_5", q: { mode: "discrete" } }]
        }
      ]
    },
    regression: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(regression) {
    const data = await getData(regression);
    const regDom = regression.Inner.dom;
    let tableLabel, table, results;
    tableLabel = "coefficients table";
    table = regDom.results.selectAll('div[name^="Coefficients"] table tr').nodes();
    const $id = tid2$id("aaclassic_5", regression);
    for (const [i, tr] of table.entries()) {
      if (i < 2 || i == table.length - 1) continue;
      if (i == 2) {
        const checkValues = getCoefData(data.coefficients.terms[$id].categories[tr.childNodes[1].innerText]);
        results = checkOnlyRowValues(Array.from(tr.childNodes).slice(1), checkValues);
        test.equal(results, true, `Should render all ${tr.childNodes[1].innerText} bin data in ${tableLabel}`);
      } else {
        const checkValues = getCoefData(data.coefficients.terms[$id].categories[tr.childNodes[0].innerText]);
        results = checkOnlyRowValues(Array.from(tr.childNodes), checkValues);
        test.equal(results, true, `Should render all ${tr.childNodes[0].innerText} bin data in ${tableLabel}`);
      }
    }
    if (test._ok) regression.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)('Linear: continuous outcome = "agedx", cubic spline independent = "aaclassic_5"', (test) => {
  test.timeoutAfter(9e3);
  runpp({
    state: {
      plots: [
        {
          chartType: "regression",
          regressionType: "linear",
          outcome: {
            id: "agedx",
            isAtomic: true
          },
          independent: [
            { id: "aaclassic_5", q: { mode: "spline", knots: [{ value: 2e3 }, { value: 12e3 }, { value: 24e3 }] } }
          ]
        }
      ]
    },
    regression: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(regression) {
    const data = await getData(regression);
    const regDom = regression.Inner.dom;
    const numOfKnots = regression.Inner.state.config.independent[0].q.knots.length;
    const $id = tid2$id("aaclassic_5", regression);
    const knotLines = regDom.inputs.selectAll(".sjpp-vp-violinDiv .sjpp-vp-line").nodes();
    test.equal(knotLines.length, numOfKnots, `Should render 3 lines over the independent variable violin plot`);
    let tableLabel, table, results;
    const splinePlot = regDom.results.select('div[name^="Cubic spline plots"] img').node();
    test.ok(splinePlot, `Should render a cubic spline plot`);
    tableLabel = "coefficients table";
    table = regDom.results.selectAll('div[name^="Coefficients"] table tr').nodes();
    test.equal(
      Object.keys(data.coefficients.terms[$id].categories).length,
      numOfKnots - 1,
      `Should pass data for ${numOfKnots - 1} spline functions`
    );
    for (const [i, tr] of table.entries()) {
      if (i < 2 || i == table.length - 1) continue;
      if (i == 2) {
        results = checkOnlyRowValues(
          Array.from(tr.childNodes).slice(1),
          getCoefData(data.coefficients.terms[$id].categories[tr.childNodes[1].innerText])
        );
        test.equal(results, true, `Should render all ${tr.childNodes[1].innerText} data in ${tableLabel}`);
      } else {
        results = checkOnlyRowValues(
          Array.from(tr.childNodes),
          getCoefData(data.coefficients.terms[$id].categories[tr.childNodes[0].innerText])
        );
        test.equal(results, true, `Should render all ${tr.childNodes[0].innerText} data in ${tableLabel}`);
      }
    }
    if (test._ok) regression.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)('Linear: continuous outcome = "agedx", independents = "sex" * "aaclassic_5"', (test) => {
  test.timeoutAfter(5e3);
  test.plan(2);
  runpp({
    state: {
      plots: [
        {
          chartType: "regression",
          regressionType: "linear",
          outcome: {
            id: "agedx"
          },
          independent: [
            { id: "sex", interactions: ["aaclassic_5"] },
            { id: "aaclassic_5", q: { mode: "continuous" }, interactions: ["sex"] }
          ]
        }
      ]
    },
    regression: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(regression) {
    const data = await getData(regression);
    const regDom = regression.Inner.dom;
    let tableLabel, table, results;
    tableLabel = "coefficients table";
    table = regDom.results.selectAll('div[name^="Coefficients"] table tr').nodes();
    const interactionRow = table[4];
    test.equal(
      interactionRow.childNodes[0].innerText,
      "Sex :\nCumulative Alkylating Agents (Cyclo ...",
      "Should render interaction term name"
    );
    const values2check = Array.from(interactionRow.childNodes).slice(3);
    const sex$id = tid2$id("sex", regression);
    const aaclassic_5$id = tid2$id("aaclassic_5", regression);
    const interaction = data.coefficients.interactions.find(
      (interaction2) => interaction2.term1 == sex$id && interaction2.term2 == aaclassic_5$id
    );
    if (!interaction) throw "interaction not found";
    interaction.categories[0].lst;
    results = checkOnlyRowValues(values2check, getCoefData(interaction.categories[0].lst));
    test.equal(results, true, `Should render all interaction data in ${tableLabel}`);
    if (test._ok) regression.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)('Linear: continuous outcome = "agedx", geneVariant independent = "TP53"', (test) => {
  test.timeoutAfter(5e3);
  runpp({
    state: {
      plots: [
        {
          chartType: "regression",
          regressionType: "linear",
          outcome: {
            id: "agedx"
          },
          independent: [{ term: { type: "geneVariant", gene: "TP53" }, q: { type: "predefined-groupset" } }]
        }
      ]
    },
    regression: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(regression) {
    const data = await getData(regression);
    const regDom = regression.Inner.dom;
    let tableLabel, table, results;
    tableLabel = "coefficients table";
    table = regDom.results.selectAll('div[name^="Coefficients"] table tr').nodes();
    const $id = tid2$id("TP53", regression);
    for (const [i, tr] of table.entries()) {
      if (i < 2 || i == table.length - 1) continue;
      if (i == 2) {
        const checkValues = getCoefData(data.coefficients.terms[$id].categories[tr.childNodes[1].innerText]);
        results = checkOnlyRowValues(Array.from(tr.childNodes).slice(1), checkValues);
        test.equal(results, true, `Should render all ${tr.childNodes[1].innerText} data in ${tableLabel}`);
      } else {
        const checkValues = getCoefData(data.coefficients.terms[$id].categories[tr.childNodes[0].innerText]);
        results = checkOnlyRowValues(Array.from(tr.childNodes), checkValues);
        test.equal(results, true, `Should render all ${tr.childNodes[0].innerText} data in ${tableLabel}`);
      }
    }
    if (test._ok) regression.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)('Logistic: continuous outcome = "hrtavg", continuous independent = "agedx"', (test) => {
  test.timeoutAfter(3e3);
  runpp({
    state: {
      plots: [
        {
          chartType: "regression",
          regressionType: "logistic",
          outcome: {
            id: "hrtavg",
            isAtomic: true
          },
          independent: [{ id: "agedx", q: { mode: "continuous" } }]
        }
      ]
    },
    regression: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(regression) {
    const data = await getData(regression);
    const regDom = regression.Inner.dom;
    let tableLabel, table, results, testTerm;
    const sampleSizeDiv = regDom.results.selectAll('div[name^="Sample size"] span').nodes().filter((d) => d.innerText == data.sampleSize);
    test.ok(
      regDom.results.node().querySelector('div[name^="Sample size"]') && sampleSizeDiv,
      `Should render "Sample size: ${data.sampleSize}"`
    );
    tableLabel = "Deviance residuals table";
    table = regDom.results.selectAll('table[name^="sjpp-residuals-table"] tr').nodes();
    results = checkTableRow(table, 1, data.residuals.rows);
    test.equal(results, true, `Should render all residuals data in ${tableLabel}`);
    tableLabel = "coefficients table";
    table = regDom.results.selectAll('div[name^="Coefficients"] table tr').nodes();
    const coefHeader = structuredClone(data.coefficients.header);
    coefHeader.splice(3, 2, "95% CI");
    coefHeader[2] = coefHeader[2] + String.fromCharCode(160) + "\u24D8";
    results = checkTableRow(table, 0, coefHeader);
    test.equal(results, true, `Should render all coefficient headers in ${tableLabel}`);
    const logHeaders = coefHeader.filter((d) => d === "Odds ratio" + String.fromCharCode(160) + "\u24D8");
    test.equal(logHeaders.length, 1, `Should render headers specific to logistic regression`);
    const coefIntercept = [data.coefficients.intercept[0], data.coefficients.intercept[1]];
    coefIntercept.push(...getCoefData(data.coefficients.intercept.slice(2)));
    results = checkTableRow(table, 1, coefIntercept);
    test.equal(results, true, `Should render all intercept data in ${tableLabel}`);
    testTerm = "Age (years) at Cancer Diagnosis";
    const checkValues1 = [testTerm, "(continuous)"];
    checkValues1.push(...getCoefData(data.coefficients.terms[tid2$id("agedx", regression)].fields));
    results = checkTableRow(table, 2, checkValues1);
    test.equal(results, true, `Should render all ${testTerm} data in ${tableLabel}`);
    tableLabel = "type3 table";
    table = regDom.results.selectAll('div[name^="Type III statistics"] table tr').nodes();
    results = checkTableRow(table, 0, data.type3.header);
    test.equal(results, true, `Should render all header data in ${tableLabel}`);
    results = checkTableRow(table, 1, data.type3.intercept);
    test.equal(results, true, `Should render all intercept data in ${tableLabel}`);
    const checkValues2 = [testTerm];
    data.type3.terms[tid2$id("agedx", regression)].forEach((d) => checkValues2.push(d));
    results = checkTableRow(table, 2, checkValues2);
    test.equal(results, true, `Should render all ${testTerm} data in ${tableLabel}`);
    tableLabel = "other summary statistics table";
    table = regDom.results.selectAll('div[name^="Other summary statistics"] table tr').nodes();
    for (const [i, header] of data.other.header.entries()) {
      results = checkTableRow(table, i, [header, data.other.rows[i]]);
      test.equal(results, true, `Should render all ${header} data in ${tableLabel}`);
    }
    if (test._ok) regression.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)('Logistic: categorical outcome = "diaggrp", continuous independent = "agedx"', (test) => {
  test.timeoutAfter(3e3);
  runpp({
    state: {
      plots: [
        {
          chartType: "regression",
          regressionType: "logistic",
          outcome: {
            id: "diaggrp",
            isAtomic: true
          },
          independent: [{ id: "agedx", q: { mode: "continuous" } }]
        }
      ]
    },
    regression: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(regression) {
    const data = await getData(regression);
    const regDom = regression.Inner.dom;
    let tableLabel, table, results, testTerm;
    const sampleSizeDiv = regDom.results.selectAll('div[name^="Sample size"] span').nodes().filter((d) => d.innerText == data.sampleSize);
    test.ok(
      regDom.results.node().querySelector('div[name^="Sample size"]') && sampleSizeDiv,
      `Should render "Sample size: ${data.sampleSize}"`
    );
    tableLabel = "Deviance residuals table";
    table = regDom.results.selectAll('table[name^="sjpp-residuals-table"] tr').nodes();
    results = checkTableRow(table, 1, data.residuals.rows);
    test.equal(results, true, `Should render all residuals data in ${tableLabel}`);
    tableLabel = "coefficients table";
    table = regDom.results.selectAll('div[name^="Coefficients"] table tr').nodes();
    const coefHeader = structuredClone(data.coefficients.header);
    coefHeader.splice(3, 2, "95% CI");
    coefHeader[2] = coefHeader[2] + String.fromCharCode(160) + "\u24D8";
    results = checkTableRow(table, 0, coefHeader);
    test.equal(results, true, `Should render all coefficient headers in ${tableLabel}`);
    const logHeaders = coefHeader.filter((d) => d === "Odds ratio" + String.fromCharCode(160) + "\u24D8");
    test.equal(logHeaders.length, 1, `Should render headers specific to logistic regression`);
    const coefIntercept = [data.coefficients.intercept[0], data.coefficients.intercept[1]];
    coefIntercept.push(...getCoefData(data.coefficients.intercept.slice(2)));
    results = checkTableRow(table, 1, coefIntercept);
    test.equal(results, true, `Should render all intercept data in ${tableLabel}`);
    testTerm = "Age (years) at Cancer Diagnosis";
    const checkValues1 = [testTerm, "(continuous)"];
    checkValues1.push(...getCoefData(data.coefficients.terms[tid2$id("agedx", regression)].fields));
    results = checkTableRow(table, 2, checkValues1);
    test.equal(results, true, `Should render all ${testTerm} data in ${tableLabel}`);
    tableLabel = "type3 table";
    table = regDom.results.selectAll('div[name^="Type III statistics"] table tr').nodes();
    results = checkTableRow(table, 0, data.type3.header);
    test.equal(results, true, `Should render all header data in ${tableLabel}`);
    results = checkTableRow(table, 1, data.type3.intercept);
    test.equal(results, true, `Should render all intercept data in ${tableLabel}`);
    const checkValues2 = [testTerm];
    data.type3.terms[tid2$id("agedx", regression)].forEach((d) => checkValues2.push(d));
    results = checkTableRow(table, 2, checkValues2);
    test.equal(results, true, `Should render all ${testTerm} data in ${tableLabel}`);
    tableLabel = "other summary statistics table";
    table = regDom.results.selectAll('div[name^="Other summary statistics"] table tr').nodes();
    for (const [i, header] of data.other.header.entries()) {
      results = checkTableRow(table, i, [header, data.other.rows[i]]);
      test.equal(results, true, `Should render all ${header} data in ${tableLabel}`);
    }
    if (test._ok) regression.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)('Cox: graded outcome = "Arrhythmias", continuous independent = "agedx"', (test) => {
  test.timeoutAfter(3e3);
  runpp({
    state: {
      plots: [
        {
          chartType: "regression",
          regressionType: "cox",
          outcome: {
            id: "Arrhythmias"
          },
          independent: [{ id: "agedx", q: { mode: "continuous" } }]
        }
      ]
    },
    regression: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(regression) {
    const data = await getData(regression);
    const regDom = regression.Inner.dom;
    let tableLabel, table, results, testTerm;
    const sampleSizeDiv = regDom.results.selectAll('div[name^="Sample size"] span').nodes().filter((d) => d.innerText == data.sampleSize);
    test.ok(
      regDom.results.node().querySelector('div[name^="Sample size"]') && sampleSizeDiv,
      `Should render "Sample size: ${data.sampleSize}"`
    );
    const numOfEventsDiv = regDom.results.selectAll('div[name^="Number of events"] span').nodes().filter((d) => d.innerText == data.eventCnt);
    test.ok(
      regDom.results.node().querySelector('div[name^="Number of events"]') && numOfEventsDiv,
      `Should render "Number of events: ${data.eventCnt}"`
    );
    test.ok(
      !regDom.results.select('table[name^="sjpp-residuals-table"]').node(),
      `Should not render residuals table in cox regression`
    );
    const $id = tid2$id("agedx", regression);
    tableLabel = "coefficients table";
    table = regDom.results.selectAll('div[name^="Coefficients"] table tr').nodes();
    const coefHeader = structuredClone(data.coefficients.header);
    coefHeader.splice(2, 2);
    coefHeader.splice(3, 2, "95% CI");
    coefHeader[2] = coefHeader[2] + String.fromCharCode(160) + "\u24D8";
    results = checkTableRow(table, 0, coefHeader);
    test.equal(results, true, `Should render all coefficient headers in ${tableLabel}`);
    const coxHeaders = coefHeader.filter((d) => d === "HR" + String.fromCharCode(160) + "\u24D8");
    test.equal(coxHeaders.length, 1, `Should render headers specific to cox regression in ${tableLabel}`);
    testTerm = "Age (years) at Cancer Diagnosis";
    const checkValues1 = [testTerm, "(continuous)"];
    data.coefficients.terms[$id].fields.splice(0, 2);
    checkValues1.push(...getCoefData(data.coefficients.terms[$id].fields));
    results = checkTableRow(table, 1, checkValues1);
    test.equal(results, true, `Should render all ${testTerm} data in ${tableLabel}`);
    tableLabel = "type3 table";
    table = regDom.results.selectAll('div[name^="Type III statistics"] table tr').nodes();
    results = checkTableRow(table, 0, data.type3.header);
    test.equal(results, true, `Should render all header data in ${tableLabel}`);
    const checkValues2 = [testTerm];
    data.type3.terms[$id].forEach((d) => checkValues2.push(d));
    results = checkTableRow(table, 1, checkValues2);
    test.equal(results, true, `Should render all ${testTerm} data in ${tableLabel}`);
    tableLabel = "Statistical tests table";
    table = regDom.results.selectAll('div[name^="Statistical tests"] table tr').nodes();
    results = checkTableRow(table, 0, data.tests.header);
    test.equal(results, true, `Should render all header data in ${tableLabel}`);
    for (const [i, row] of data.tests.rows.entries()) {
      results = checkTableRow(table, i + 1, row);
      test.equal(results, true, `Should render all ${row} data in ${tableLabel}`);
    }
    tableLabel = "other summary statistics table";
    table = regDom.results.selectAll('div[name^="Other summary statistics"] table tr').nodes();
    for (const [i, header] of data.other.header.entries()) {
      results = checkTableRow(table, i, [header, data.other.rows[i]]);
      test.equal(results, true, `Should render all ${header} data in ${tableLabel}`);
    }
    if (test._ok) regression.Inner.app.destroy();
    test.end();
  }
});
(0, import_tape.default)('Cox: survival outcome, continuous independent = "agedx"', (test) => {
  test.timeoutAfter(3e3);
  runpp({
    state: {
      plots: [
        {
          chartType: "regression",
          regressionType: "cox",
          outcome: {
            id: "os"
          },
          independent: [{ id: "agedx", q: { mode: "continuous" } }]
        }
      ]
    },
    regression: {
      callbacks: {
        "postRender.test": runTests
      }
    }
  });
  async function runTests(regression) {
    const data = await getData(regression);
    const regDom = regression.Inner.dom;
    const $id = tid2$id("agedx", regression);
    let tableLabel, table, results, testTerm;
    const sampleSizeDiv = regDom.results.selectAll('div[name^="Sample size"] span').nodes().filter((d) => d.innerText == data.sampleSize);
    test.ok(
      regDom.results.node().querySelector('div[name^="Sample size"]') && sampleSizeDiv,
      `Should render "Sample size: ${data.sampleSize}"`
    );
    const numOfEventsDiv = regDom.results.selectAll('div[name^="Number of events"] span').nodes().filter((d) => d.innerText == data.eventCnt);
    test.ok(
      regDom.results.node().querySelector('div[name^="Number of events"]') && numOfEventsDiv,
      `Should render "Number of events: ${data.eventCnt}"`
    );
    test.ok(
      !regDom.results.select('table[name^="sjpp-residuals-table"]').node(),
      `Should not render residuals table in cox regression`
    );
    tableLabel = "coefficients table";
    table = regDom.results.selectAll('div[name^="Coefficients"] table tr').nodes();
    const coefHeader = structuredClone(data.coefficients.header);
    coefHeader.splice(2, 2);
    coefHeader.splice(3, 2, "95% CI");
    coefHeader[2] = coefHeader[2] + String.fromCharCode(160) + "\u24D8";
    results = checkTableRow(table, 0, coefHeader);
    test.equal(results, true, `Should render all coefficient headers in ${tableLabel}`);
    const coxHeaders = coefHeader.filter((d) => d === "HR" + String.fromCharCode(160) + "\u24D8");
    test.equal(coxHeaders.length, 1, `Should render headers specific to cox regression in ${tableLabel}`);
    testTerm = "Age (years) at Cancer Diagnosis";
    const checkValues1 = [testTerm, "(continuous)"];
    data.coefficients.terms[$id].fields.splice(0, 2);
    checkValues1.push(...getCoefData(data.coefficients.terms[$id].fields));
    results = checkTableRow(table, 1, checkValues1);
    test.equal(results, true, `Should render all ${testTerm} data in ${tableLabel}`);
    tableLabel = "type3 table";
    table = regDom.results.selectAll('div[name^="Type III statistics"] table tr').nodes();
    results = checkTableRow(table, 0, data.type3.header);
    test.equal(results, true, `Should render all header data in ${tableLabel}`);
    const checkValues2 = [testTerm];
    data.type3.terms[$id].forEach((d) => checkValues2.push(d));
    results = checkTableRow(table, 1, checkValues2);
    test.equal(results, true, `Should render all ${testTerm} data in ${tableLabel}`);
    tableLabel = "Statistical tests table";
    table = regDom.results.selectAll('div[name^="Statistical tests"] table tr').nodes();
    results = checkTableRow(table, 0, data.tests.header);
    test.equal(results, true, `Should render all header data in ${tableLabel}`);
    for (const [i, row] of data.tests.rows.entries()) {
      results = checkTableRow(table, i + 1, row);
      test.equal(results, true, `Should render all ${row} data in ${tableLabel}`);
    }
    tableLabel = "other summary statistics table";
    table = regDom.results.selectAll('div[name^="Other summary statistics"] table tr').nodes();
    for (const [i, header] of data.other.header.entries()) {
      results = checkTableRow(table, i, [header, data.other.rows[i]]);
      test.equal(results, true, `Should render all ${header} data in ${tableLabel}`);
    }
    if (test._ok) regression.Inner.app.destroy();
    test.end();
  }
});
var runpp = getRunPp("mass", {
  state: {
    nav: {
      header_mode: "hide_search",
      activeTab: 1
    },
    vocab: {
      dslabel: "TermdbTest",
      genome: "hg38-test"
    }
  },
  debug: 1
});
async function getData(regression) {
  const data = await regression.Inner.app.Inner.api.vocabApi.getRegressionData(getDataRequestOpts(regression));
  function getDataRequestOpts(regression2) {
    const c = regression2.Inner.config;
    const opts = {
      regressionType: c.regressionType,
      outcome: c.outcome,
      independent: c.independent
    };
    opts.filter = regression2.Inner.inputs.parent.filter;
    return opts;
  }
  return data.resultLst[0].data;
}
function checkTableRow(table, idx, dataArray) {
  const checkArray = [];
  let issuesFound = 0;
  table[idx].childNodes.forEach((t) => {
    checkArray.push(t.innerText);
  });
  dataArray.forEach((d) => {
    if (!checkArray.some((t) => t == d)) {
      ++issuesFound;
    }
  });
  if (issuesFound === 0) return true;
  else return false;
}
function checkOnlyRowValues(valueNodes, dataArray) {
  const checkArray = [];
  let issuesFound = 0;
  valueNodes.forEach((t) => {
    checkArray.push(t.innerText);
  });
  dataArray.forEach((d) => {
    if (!checkArray.some((t) => t == d)) {
      ++issuesFound;
    }
  });
  if (issuesFound === 0) return true;
  else return false;
}
function getCoefData(in_data) {
  const out_data = structuredClone(in_data);
  out_data.splice(1, 2, `${out_data[1]} \u2013 ${out_data[2]}`);
  return out_data;
}
function tid2$id(tid, regression) {
  const t = regression.Inner.inputs.independent.inputLst.find((i) => {
    const id = i.term.id || i.term.term.id || i.term.term.name;
    return id == tid;
  });
  if (t) return t.term.$id;
  throw "unknown " + tid;
}
//# sourceMappingURL=regression.integration.spec-RP74JTAA.js.map
