/** * Compute the quiz statistics. * * @param int $quizid the quiz id. * @param int $whichattempts which attempts to use, represented internally as one of the constants as used in * $quiz->grademethod ie. * QUIZ_GRADEAVERAGE, QUIZ_GRADEHIGHEST, QUIZ_ATTEMPTLAST or QUIZ_ATTEMPTFIRST * we calculate stats based on which attempts would affect the grade for each student. * @param array $groupstudents students in this group. * @param int $p number of positions (slots). * @param float $sumofmarkvariance sum of mark variance, calculated as part of question statistics * @return quiz_statistics_calculated $quizstats The statistics for overall attempt scores. */ public function calculate($quizid, $whichattempts, $groupstudents, $p, $sumofmarkvariance) { $quizstats = new quiz_statistics_calculated($whichattempts); $countsandaverages = $this->attempt_counts_and_averages($quizid, $groupstudents); foreach ($countsandaverages as $propertyname => $value) { $quizstats->{$propertyname} = $value; } $s = $quizstats->s(); if ($s == 0) { return $quizstats; } // Recalculate sql again this time possibly including test for first attempt. list($fromqa, $whereqa, $qaparams) = quiz_statistics_attempts_sql($quizid, $groupstudents, $whichattempts); $quizstats->median = $this->median($s, $fromqa, $whereqa, $qaparams); if ($s > 1) { $powers = $this->sum_of_powers_of_difference_to_mean($quizstats->avg(), $fromqa, $whereqa, $qaparams); $quizstats->standarddeviation = sqrt($powers->power2 / ($s - 1)); // Skewness. if ($s > 2) { // See http://docs.moodle.org/dev/Quiz_item_analysis_calculations_in_practise#Skewness_and_Kurtosis. $m2 = $powers->power2 / $s; $m3 = $powers->power3 / $s; $m4 = $powers->power4 / $s; $k2 = $s * $m2 / ($s - 1); $k3 = $s * $s * $m3 / (($s - 1) * ($s - 2)); if ($k2 != 0) { $quizstats->skewness = $k3 / pow($k2, 3 / 2); // Kurtosis. if ($s > 3) { $k4 = $s * $s * (($s + 1) * $m4 - 3 * ($s - 1) * $m2 * $m2) / (($s - 1) * ($s - 2) * ($s - 3)); $quizstats->kurtosis = $k4 / ($k2 * $k2); } if ($p > 1) { $quizstats->cic = 100 * $p / ($p - 1) * (1 - $sumofmarkvariance / $k2); $quizstats->errorratio = 100 * sqrt(1 - $quizstats->cic / 100); $quizstats->standarderror = $quizstats->errorratio * $quizstats->standarddeviation / 100; } } } } $quizstats->cache(quiz_statistics_qubaids_condition($quizid, $groupstudents, $whichattempts)); return $quizstats; }