## DESCRIPTION
## Match each of the following hypothesis tests with their corresponding descriptions.
## ENDDESCRIPTION
## KEYWORDS('hypothesis tests','descriptions')
## DBsubject('Biostatistics')
## DBchapter('')
## DBsection('')
## Date('2026-07-12')
## Author('Neil R. Voss')
## Institution('Roosevelt University')

DOCUMENT();

loadMacros(
    'PGstandard.pl',
    'PGML.pl',
    'PGchoicemacros.pl',
    'parserPopUp.pl',
    'parserUtils.pl',
    'PGgraders.pl',
    'PGcourse.pl'
);
our @ALPHABET = ('A' .. 'Z');

# ================================
# Full matching data
# ================================
%match_data = (
  'Benchmark Z-test' => [
    'Compares the <span style="color: #935d00; font-weight:700;">mean</span> of a sample to a known <span style="color: #3b7600; font-weight:700;">population</span> <span style="color: #935d00; font-weight:700;">mean</span> when the <span style="color: #3b7600; font-weight:700;">population</span> variance is known.',
    'Used when comparing a sample\'s <span style="color: #935d00; font-weight:700;">mean</span> to a large dataset with a known <span style="color: #3b7600; font-weight:700;">population</span> <span style="color: #007576; font-weight:700;">standard deviation</span>.',
    'The <span style="color: #3b7600; font-weight:700;">population</span> <span style="color: #935d00; font-weight:700;">mean</span> systolic blood pressure is 120 mmHg with a <span style="color: #007576; font-weight:700;">standard deviation</span> of 3.9 mmHg. You are testing a sample of n = 100 patients to see if the <span style="color: #935d00; font-weight:700;">mean</span> blood pressure differs from 120 mmHg.',
    'The <span style="color: #3b7600; font-weight:700;">population</span> <span style="color: #935d00; font-weight:700;">mean</span> gene expression is 200 units with a <span style="color: #007576; font-weight:700;">standard deviation</span> of 5 units. You have a sample of n = 150 treated cells and want to test if the <span style="color: #935d00; font-weight:700;">mean</span> gene expression differs from the <span style="color: #3b7600; font-weight:700;">population</span> <span style="color: #935d00; font-weight:700;">mean</span>.',
    'The <span style="color: #3b7600; font-weight:700;">population</span> <span style="color: #935d00; font-weight:700;">mean</span> pH in a wetland is 7.5 with a <span style="color: #007576; font-weight:700;">standard deviation</span> of 0.32. You are sampling n = 50 water <span style="color: #007a00; font-weight:700;">samples</span> to check if the <span style="color: #935d00; font-weight:700;">average</span> pH has changed over time.',
    'The <span style="color: #935d00; font-weight:700;">average</span> heart rate of a healthy adult <span style="color: #3b7600; font-weight:700;">population</span> is 72 bpm, with a <span style="color: #007576; font-weight:700;">standard deviation</span> of 4 bpm. You have a sample of n = 50 patients and want to test if their <span style="color: #935d00; font-weight:700;">average</span> heart rate differs from the <span style="color: #3b7600; font-weight:700;">population</span> <span style="color: #935d00; font-weight:700;">mean</span>.',
    'In a <span style="color: #3b7600; font-weight:700;">population</span> of bacteria, the <span style="color: #935d00; font-weight:700;">average</span> gene expression level for a key metabolic gene is 100 units, with a <span style="color: #007576; font-weight:700;">standard deviation</span> of 6 units. You collect n = 40 treated bacterial <span style="color: #007a00; font-weight:700;">samples</span> and want to test if their gene expression level differs from the <span style="color: #3b7600; font-weight:700;">population</span> <span style="color: #935d00; font-weight:700;">mean</span>.',
    'The <span style="color: #935d00; font-weight:700;">average</span> temperature in a coastal region is 20&deg;C, with a <span style="color: #007576; font-weight:700;">standard deviation</span> of 1.5&deg;C. You collect n = 35 daily temperature readings from a nearby estuary and want to test if the estuary\'s <span style="color: #935d00; font-weight:700;">average</span> temperature differs from the regional <span style="color: #935d00; font-weight:700;">mean</span>.',
  ],
  'Benchmark T-test' => [
    'Compares the <span style="color: #935d00; font-weight:700;">mean</span> of a sample to a known <span style="color: #3b7600; font-weight:700;">population</span> <span style="color: #935d00; font-weight:700;">mean</span> when the <span style="color: #3b7600; font-weight:700;">population</span> variance is <span style="color: #a719db; font-weight:700;">unknown</span>.',
    'Used when the <span style="color: #3b7600; font-weight:700;">population</span> variance is <span style="color: #a719db; font-weight:700;">unknown</span>, and you have a smaller <span style="color: #b74300; font-weight:700;">sample size</span> (n &lt; 30).',
    'The <span style="color: #3b7600; font-weight:700;">population</span> <span style="color: #935d00; font-weight:700;">mean</span> resting heart rate is 70 bpm, but the <span style="color: #007576; font-weight:700;">standard deviation</span> is <span style="color: #a719db; font-weight:700;">unknown</span>. You collect a sample of n = 25 patients on a new drug to test if their <span style="color: #935d00; font-weight:700;">mean</span> heart rate differs from the <span style="color: #3b7600; font-weight:700;">population</span> <span style="color: #935d00; font-weight:700;">mean</span>.',
    'The <span style="color: #3b7600; font-weight:700;">population</span> <span style="color: #935d00; font-weight:700;">mean</span> protein concentration is 50 mg/mL, but the <span style="color: #007576; font-weight:700;">standard deviation</span> is <span style="color: #a719db; font-weight:700;">unknown</span>. You are working with n = 20 <span style="color: #007a00; font-weight:700;">samples</span> and want to test if the <span style="color: #935d00; font-weight:700;">mean</span> protein concentration differs from the known <span style="color: #935d00; font-weight:700;">mean</span>.',
    'The <span style="color: #3b7600; font-weight:700;">population</span> <span style="color: #935d00; font-weight:700;">mean</span> species richness is 25 species per plot, but the <span style="color: #007576; font-weight:700;">standard deviation</span> is <span style="color: #a719db; font-weight:700;">unknown</span>. You have a small sample of n = 18 plots and want to test if species richness differs from the <span style="color: #3b7600; font-weight:700;">population</span> <span style="color: #935d00; font-weight:700;">mean</span>.',
    'The <span style="color: #935d00; font-weight:700;">average</span> blood sugar level in the <span style="color: #3b7600; font-weight:700;">population</span> is 90 mg/dL, but the <span style="color: #007576; font-weight:700;">standard deviation</span> is <span style="color: #a719db; font-weight:700;">unknown</span>. You collect a sample of n = 20 patients and want to test if their <span style="color: #935d00; font-weight:700;">average</span> blood sugar level differs from the <span style="color: #3b7600; font-weight:700;">population</span> <span style="color: #935d00; font-weight:700;">mean</span>.',
    'The <span style="color: #935d00; font-weight:700;">average</span> protein concentration in a standard cell line is 50 mg/mL, but the <span style="color: #007576; font-weight:700;">standard deviation</span> is <span style="color: #a719db; font-weight:700;">unknown</span>. You collect n = 15 <span style="color: #007a00; font-weight:700;">samples</span> from a modified cell line to test if the <span style="color: #935d00; font-weight:700;">mean</span> protein concentration differs from the standard.',
    'The <span style="color: #935d00; font-weight:700;">average</span> tree height in a natural forest is 12 meters, but the <span style="color: #007576; font-weight:700;">standard deviation</span> is <span style="color: #a719db; font-weight:700;">unknown</span>. You collect n = 12 <span style="color: #007a00; font-weight:700;">samples</span> from a reforested area to test if the <span style="color: #935d00; font-weight:700;">average</span> tree height differs from the natural forest.',
  ],
  'Two-Sample T-test' => [
    'Compares the <span style="color: #935d00; font-weight:700;">mean</span>s of two independent groups to determine if they are statistically different from each other.',
    'Used to determine whether the <span style="color: #935d00; font-weight:700;">average</span> heights of two different plant species are <span style="color: #0067cc; font-weight:700;">significantly different</span>.',
    'You are comparing the <span style="color: #935d00; font-weight:700;">mean</span> cholesterol levels between two groups, one receiving a placebo and the other a treatment. Each group contains n = 20 participants. You want to test if the <span style="color: #935d00; font-weight:700;">mean</span>s are <span style="color: #0067cc; font-weight:700;">significantly different</span>.',
    'You are comparing the <span style="color: #935d00; font-weight:700;">mean</span> gene expression of two cell lines, one treated and one untreated, with n = 25 <span style="color: #007a00; font-weight:700;">samples</span> in each group. You want to test if the <span style="color: #935d00; font-weight:700;">mean</span>s are <span style="color: #0067cc; font-weight:700;">significantly different</span>.',
    'You want to test if the <span style="color: #935d00; font-weight:700;">mean</span> number of species differs between two regions, one pristine and one affected by deforestation, with n = 25 plots in each region.',
    'You are comparing the <span style="color: #935d00; font-weight:700;">average</span> recovery times between two groups of patients, one receiving a new drug and one receiving standard care, with n = 25 patients in each group. You want to test if the <span style="color: #935d00; font-weight:700;">mean</span>s are different.',
    'You are comparing the <span style="color: #935d00; font-weight:700;">average</span> enzyme activity between two experimental conditions, one treated with a new inhibitor and one with a control, with n = 20 <span style="color: #007a00; font-weight:700;">samples</span> in each group. You want to test if the <span style="color: #935d00; font-weight:700;">mean</span>s are different.',
    'You want to compare the <span style="color: #935d00; font-weight:700;">average</span> soil pH between two agricultural fields, one using organic fertilizer and one using conventional methods, with n = 30 soil <span style="color: #007a00; font-weight:700;">samples</span> from each field. You want to test if the <span style="color: #935d00; font-weight:700;">mean</span>s are <span style="color: #0067cc; font-weight:700;">significantly different</span>.',
  ],
  'Two-Sample F-test' => [
    'Compares the <span style="color: #cc0066; font-weight:700;">variances</span> of two independent groups to test if the <span style="color: #076dad; font-weight:700;">variability</span> between them is <span style="color: #0067cc; font-weight:700;">significantly different</span>.',
    'Used to test whether two different batches of products have equal <span style="color: #076dad; font-weight:700;">variability</span> in their measurements.',
    'You are comparing the <span style="color: #076dad; font-weight:700;">variability</span> in blood pressure between two groups, one with n = 25 patients on a standard drug and another with n = 40 patients on an experimental drug. You want to test if the <span style="color: #cc0066; font-weight:700;">variances</span> are different.',
    'You are comparing the variance of protein concentrations between two experimental batches, each with n = 25 <span style="color: #007a00; font-weight:700;">samples</span>, to see if their <span style="color: #076dad; font-weight:700;">variability</span> differs.',
    'You are comparing the <span style="color: #076dad; font-weight:700;">variability</span> in soil nutrient levels between two areas, one fertilized and one unfertilized, with n = 25 <span style="color: #007a00; font-weight:700;">samples</span> in each group. You want to test if the <span style="color: #cc0066; font-weight:700;">variances</span> differ.',
    'You are comparing the <span style="color: #076dad; font-weight:700;">variability</span> in cholesterol levels between two groups, one receiving a diet plan and the other receiving medication, with n = 40 patients in each group. You want to test if the <span style="color: #cc0066; font-weight:700;">variances</span> are <span style="color: #0067cc; font-weight:700;">significantly different</span>.',
    'You are comparing the <span style="color: #076dad; font-weight:700;">variability</span> in protein yield between two different laboratory protocols, each using n = 25 <span style="color: #007a00; font-weight:700;">samples</span>. You want to test if the <span style="color: #cc0066; font-weight:700;">variances</span> in protein yield are <span style="color: #0067cc; font-weight:700;">significantly different</span>.',
    'You are comparing the <span style="color: #076dad; font-weight:700;">variability</span> in air pollution measurements between two cities, with n = 35 measurements from each city. You want to test if the <span style="color: #cc0066; font-weight:700;">variances</span> in pollution levels differ significantly.',
  ],
  'Analysis of Variance (ANOVA)' => [
    'Compares the <span style="color: #935d00; font-weight:700;">mean</span>s of more than two groups to determine if at least one group\'s <span style="color: #935d00; font-weight:700;">mean</span> is <span style="color: #0067cc; font-weight:700;">significantly different</span> from the others.',
    'Used to compare the <span style="color: #935d00; font-weight:700;">average</span> exam scores across three different classrooms.',
    'You want to compare the <span style="color: #935d00; font-weight:700;">mean</span> blood glucose levels of patients in four drug groups, each group has n = 30 participants. You want to test if at least one group\'s <span style="color: #935d00; font-weight:700;">mean</span> differs significantly.',
    'You are testing if the <span style="color: #935d00; font-weight:700;">mean</span> protein abundance differs across four experimental conditions, with n = 25 <span style="color: #007a00; font-weight:700;">samples</span> per condition.',
    'You want to compare the <span style="color: #935d00; font-weight:700;">mean</span> number of plant species across five habitats, with n = 20 plots in each habitat. You want to test if any habitat shows a <span style="color: #0067cc; font-weight:700;">significantly different</span> <span style="color: #935d00; font-weight:700;">mean</span>.',
    'You want to compare the <span style="color: #935d00; font-weight:700;">mean</span> weight loss between patients following four (4) different diet plans, with n = 30 participants in each group. You want to test if there are significant differences in <span style="color: #935d00; font-weight:700;">mean</span> weight loss across the groups.',
    'You are testing if the <span style="color: #935d00; font-weight:700;">mean</span> DNA replication rate differs across four different temperatures, with n = 20 <span style="color: #007a00; font-weight:700;">samples</span> per temperature. You want to test if any group shows <span style="color: #0067cc; font-weight:700;">significantly different</span> replication rates.',
    'You are studying bird <span style="color: #3b7600; font-weight:700;">population</span>s across five different habitats. You collect n = 25 bird counts from each habitat and want to test if there is a significant difference in the <span style="color: #935d00; font-weight:700;">mean</span> number of birds observed across the habitats.',
  ],
);

