Mathematical Functions on Variables: median, mode, mean
median()
To take the median of a list of variables.
Example
Practical example
You have a question where you should calculate the median. Let’s review the example question below.
In this question, you have random numbers assigned to your variables (###a,b,c,d,e,f,g!!:r(1,10,0.1,2dp)###). Your task is to calculate the median from the range of variables with the assigned numbers you have. How to calculate the correct median if the variables’ numeric meaning is random and changes with every new example, as we established with the r() function?
For this, you should set the answer criterion in the Question Template box. You add the following line under the simple random function line:
Function ###ans:median(a,b,c,e,f,g)### allows you to store the median of a, b, c, e, f, g and retrieve the meaning, assigned to it (exactly the median of a, b, c, e, f, g) in the Answer Template box - assuming you use multiple answer type, the Answer Template box is always for the correct answer:
The output in the Preview box will look as following:
mode()
To take the mode of a list of variables. Be careful that there are repeated variables, or else you will get an error!
Example
Practical example
You have a question where you should calculate the mode. Let’s review the example question below.
In this question, you have random numbers assigned to your variables (###a,b,c,d,e,f,g!!:r(18,87,1,0dp$)###, ###h,i,j,k,l!!:r(25,86,1,0dp$)###). Your task is to calculate the mode and to assign the answer to a correct meaning of a variable. How to ensure that if the variables’ numeric meaning is random and changes with every new example, as we established with the r() function?
There are two ways to assign the answer to the correct mode meaning or variable. For both you need to repeat one variable in an example twice as below:
As the mode is the most repeated number, OTTER will identify h which is repeated two times as the correct answer. You can show it in the answer in two ways. You can actually calculate the mode, repeating h in brakes two times as you did in the Question Template, but that is the long way. Or you can assign h itself as a correct option, as it is repeated two times and is already set to be the answer:
In both cases, the output in the preview box will look like this. Please, pay attention to numeric meaning assigned to h and the correct answers options:
As you may have noticed, the double h you repeated in the code is in the beginning of the line of numbers for Donut Holiday Results, for which we need to calculate the mode. So the answer options are as shown below, and h, thus 39, is the correct one.
mean()
To take the mean of a list of variables.
Example
Practical example
You have a question where you should calculate the mode. Let’s review the example question below.
In this question, you have random numbers assigned to your variables (###a,b,c,d,e,f!!:r(1,20,1,0dp)###, ###g,h,i,j,k!!:r(1,30,1,0dp)###). Your task is to calculate the meaning and to assign the answer to a correct meaning of a variable. How to ensure that if the variables’ numeric meaning is random and changes with every new example, as we established with the r() function?
You do it the following way: adding the mean function to the group of variables you need to calculate it from:
The output in the answer box where you have your mean calculated will look like the picture below. Please pay attention that the mean is calculated from the variables set by the mean function (from the likelihood of saying “Hello”):
No Comments