Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Quiz statistics calculations in practice

From MoodleDocs

Moodle 2.0


Purpose of this page

Here I'm going to document what the code actually does. Documenting it here principally because I can't use TEX notation in php comments, well I guess I can but only real TEX geeks will be able to read it :-)

Code

The calculations below are all done in quiz/report/statistics/report.php The code refers to links to this doc in php comments.

Calculating MEAN of grades for all attempts by students

We calculate the MEAN of first and all attempts by :

  • fetching two totals and counts of all grades for attempts from the db the total grades for first attempts and the rest of the attempts.
  • then to get the mean of first attempts :
    • we divide the total grade for all first attempts by the number of all first attempts.
  • for the mean for all attempts :
    • we add the total of all first attempts to the total for the rest of the attempts and divide by the total count of first attempts plus the total count of the rest of the attempts.

Before display I divide by quiz.sumgrades and times by a hundred to express this as a percentage of total possible grade.

Depending on whether we are calculating the rest of the statistics for all attempts or for just the first attempts we select the appropriate mean to use in the rest of the calculations and save a empty string or a string of sql that selects first attempts only.

Calculating Standard Deviation, Skewness and Kurtosis of grades for all attempts by students

In order not to have to load potentially large datasets into memory we get the DB to do the bulk of the work doing these calculations.

We can get sql to do the following calculations :

power2

power3

power4

Standard Deviation

Test standard deviation

Before display I divide by quiz.sumgrades and times by a hundred to express this as a percentage of total possible grade.

Skewness and Kurtosis

So then :


Then Skewness

and :

Kurtosis

CIC, ER and SE

First we fetch the average grade for each position :

.

Then :

and :

and :

So :

We fetch :

From the db for all questions and then sum them all so we have :

Then we do :

Then :

And :

And :

Since SE is a grade we divide it by the maximum possible grade and times by 100 to get a percentage of the max possible grade for the whole quiz.