{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ch08-preview-title",
   "metadata": {},
   "source": [
    "# Preview\n",
    "\n",
    "- Use these questions before class to check your familiarity with the chapter glossary and core terms.\n",
    "- Sign in from the account menu before you start answering the questions.\n",
    "- Multiple submissions are allowed. The highest score is kept.\n",
    "\n",
    "Review the [Chapter 9 glossary](../0900-hypothesis-testing.ipynb) before class. These ten questions mix multiple-choice and true/false: seven recognize terms and three connect related ideas. No calculations or code tracing are required.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ch08-preview-quiz",
   "metadata": {},
   "source": [
    "<style>\n",
    ".ch09-preview-quiz { max-width: 900px; }\n",
    ".ch09-preview-question { border: 1px solid #d8dee4; border-radius: 6px; padding: 1rem; margin: 1rem 0; background: #fff; }\n",
    ".ch09-preview-question p { margin-top: 0; font-weight: 600; }\n",
    ".ch09-preview-question label { display: block; margin: 0.35rem 0; cursor: pointer; }\n",
    ".ch09-preview-question input { margin-right: 0.4rem; }\n",
    ".ch09-preview-actions { display: flex; gap: 0.75rem; align-items: center; margin: 1rem 0; flex-wrap: wrap; }\n",
    ".ch09-preview-actions button { border: 1px solid #176de8; border-radius: 6px; background: #176de8; color: white; padding: 0.55rem 0.9rem; cursor: pointer; font-weight: 600; }\n",
    ".ch09-preview-actions button.secondary { background: white; color: #176de8; }\n",
    ".ch09-preview-actions.is-locked { opacity: 0.55; }\n",
    ".ch09-preview-actions button:disabled { cursor: not-allowed; opacity: 0.65; }\n",
    ".ch09-preview-result { font-weight: 600; }\n",
    ".ch09-preview-feedback { margin-top: 0.65rem; font-weight: 600; }\n",
    ".ch09-preview-feedback.correct { color: #1a7f37; }\n",
    ".ch09-preview-feedback.incorrect { color: #cf222e; }\n",
    "</style>\n",
    "\n",
    "<div class='ch09-preview-quiz' id='ch09-preview-quiz' data-question-set-version='dsm-ch09-preview-2026-10-19-v2'>\n",
    "  <p>Earlier submissions and best scores are retained. If you already completed this Preview, you do not need to repeat it; you may retry the revised questions.</p>\n",
    "  <div id='ch09-preview-questions'></div>\n",
    "  <div class='ch09-preview-actions'>\n",
    "    <button type='button' id='ch09-preview-submit' disabled>Submit</button>\n",
    "    <button type='button' class='secondary' id='ch09-preview-reset'>Reset</button>\n",
    "    <span class='ch09-preview-result' id='ch09-preview-result' aria-live='polite'></span>\n",
    "  </div>\n",
    "</div>\n",
    "\n",
    "<script>\n",
    "(function () {\n",
    "  var quizId = 'ch09-preview';\n",
    "  var questionSetVersion = 'dsm-ch09-preview-2026-10-19-v2';\n",
    "  var answersUnlocked = false;\n",
    "  var attemptState = null;\n",
    "  var stateQueue = Promise.resolve();\n",
    "\n",
    "  function stateRequest(action, extra) {\n",
    "    return fetch('/api/v1/preview-options.php', {\n",
    "      method: 'POST', credentials: 'same-origin',\n",
    "      headers: { 'Content-Type': 'application/json' },\n",
    "      body: JSON.stringify(Object.assign({\n",
    "        assignment_id: quizId, version: questionSetVersion, action: action,\n",
    "        page: window.location.pathname.replace(/^\\/+/, '').replace(/\\.html$/, ''),\n",
    "        questions: authoredQuestions, legacy_questions: legacyQuestions, legacy_version: legacyVersion, token: attemptState && attemptState.token,\n",
    "        revision: attemptState && attemptState.revision\n",
    "      }, extra || {}))\n",
    "    }).then(function (response) {\n",
    "      return response.json().then(function (payload) {\n",
    "        if (!response.ok || !payload.ok) throw new Error(payload.error || 'Could not save Preview state.');\n",
    "        attemptState = payload.state;\n",
    "        return payload;\n",
    "      });\n",
    "    });\n",
    "  }\n",
    "\n",
    "  function draftAnswers(quiz) {\n",
    "    var answers = {};\n",
    "    questions.forEach(function (question) {\n",
    "      var input = quiz.querySelector('input[name=' + question.id + ']:checked');\n",
    "      if (input) answers[question.id] = input.value;\n",
    "    });\n",
    "    return answers;\n",
    "  }\n",
    "\n",
    "  function saveAnswers(quiz) {\n",
    "    var answers = draftAnswers(quiz);\n",
    "    stateQueue = stateQueue.catch(function () {}).then(function () {\n",
    "      return stateRequest('save', { answers: answers });\n",
    "    });\n",
    "    return stateQueue;\n",
    "  }\n",
    "  var questions = [\n",
    "  {\n",
    "    \"format\": \"true_false\",\n",
    "    \"prompt\": \"True or false: Failing to reject a null hypothesis proves that the null hypothesis is true.\",\n",
    "    \"concepts\": [\n",
    "      \"Fail to reject\",\n",
    "      \"Null hypothesis\"\n",
    "    ],\n",
    "    \"explanation\": \"False. Failing to reject means the data do not provide enough evidence against the null model. It does not prove the model true; limited data or small effects can leave uncertainty.\",\n",
    "    \"retry_hint\": \"Revisit the difference between insufficient evidence and proof of a claim.\",\n",
    "    \"id\": \"q1\",\n",
    "    \"cognitive_level\": \"recognition\",\n",
    "    \"reading\": \"../0903-decisions-uncertainty.html\",\n",
    "    \"choices\": {\n",
    "      \"A\": \"True\",\n",
    "      \"B\": \"False\"\n",
    "    }\n",
    "  },\n",
    "  {\n",
    "    \"format\": \"multiple_choice\",\n",
    "    \"prompt\": \"A retailer starts with the claim that a checkout redesign has no effect. What is this baseline claim called?\",\n",
    "    \"concepts\": [\n",
    "      \"Null hypothesis\",\n",
    "      \"Alternative hypothesis\"\n",
    "    ],\n",
    "    \"explanation\": \"The null hypothesis is the baseline claim assessed against the data. An alternative describes the competing possibility; a statistic measures evidence, and a significance level sets a decision cutoff.\",\n",
    "    \"retry_hint\": \"Compare the glossary entries for a starting claim and a competing claim.\",\n",
    "    \"id\": \"q2\",\n",
    "    \"cognitive_level\": \"recognition\",\n",
    "    \"reading\": \"../0903-decisions-uncertainty.html\",\n",
    "    \"choices\": {\n",
    "      \"A\": \"Alternative hypothesis\",\n",
    "      \"B\": \"Test statistic\",\n",
    "      \"C\": \"Null hypothesis\",\n",
    "      \"D\": \"Significance level\"\n",
    "    }\n",
    "  },\n",
    "  {\n",
    "    \"format\": \"multiple_choice\",\n",
    "    \"prompt\": \"An analyst repeatedly generates possible results assuming the baseline model is true. The resulting distribution of the test statistic is the:\",\n",
    "    \"concepts\": [\n",
    "      \"Null distribution\",\n",
    "      \"Simulation\"\n",
    "    ],\n",
    "    \"explanation\": \"A null distribution describes how the statistic varies when the null model holds. The observed statistic is one value from the actual data; it is compared with that distribution.\",\n",
    "    \"retry_hint\": \"Distinguish one measured summary from a distribution generated under an assumption.\",\n",
    "    \"id\": \"q3\",\n",
    "    \"cognitive_level\": \"recognition\",\n",
    "    \"reading\": \"../0903-decisions-uncertainty.html\",\n",
    "    \"choices\": {\n",
    "      \"A\": \"Observed statistic\",\n",
    "      \"B\": \"Alternative hypothesis\",\n",
    "      \"C\": \"Significance level\",\n",
    "      \"D\": \"Null distribution\"\n",
    "    }\n",
    "  },\n",
    "  {\n",
    "    \"format\": \"true_false\",\n",
    "    \"prompt\": \"True or false: A test statistic is a numerical summary used to measure evidence in a hypothesis test.\",\n",
    "    \"concepts\": [\n",
    "      \"Test statistic\",\n",
    "      \"Observed statistic\"\n",
    "    ],\n",
    "    \"explanation\": \"True. A test statistic turns the relevant feature of the data into a number. Computing that statistic from the real data gives the observed statistic; simulations provide comparison values.\",\n",
    "    \"retry_hint\": \"Review what a statistic summarizes and how an observed statistic is obtained.\",\n",
    "    \"id\": \"q4\",\n",
    "    \"cognitive_level\": \"recognition\",\n",
    "    \"reading\": \"../0903-decisions-uncertainty.html\",\n",
    "    \"choices\": {\n",
    "      \"A\": \"True\",\n",
    "      \"B\": \"False\"\n",
    "    }\n",
    "  },\n",
    "  {\n",
    "    \"format\": \"multiple_choice\",\n",
    "    \"prompt\": \"Which term describes the probability, assuming the null model, of a result at least as extreme as the observed one?\",\n",
    "    \"concepts\": [\n",
    "      \"P-value\",\n",
    "      \"Null hypothesis\"\n",
    "    ],\n",
    "    \"explanation\": \"The p-value concerns possible data under an assumed null model. It is not the probability that the null hypothesis itself is true. The significance level is a chosen comparison cutoff.\",\n",
    "    \"retry_hint\": \"Pay attention to what is assumed and what outcome the probability describes.\",\n",
    "    \"id\": \"q5\",\n",
    "    \"cognitive_level\": \"recognition\",\n",
    "    \"reading\": \"../0903-decisions-uncertainty.html\",\n",
    "    \"choices\": {\n",
    "      \"A\": \"Significance level\",\n",
    "      \"B\": \"Effect size\",\n",
    "      \"C\": \"Probability that the null hypothesis is true\",\n",
    "      \"D\": \"P-value\"\n",
    "    }\n",
    "  },\n",
    "  {\n",
    "    \"format\": \"multiple_choice\",\n",
    "    \"prompt\": \"Before seeing results, a team chooses the p-value cutoff it will use for its decision. What is that cutoff called?\",\n",
    "    \"concepts\": [\n",
    "      \"Significance level\",\n",
    "      \"Decision rule\"\n",
    "    ],\n",
    "    \"explanation\": \"The significance level is the cutoff used in a decision rule. The observed statistic and p-value come from assessing the data; an error type describes a possible wrong decision.\",\n",
    "    \"retry_hint\": \"Separate a rule chosen in advance from a quantity calculated from observations.\",\n",
    "    \"id\": \"q6\",\n",
    "    \"cognitive_level\": \"recognition\",\n",
    "    \"reading\": \"../0903-decisions-uncertainty.html\",\n",
    "    \"choices\": {\n",
    "      \"A\": \"Observed statistic\",\n",
    "      \"B\": \"Significance level\",\n",
    "      \"C\": \"Null distribution\",\n",
    "      \"D\": \"Type II error\"\n",
    "    }\n",
    "  },\n",
    "  {\n",
    "    \"format\": \"multiple_choice\",\n",
    "    \"prompt\": \"Which error means rejecting a null hypothesis that is actually true?\",\n",
    "    \"concepts\": [\n",
    "      \"Type I error\",\n",
    "      \"Type II error\"\n",
    "    ],\n",
    "    \"explanation\": \"A Type I error is a false alarm: rejecting a true null hypothesis. A Type II error goes the other way, failing to reject a false null hypothesis.\",\n",
    "    \"retry_hint\": \"Match each error to the true state of the baseline claim and the decision made.\",\n",
    "    \"id\": \"q7\",\n",
    "    \"cognitive_level\": \"recognition\",\n",
    "    \"reading\": \"../0903-decisions-uncertainty.html\",\n",
    "    \"choices\": {\n",
    "      \"A\": \"Type II error\",\n",
    "      \"B\": \"Practical significance\",\n",
    "      \"C\": \"Type I error\",\n",
    "      \"D\": \"Fail to reject\"\n",
    "    }\n",
    "  },\n",
    "  {\n",
    "    \"format\": \"true_false\",\n",
    "    \"prompt\": \"True or false: Simulated statistics under a null model provide a reference for judging the statistic observed in real data.\",\n",
    "    \"concepts\": [\n",
    "      \"Simulation\",\n",
    "      \"Null distribution\",\n",
    "      \"Observed statistic\"\n",
    "    ],\n",
    "    \"explanation\": \"True. Simulation supplies a null distribution: reference values expected under the baseline model. Comparing the observed statistic with those values connects the model to the evidence.\",\n",
    "    \"retry_hint\": \"Connect the glossary meanings of simulation, null distribution, and observed statistic.\",\n",
    "    \"id\": \"q8\",\n",
    "    \"cognitive_level\": \"connection\",\n",
    "    \"reading\": \"../0901-assess-model-1.html\",\n",
    "    \"choices\": {\n",
    "      \"A\": \"True\",\n",
    "      \"B\": \"False\"\n",
    "    }\n",
    "  },\n",
    "  {\n",
    "    \"format\": \"multiple_choice\",\n",
    "    \"prompt\": \"A tiny improvement is statistically significant but saves almost no money. Which distinction helps the manager interpret it?\",\n",
    "    \"concepts\": [\n",
    "      \"Statistical significance\",\n",
    "      \"Practical significance\"\n",
    "    ],\n",
    "    \"explanation\": \"Statistical significance concerns evidence against a null model. Practical significance concerns the real-world importance of the effect. A result can provide evidence of a difference while offering little business value.\",\n",
    "    \"retry_hint\": \"Compare evidence that an effect exists with the size or usefulness of the effect.\",\n",
    "    \"id\": \"q9\",\n",
    "    \"cognitive_level\": \"connection\",\n",
    "    \"reading\": \"../0903-decisions-uncertainty.html\",\n",
    "    \"choices\": {\n",
    "      \"A\": \"One-sided versus two-sided tests\",\n",
    "      \"B\": \"Null hypothesis versus test statistic\",\n",
    "      \"C\": \"Type I versus Type II error\",\n",
    "      \"D\": \"Statistical significance versus practical significance\"\n",
    "    }\n",
    "  },\n",
    "  {\n",
    "    \"format\": \"multiple_choice\",\n",
    "    \"prompt\": \"A team asks whether a new process changes delays in either direction, rather than only reducing them. Which test direction matches that question?\",\n",
    "    \"concepts\": [\n",
    "      \"Two-sided test\",\n",
    "      \"One-sided test\",\n",
    "      \"Alternative hypothesis\"\n",
    "    ],\n",
    "    \"explanation\": \"A two-sided alternative allows changes in either direction. A one-sided alternative focuses on a specified direction. The research question should determine this distinction before examining results.\",\n",
    "    \"retry_hint\": \"Use the glossary distinction between one direction and either direction.\",\n",
    "    \"id\": \"q10\",\n",
    "    \"cognitive_level\": \"connection\",\n",
    "    \"reading\": \"../0903-decisions-uncertainty.html\",\n",
    "    \"choices\": {\n",
    "      \"A\": \"Two-sided test\",\n",
    "      \"B\": \"One-sided test\",\n",
    "      \"C\": \"A test that proves the null\",\n",
    "      \"D\": \"A test with no alternative hypothesis\"\n",
    "    }\n",
    "  }\n",
    "];\n",
    "\n",
    "  var legacyQuestions = [\n",
    "  {\n",
    "    \"id\": \"q1\",\n",
    "    \"prompt\": \"Which term matches this explanation? A method for comparing observed data with a stated chance model.\",\n",
    "    \"choices\": {\n",
    "      \"A\": \"Null hypothesis\",\n",
    "      \"B\": \"Hypothesis test\",\n",
    "      \"C\": \"Alternative hypothesis\",\n",
    "      \"D\": \"Test statistic\"\n",
    "    },\n",
    "    \"format\": \"multiple_choice\",\n",
    "    \"cognitive_level\": \"recognition\",\n",
    "    \"concepts\": [\n",
    "      \"Hypothesis test\"\n",
    "    ],\n",
    "    \"explanation\": \"Hypothesis test: A method for comparing observed data with a stated chance model. This is the glossary meaning used by this original question.\",\n",
    "    \"retry_hint\": \"Compare the related terms in the assigned chapter glossary; identify what the description refers to.\",\n",
    "    \"reading\": \"../0900-hypothesis-testing.html\"\n",
    "  },\n",
    "  {\n",
    "    \"id\": \"q2\",\n",
    "    \"prompt\": \"Which term matches this explanation? The competing claim suggested by the research question.\",\n",
    "    \"choices\": {\n",
    "      \"A\": \"Test statistic\",\n",
    "      \"B\": \"Observed statistic\",\n",
    "      \"C\": \"Alternative hypothesis\",\n",
    "      \"D\": \"Null distribution\"\n",
    "    },\n",
    "    \"format\": \"multiple_choice\",\n",
    "    \"cognitive_level\": \"recognition\",\n",
    "    \"concepts\": [\n",
    "      \"Alternative hypothesis\"\n",
    "    ],\n",
    "    \"explanation\": \"Alternative hypothesis: The competing claim suggested by the research question. This is the glossary meaning used by this original question.\",\n",
    "    \"retry_hint\": \"Compare the related terms in the assigned chapter glossary; identify what the description refers to.\",\n",
    "    \"reading\": \"../0900-hypothesis-testing.html\"\n",
    "  },\n",
    "  {\n",
    "    \"id\": \"q3\",\n",
    "    \"prompt\": \"Which term matches this explanation? The test statistic computed from the actual data.\",\n",
    "    \"choices\": {\n",
    "      \"A\": \"Hypothesis test\",\n",
    "      \"B\": \"Null hypothesis\",\n",
    "      \"C\": \"Alternative hypothesis\",\n",
    "      \"D\": \"Observed statistic\"\n",
    "    },\n",
    "    \"format\": \"multiple_choice\",\n",
    "    \"cognitive_level\": \"recognition\",\n",
    "    \"concepts\": [\n",
    "      \"Observed statistic\"\n",
    "    ],\n",
    "    \"explanation\": \"Observed statistic: The test statistic computed from the actual data. This is the glossary meaning used by this original question.\",\n",
    "    \"retry_hint\": \"Compare the related terms in the assigned chapter glossary; identify what the description refers to.\",\n",
    "    \"reading\": \"../0900-hypothesis-testing.html\"\n",
    "  },\n",
    "  {\n",
    "    \"id\": \"q4\",\n",
    "    \"prompt\": \"Which term matches this explanation? A cutoff used to decide whether a p-value is small enough to reject the null.\",\n",
    "    \"choices\": {\n",
    "      \"A\": \"Significance level\",\n",
    "      \"B\": \"Null hypothesis\",\n",
    "      \"C\": \"Alternative hypothesis\",\n",
    "      \"D\": \"Hypothesis test\"\n",
    "    },\n",
    "    \"format\": \"multiple_choice\",\n",
    "    \"cognitive_level\": \"recognition\",\n",
    "    \"concepts\": [\n",
    "      \"Significance level\"\n",
    "    ],\n",
    "    \"explanation\": \"Significance level: A cutoff used to decide whether a p-value is small enough to reject the null. This is the glossary meaning used by this original question.\",\n",
    "    \"retry_hint\": \"Compare the related terms in the assigned chapter glossary; identify what the description refers to.\",\n",
    "    \"reading\": \"../0900-hypothesis-testing.html\"\n",
    "  },\n",
    "  {\n",
    "    \"id\": \"q5\",\n",
    "    \"prompt\": \"Which term matches this explanation? Decide that the data do not provide enough evidence against the null model.\",\n",
    "    \"choices\": {\n",
    "      \"A\": \"Alternative hypothesis\",\n",
    "      \"B\": \"Hypothesis test\",\n",
    "      \"C\": \"Null hypothesis\",\n",
    "      \"D\": \"Fail to reject\"\n",
    "    },\n",
    "    \"format\": \"multiple_choice\",\n",
    "    \"cognitive_level\": \"recognition\",\n",
    "    \"concepts\": [\n",
    "      \"Fail to reject\"\n",
    "    ],\n",
    "    \"explanation\": \"Fail to reject: Decide that the data do not provide enough evidence against the null model. This is the glossary meaning used by this original question.\",\n",
    "    \"retry_hint\": \"Compare the related terms in the assigned chapter glossary; identify what the description refers to.\",\n",
    "    \"reading\": \"../0900-hypothesis-testing.html\"\n",
    "  },\n",
    "  {\n",
    "    \"id\": \"q6\",\n",
    "    \"prompt\": \"Which term matches this explanation? A test where the alternative allows differences in either direction.\",\n",
    "    \"choices\": {\n",
    "      \"A\": \"Hypothesis test\",\n",
    "      \"B\": \"Two-sided test\",\n",
    "      \"C\": \"Null hypothesis\",\n",
    "      \"D\": \"Alternative hypothesis\"\n",
    "    },\n",
    "    \"format\": \"multiple_choice\",\n",
    "    \"cognitive_level\": \"recognition\",\n",
    "    \"concepts\": [\n",
    "      \"Two-sided test\"\n",
    "    ],\n",
    "    \"explanation\": \"Two-sided test: A test where the alternative allows differences in either direction. This is the glossary meaning used by this original question.\",\n",
    "    \"retry_hint\": \"Compare the related terms in the assigned chapter glossary; identify what the description refers to.\",\n",
    "    \"reading\": \"../0900-hypothesis-testing.html\"\n",
    "  },\n",
    "  {\n",
    "    \"id\": \"q7\",\n",
    "    \"prompt\": \"Which term matches this explanation? Assigning units to groups by chance.\",\n",
    "    \"choices\": {\n",
    "      \"A\": \"Hypothesis test\",\n",
    "      \"B\": \"Null hypothesis\",\n",
    "      \"C\": \"Random assignment\",\n",
    "      \"D\": \"Alternative hypothesis\"\n",
    "    },\n",
    "    \"format\": \"multiple_choice\",\n",
    "    \"cognitive_level\": \"recognition\",\n",
    "    \"concepts\": [\n",
    "      \"Random assignment\"\n",
    "    ],\n",
    "    \"explanation\": \"Random assignment: Assigning units to groups by chance. This is the glossary meaning used by this original question.\",\n",
    "    \"retry_hint\": \"Compare the related terms in the assigned chapter glossary; identify what the description refers to.\",\n",
    "    \"reading\": \"../0900-hypothesis-testing.html\"\n",
    "  },\n",
    "  {\n",
    "    \"id\": \"q8\",\n",
    "    \"prompt\": \"Which term matches this explanation? The real-world size or importance of an effect.\",\n",
    "    \"choices\": {\n",
    "      \"A\": \"Practical significance\",\n",
    "      \"B\": \"Null hypothesis\",\n",
    "      \"C\": \"Alternative hypothesis\",\n",
    "      \"D\": \"Hypothesis test\"\n",
    "    },\n",
    "    \"format\": \"multiple_choice\",\n",
    "    \"cognitive_level\": \"recognition\",\n",
    "    \"concepts\": [\n",
    "      \"Practical significance\"\n",
    "    ],\n",
    "    \"explanation\": \"Practical significance: The real-world size or importance of an effect. This is the glossary meaning used by this original question.\",\n",
    "    \"retry_hint\": \"Compare the related terms in the assigned chapter glossary; identify what the description refers to.\",\n",
    "    \"reading\": \"../0900-hypothesis-testing.html\"\n",
    "  },\n",
    "  {\n",
    "    \"id\": \"q9\",\n",
    "    \"prompt\": \"Which term matches this explanation? Failing to reject a false null hypothesis.\",\n",
    "    \"choices\": {\n",
    "      \"A\": \"Alternative hypothesis\",\n",
    "      \"B\": \"Hypothesis test\",\n",
    "      \"C\": \"Null hypothesis\",\n",
    "      \"D\": \"Type II error\"\n",
    "    },\n",
    "    \"format\": \"multiple_choice\",\n",
    "    \"cognitive_level\": \"recognition\",\n",
    "    \"concepts\": [\n",
    "      \"Type II error\"\n",
    "    ],\n",
    "    \"explanation\": \"Type II error: Failing to reject a false null hypothesis. This is the glossary meaning used by this original question.\",\n",
    "    \"retry_hint\": \"Compare the related terms in the assigned chapter glossary; identify what the description refers to.\",\n",
    "    \"reading\": \"../0900-hypothesis-testing.html\"\n",
    "  },\n",
    "  {\n",
    "    \"id\": \"q10\",\n",
    "    \"prompt\": \"Which term matches this explanation? A rule for converting statistical evidence into an action.\",\n",
    "    \"choices\": {\n",
    "      \"A\": \"Decision rule\",\n",
    "      \"B\": \"Hypothesis test\",\n",
    "      \"C\": \"Null hypothesis\",\n",
    "      \"D\": \"Alternative hypothesis\"\n",
    "    },\n",
    "    \"format\": \"multiple_choice\",\n",
    "    \"cognitive_level\": \"recognition\",\n",
    "    \"concepts\": [\n",
    "      \"Decision rule\"\n",
    "    ],\n",
    "    \"explanation\": \"Decision rule: A rule for converting statistical evidence into an action. This is the glossary meaning used by this original question.\",\n",
    "    \"retry_hint\": \"Compare the related terms in the assigned chapter glossary; identify what the description refers to.\",\n",
    "    \"reading\": \"../0900-hypothesis-testing.html\"\n",
    "  }\n",
    "];\n",
    "  var legacyVersion = 'dsm-ch09-preview-before-2026-10-19';\n",
    "  var authoredQuestions = JSON.parse(JSON.stringify(questions));\n",
    "\n",
    "  function text(value) {\n",
    "    return document.createTextNode(value);\n",
    "  }\n",
    "\n",
    "  function getParams() {\n",
    "    var params = new URLSearchParams(window.location.search);\n",
    "    return {\n",
    "      canvas_course_id: params.get('canvas_course_id') || params.get('course_id') || '',\n",
    "      canvas_assignment_id: params.get('canvas_assignment_id') || params.get('assignment_id') || '',\n",
    "      canvas_user_id: params.get('canvas_user_id') || params.get('user_id') || '',\n",
    "      student_identifier: params.get('student_identifier') || params.get('student_id') || params.get('email') || ''\n",
    "    };\n",
    "  }\n",
    "\n",
    "  function loadSessionIdentity(identity, actions, submit, result) {\n",
    "    submit.disabled = true;\n",
    "    actions.classList.add('is-locked');\n",
    "    result.textContent = 'Sign in from the account menu to submit this assignment.';\n",
    "\n",
    "    return fetch('/api/v1/session.php', { credentials: 'same-origin' })\n",
    "      .then(function (response) { return response.ok ? response.json() : null; })\n",
    "      .then(function (payload) {\n",
    "        if (!payload || !payload.authenticated || !payload.identity) return identity;\n",
    "        identity.canvas_user_id = payload.identity.canvas_user_id || identity.canvas_user_id || '';\n",
    "        identity.student_identifier = payload.identity.student_identifier || identity.student_identifier || '';\n",
    "        submit.disabled = false;\n",
    "        actions.classList.remove('is-locked');\n",
    "        result.textContent = payload.identity.display_name ? 'Signed in as ' + payload.identity.display_name + '.' : 'Signed in.';\n",
    "        return identity;\n",
    "      })\n",
    "      .catch(function () { return identity; });\n",
    "  }\n",
    "\n",
    "  function renderQuestions(container) {\n",
    "    container.textContent = '';\n",
    "    questions.forEach(function (question, index) {\n",
    "      var card = document.createElement('div');\n",
    "      card.className = 'ch09-preview-question';\n",
    "      card.dataset.question = question.id;\n",
    "\n",
    "      var prompt = document.createElement('p');\n",
    "      prompt.appendChild(text((index + 1) + '. ' + question.prompt));\n",
    "      card.appendChild(prompt);\n",
    "\n",
    "      (attemptState ? attemptState.orders[question.id] : Object.keys(question.choices)).forEach(function (letter, position) {\n",
    "        var label = document.createElement('label');\n",
    "        var input = document.createElement('input');\n",
    "        input.type = 'radio';\n",
    "        input.name = question.id;\n",
    "        input.value = letter;\n",
    "        input.checked = !!(attemptState && attemptState.answers[question.id] === letter);\n",
    "        label.appendChild(input);\n",
    "        label.appendChild(text(String.fromCharCode(65 + position) + '. ' + question.choices[letter]));\n",
    "        card.appendChild(label);\n",
    "      });\n",
    "\n",
    "      var feedback = document.createElement('div');\n",
    "      feedback.className = 'ch09-preview-feedback';\n",
    "      feedback.setAttribute('aria-live', 'polite');\n",
    "      card.appendChild(feedback);\n",
    "      container.appendChild(card);\n",
    "    });\n",
    "  }\n",
    "\n",
    "  function collectAnswers(quiz) {\n",
    "    var answers = {};\n",
    "    questions.forEach(function (question) {\n",
    "      var selected = quiz.querySelector('input[name=' + question.id + ']:checked');\n",
    "      answers[question.id] = selected ? selected.value : '';\n",
    "    });\n",
    "    // Press stores this marker with the submitted answers; it is not a scored question.\n",
    "    answers.__question_set = attemptState ? attemptState.version : questionSetVersion;\n",
    "    if (attemptState) answers.preview_attempt = attemptState.token;\n",
    "    return answers;\n",
    "  }\n",
    "\n",
    "  function loadFeedbackPolicy() {\n",
    "    // Use the existing server release setting; a network failure must not unlock answers.\n",
    "    return fetch('/api/v1/assignment-settings.php?assignment_id=' + encodeURIComponent(quizId), {\n",
    "      credentials: 'same-origin'\n",
    "    })\n",
    "      .then(function (response) { return response.ok ? response.json() : null; })\n",
    "      .then(function (payload) {\n",
    "        answersUnlocked = !!(payload && payload.ok && payload.answers_unlocked === true);\n",
    "      })\n",
    "      .catch(function () { answersUnlocked = false; });\n",
    "  }\n",
    "\n",
    "  function applyFeedback(quiz, feedback) {\n",
    "    questions.forEach(function (question) {\n",
    "      var card = quiz.querySelector('[data-question=' + question.id + ']');\n",
    "      var message = card.querySelector('.ch09-preview-feedback');\n",
    "      var item = feedback[question.id];\n",
    "      message.className = 'ch09-preview-feedback';\n",
    "      var status = (!item || !item.submitted) ? 'No answer submitted.' :\n",
    "        (item.correct ? 'Correct.' : 'Review and try again.');\n",
    "      var guidance = answersUnlocked ? question.explanation : question.retry_hint;\n",
    "      message.textContent = status + ' ' + guidance;\n",
    "      var reading = document.createElement('a');\n",
    "      reading.href = question.reading || \"../0900-hypothesis-testing.html\";\n",
    "      reading.appendChild(text('Review this concept'));\n",
    "      message.appendChild(text(' '));\n",
    "      message.appendChild(reading);\n",
    "      message.classList.add(item && item.correct ? 'correct' : 'incorrect');\n",
    "    });\n",
    "  }\n",
    "\n",
    "  function initLegacyPreviewQuiz() {\n",
    "    var quiz = document.getElementById('ch09-preview-quiz');\n",
    "    if (!quiz || quiz.dataset.ready === 'true') return;\n",
    "    quiz.dataset.ready = 'true';\n",
    "\n",
    "    var identity = getParams();\n",
    "    var questionsContainer = document.getElementById('ch09-preview-questions');\n",
    "    var result = document.getElementById('ch09-preview-result');\n",
    "    var submit = document.getElementById('ch09-preview-submit');\n",
    "    var actions = quiz.querySelector('.ch09-preview-actions');\n",
    "    var reset = document.getElementById('ch09-preview-reset');\n",
    "\n",
    "    renderQuestions(questionsContainer);\n",
    "    loadSessionIdentity(identity, actions, submit, result);\n",
    "\n",
    "    submit.addEventListener('click', function () {\n",
    "      var answers = collectAnswers(quiz);\n",
    "      submit.disabled = true;\n",
    "      result.textContent = 'Submitting...';\n",
    "\n",
    "      fetch('/api/v1/quiz-attempts.php', {\n",
    "        method: 'POST',\n",
    "        headers: { 'Content-Type': 'application/json' },\n",
    "        credentials: 'same-origin',\n",
    "        body: JSON.stringify({\n",
    "          quiz_id: quizId,\n",
    "          question_set_version: questionSetVersion,\n",
    "          answers: answers,\n",
    "          student_identifier: identity.student_identifier || identity.canvas_user_id || '',\n",
    "          canvas_course_id: identity.canvas_course_id,\n",
    "          canvas_assignment_id: identity.canvas_assignment_id,\n",
    "          canvas_user_id: identity.canvas_user_id\n",
    "        })\n",
    "      })\n",
    "        .then(function (response) {\n",
    "          return response.text().then(function (text) {\n",
    "            var payload = null;\n",
    "            try {\n",
    "              payload = text ? JSON.parse(text) : null;\n",
    "            } catch (error) {\n",
    "              throw new Error('Server returned a non-JSON response (HTTP ' + response.status + '): ' + text.slice(0, 160));\n",
    "            }\n",
    "            if (!payload) {\n",
    "              throw new Error('Server returned an empty response (HTTP ' + response.status + '). Check that PHP is enabled for /api/v1/quiz-attempts.php.');\n",
    "            }\n",
    "            if (!response.ok || !payload.ok) {\n",
    "              throw new Error(payload.message || payload.error || 'Submission failed.');\n",
    "            }\n",
    "            return payload;\n",
    "          });\n",
    "        })\n",
    "        .then(function (payload) {\n",
    "          var best = (payload.best_score === null || typeof payload.best_score === 'undefined') ? payload.score : payload.best_score;\n",
    "          var attempt = (payload.attempt_count === null || typeof payload.attempt_count === 'undefined') ? '' : ' Attempt ' + payload.attempt_count + '.';\n",
    "          return loadFeedbackPolicy().then(function () {\n",
    "            applyFeedback(quiz, payload.feedback || {});\n",
    "            result.textContent = 'Submission saved.' + attempt + ' Score: ' + payload.score + ' / ' + payload.max_score + '. Best score: ' + best + ' / ' + payload.max_score + '. Canvas sync: ' + payload.canvas_sync_status + '.';\n",
    "            if (!answersUnlocked) result.textContent += ' Full explanations are available when answers are released.';\n",
    "          });\n",
    "        })\n",
    "        .catch(function (error) {\n",
    "          result.textContent = 'Could not save this attempt: ' + error.message;\n",
    "        })\n",
    "        .finally(function () {\n",
    "          submit.disabled = false;\n",
    "        });\n",
    "    });\n",
    "\n",
    "    reset.addEventListener('click', function () {\n",
    "      quiz.querySelectorAll('input[type=radio]').forEach(function (input) {\n",
    "        input.checked = false;\n",
    "      });\n",
    "      quiz.querySelectorAll('.ch09-preview-feedback').forEach(function (feedback) {\n",
    "        feedback.className = 'ch09-preview-feedback';\n",
    "        feedback.textContent = '';\n",
    "      });\n",
    "      result.textContent = '';\n",
    "    });\n",
    "  }\n",
    "\n",
    "\n",
    "  function initPreviewQuiz() {\n",
    "    // The legacy PHP host retains its existing fixed-order delivery until it migrates to Press.\n",
    "    if (!/(^|\\.)thinkpress\\.org$/.test(window.location.hostname) &&\n",
    "        !['localhost', '127.0.0.1'].includes(window.location.hostname)) return initLegacyPreviewQuiz();\n",
    "    var quiz = document.getElementById('ch09-preview-quiz');\n",
    "    if (!quiz || quiz.dataset.ready === 'true') return;\n",
    "    quiz.dataset.ready = 'true';\n",
    "\n",
    "    var identity = getParams();\n",
    "    var questionsContainer = document.getElementById('ch09-preview-questions');\n",
    "    var result = document.getElementById('ch09-preview-result');\n",
    "    var submit = document.getElementById('ch09-preview-submit');\n",
    "    var actions = quiz.querySelector('.ch09-preview-actions');\n",
    "    var reset = document.getElementById('ch09-preview-reset');\n",
    "\n",
    "    // Press owns this quiz's draft and option order; the generic runner must not restore older inputs over it.\n",
    "    quiz.classList.add('press-preview-managed');\n",
    "    var next = document.createElement('button');\n",
    "    next.type = 'button';\n",
    "    next.textContent = 'Start a new attempt';\n",
    "    next.hidden = true;\n",
    "    actions.appendChild(next);\n",
    "\n",
    "    function lockQuestions(locked) {\n",
    "      quiz.querySelectorAll('input[type=radio]').forEach(function (input) { input.disabled = locked; });\n",
    "      reset.disabled = locked;\n",
    "    }\n",
    "    function showState(payload) {\n",
    "      questions = attemptState.questions;\n",
    "      renderQuestions(questionsContainer);\n",
    "      lockQuestions(payload.completed);\n",
    "      submit.disabled = payload.completed;\n",
    "      next.hidden = !payload.completed;\n",
    "      if (!payload.completed) result.textContent = '';\n",
    "      if (attemptState.preserved_draft && !payload.completed) {\n",
    "        result.textContent = 'Resumed your saved answers with their original option order.';\n",
    "      }\n",
    "      if (payload.result) {\n",
    "        return loadFeedbackPolicy().then(function () {\n",
    "          applyFeedback(quiz, payload.result.feedback || {});\n",
    "          result.textContent = 'Saved attempt. Score: ' + payload.result.score + ' / ' + payload.result.max_score +\n",
    "            '. Best score: ' + payload.result.best_score + ' / ' + payload.result.max_score + '.';\n",
    "          if (!answersUnlocked) result.textContent += ' Full explanations are available when answers are released.';\n",
    "        });\n",
    "      }\n",
    "      return Promise.resolve();\n",
    "    }\n",
    "    renderQuestions(questionsContainer);\n",
    "    lockQuestions(true);\n",
    "    loadSessionIdentity(identity, actions, submit, result).then(function () {\n",
    "      if (submit.disabled) return;\n",
    "      submit.disabled = true;\n",
    "      result.textContent = 'Resuming your Preview...';\n",
    "      return stateRequest('resume').then(showState).catch(function (error) {\n",
    "        submit.disabled = true;\n",
    "        result.textContent = 'Could not resume this Preview: ' + error.message + ' Reload to retry.';\n",
    "      });\n",
    "    });\n",
    "\n",
    "    quiz.addEventListener('change', function (event) {\n",
    "      if (!event.target || event.target.type !== 'radio' || !attemptState) return;\n",
    "      saveAnswers(quiz).catch(function (error) { result.textContent = 'Answers not saved: ' + error.message; });\n",
    "    });\n",
    "\n",
    "    submit.addEventListener('click', async function () {\n",
    "      submit.disabled = true;\n",
    "      lockQuestions(true);\n",
    "      result.textContent = 'Submitting...';\n",
    "      try {\n",
    "        await saveAnswers(quiz);\n",
    "        var response = await fetch('/api/v1/quiz-attempts.php', {\n",
    "          method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'same-origin',\n",
    "          body: JSON.stringify({ quiz_id: quizId, answers: collectAnswers(quiz),\n",
    "            question_set_version: attemptState.version,\n",
    "            student_identifier: identity.student_identifier || identity.canvas_user_id || '',\n",
    "            canvas_course_id: identity.canvas_course_id, canvas_assignment_id: identity.canvas_assignment_id,\n",
    "            canvas_user_id: identity.canvas_user_id })\n",
    "        });\n",
    "        var payload = await response.json();\n",
    "        if (!response.ok || !payload.ok) throw new Error(payload.message || payload.error || 'Submission failed.');\n",
    "        await loadFeedbackPolicy();\n",
    "        applyFeedback(quiz, payload.feedback || {});\n",
    "        result.textContent = 'Submission saved. Attempt ' + payload.attempt_count + '. Score: ' + payload.score +\n",
    "          ' / ' + payload.max_score + '. Best score: ' + payload.best_score + ' / ' + payload.max_score + '.';\n",
    "        if (!answersUnlocked) result.textContent += ' Full explanations are available when answers are released.';\n",
    "        next.hidden = false;\n",
    "      } catch (error) {\n",
    "        result.textContent = 'Could not save this attempt: ' + error.message;\n",
    "        submit.disabled = false;\n",
    "        lockQuestions(false);\n",
    "      }\n",
    "    });\n",
    "\n",
    "    reset.addEventListener('click', function () {\n",
    "      submit.disabled = true;\n",
    "      stateQueue = stateQueue.catch(function () {}).then(function () { return stateRequest('clear'); });\n",
    "      stateQueue.then(function (payload) { result.textContent = ''; return showState(payload); })\n",
    "        .catch(function (error) { result.textContent = error.message; submit.disabled = false; });\n",
    "    });\n",
    "    next.addEventListener('click', function () {\n",
    "      next.disabled = true;\n",
    "      stateRequest('next').then(function (payload) { result.textContent = ''; return showState(payload); })\n",
    "        .catch(function (error) { result.textContent = error.message; })\n",
    "        .finally(function () { next.disabled = false; });\n",
    "    });\n",
    "  }\n",
    "\n",
    "  if (document.readyState === 'loading') {\n",
    "    document.addEventListener('DOMContentLoaded', initPreviewQuiz);\n",
    "  } else {\n",
    "    initPreviewQuiz();\n",
    "  }\n",
    "})();\n",
    "</script>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