# -------------------------------
# Select N random keys
# -------------------------------
my $n = 5;
@all_keys = PGsort(sub { $_[0] lt $_[1] }, keys %match_data);
my $local_seed = (defined($problemSeed) && $problemSeed ne '') ? $problemSeed : 1;
my $local_random = new PGrandom($local_seed);

my @indices = (0 .. $#all_keys);
my @shuffled = ();
while (@indices) {
  my $pick = $local_random->random(0, $#indices, 1);
  push @shuffled, splice(@indices, $pick, 1);
}
my @selected_keys = @all_keys[@shuffled[0..$n-1]];

# -------------------------------
# Build question/answer pairs
# -------------------------------
# Each entry: [prompt, choice]
@q_and_a = ();
foreach my $key (@selected_keys) {
  my $values_ref = $match_data{$key};
  my $i = $local_random->random(0, $#$values_ref, 1);
  my $value = $values_ref->[$i];
  push @q_and_a, [ $value, $key ];
}

# -------------------------------
# Randomize the questions
# -------------------------------
my @q_indices = (0 .. $#q_and_a);
my @q_shuffled = ();
while (@q_indices) {
  my $pick = $local_random->random(0, $#q_indices, 1);
  push @q_shuffled, $q_and_a[splice(@q_indices, $pick, 1)];
}
@q_and_a = @q_shuffled;

# -------------------------------
# Sort the choices alphabetically
# -------------------------------
@answers = ();
push(@answers, (map { $_->[1] } @q_and_a));
@answers_sorted = PGsort(sub { $_[0] lt $_[1] }, @answers);

# -------------------------------
# HTML-safe answer labels
# -------------------------------
%answer_html = (
  'Benchmark Z-test' => '<span style="color: #d40000; font-weight:700;">Benchmark Z-test</span>',
  'Benchmark T-test' => '<span style="color: #6c6c00; font-weight:700;">Benchmark T-test</span>',
  'Two-Sample T-test' => '<span style="color: #00775f; font-weight:700;">Two-Sample T-test</span>',
  'Two-Sample F-test' => '<span style="color: #003fff; font-weight:700;">Two-Sample F-test</span>',
  'Analysis of Variance (ANOVA)' => '<span style="color: #c80085; font-weight:700;">Analysis of Variance (ANOVA)</span>',
);

@answers_sorted_html = map { $answer_html{$_} || $_ } @answers_sorted;

# -------------------------------
# Create answer index lookup
# -------------------------------
our %answer_index;
for (my $i = 0; $i <= $#answers_sorted; $i++) {
  $answer_index{$answers_sorted[$i]} = $i;
}

# -------------------------------
# PopUp/DropDown compatibility
# -------------------------------
sub make_popup {
  return defined &DropDown ? DropDown(@_) : PopUp(@_);
}

# -------------------------------
# Create popup objects (blank default)
# -------------------------------
my @answer_letters = @ALPHABET[0 .. $#answers_sorted];
my @answer_letters_with_blank = ('', @answer_letters);
@answer_dropdowns =
  map { make_popup([ @answer_letters_with_blank ], $answer_index{$q_and_a[$_][1]} + 1 ) }
  0 .. $#q_and_a;

# -------------------------------
# Render the question
# -------------------------------
HEADER_TEXT(<<END_STYLE);
<style>
.pgml-bold { font-weight: 700; }
.two-column {
    display: flex;
	flex-wrap: wrap;
	gap: 2rem;
	align-items: center;
	justify-content: space-evenly;
}
</style>
END_STYLE

$question_text = 'Match each of the following hypothesis tests with their corresponding descriptions.';
$note_text = 'Note: Each choice will be used exactly once.';

BEGIN_PGML
[$question_text]*
[$note_text]*

[@ MODES(HTML => '<div class="two-column"><div>') @]*
[@ join(
    "\n\n",
    map {
        '[_]{$answer_dropdowns[' . $_ . ']} '
            . '*' . ($_ + 1) . '.* '
            . '[$q_and_a[' . $_ . '][0]]*'
    } 0 .. $#q_and_a
) @]**
[@ MODES(HTML => '</div><div class="right-col">') @]*
[@ join(
    "\n\n",
    map {
        chr(65 + $_) . '\\.' . ' ' . '[$answers_sorted_html[' . $_ . ']]*'
    } 0 .. $#answers_sorted
) @]**
[@ MODES(HTML => '</div></div>') @]*
END_PGML

# -------------------------------
# Dynamic Partial Credit Based on $n
# -------------------------------
$showPartialCorrectAnswers = 0;
my @thresholds;
my @scores;
for (my $i = 1; $i <= $n; $i++) {
  push @thresholds, $i;
  push @scores, sprintf("%.2f", $i / $n);
}

install_problem_grader(~~&custom_problem_grader_fluid);
$ENV{grader_numright} = [@thresholds];
$ENV{grader_scores}   = [@scores];
$ENV{grader_message} = 'You can earn partial credit.';

# -------------------------------
# Solution
# -------------------------------
$answer_list = join(', ', map { ($_ + 1) . '-' . $ALPHABET[$answer_index{$q_and_a[$_][1]}] } 0 .. $#q_and_a);
BEGIN_PGML_SOLUTION
The correct answers are: [$answer_list].
END_PGML_SOLUTION

ENDDOCUMENT();

