<P> The following MATLAB (or Octave) code example computes the mode of a sample: </P> <P> The algorithm requires as a first step to sort the sample in ascending order . It then computes the discrete derivative of the sorted list, and finds the indices where this derivative is positive . Next it computes the discrete derivative of this set of indices, locating the maximum of this derivative of indices, and finally evaluates the sorted sample at the point where that maximum occurs, which corresponds to the last member of the stretch of repeated values . </P> <Table> Comparison of common averages of values (1, 2, 2, 3, 4, 7, 9) <Tr> <Th> Type </Th> <Th> Description </Th> <Th> Example </Th> <Th> Result </Th> </Tr> <Tr> <Td> Arithmetic mean </Td> <Td> Sum of values of a data set divided by number of values: x _̄ = 1 n ∑ i = 1 n x i (\ displaystyle \ scriptstyle (\ bar (x)) = (\ frac (1) (n)) \ sum _ (i = 1) ^ (n) x_ (i)) </Td> <Td> (1 + 2 + 2 + 3 + 4 + 7 + 9) / 7 </Td> <Td> </Td> </Tr> <Tr> <Td> Median </Td> <Td> Middle value separating the greater and lesser halves of a data set </Td> <Td> 1, 2, 2, 3, 4, 7, 9 </Td> <Td> </Td> </Tr> <Tr> <Td> Mode </Td> <Td> Most frequent value in a data set </Td> <Td> 1, 2, 2, 3, 4, 7, 9 </Td> <Td> </Td> </Tr> </Table> <Tr> <Th> Type </Th> <Th> Description </Th> <Th> Example </Th> <Th> Result </Th> </Tr>

What is the value that occurs most frequently in a distribution