Fatal Error -> getAnnotationsAvg

I am trying to adapt Miguel Montes' rate plugin into another plugin.  I am having an issue (Fatal Error) with the getAnnotationsAvg:


Fatal error: Call to a member function getAnnotationsAvg() on a non-object in /home/xxxxx/public_html/mysite.com/mod/rate/views/default/rate/rate.php on line 15


Here is the rate file (error occurs where it is underlined and bolded below):

 *        RATE PLUGIN
 *        @package rate
 *        @author Miguel Montes mmontesp@gmail.com
 *        @license GNU General Public License (GPL) version 2
 *        @copyright (c) Miguel Montes 2008
 *        @link http://community.elgg.org/pg/profile/mmontesp

$opt = array(elgg_echo("rate:0")=>1, elgg_echo("rate:1")=>2, elgg_echo("rate:2")=>3, elgg_echo("rate:3")=>4, elgg_echo("rate:4")=>5, elgg_echo("rate:5")=>6);

$rate = $vars['entity']->getAnnotationsAvg('generic_rate');
$image = round($rate*2);
$rate = $image/2;

echo "<img src='{$CONFIG->wwwroot}mod/rate/_graphics/$image.gif' alt='$rate' title='$rate'/> (".$vars['entity']->countAnnotations('generic_rate')." ".elgg_echo("rate:rates").")";

//Solo mostramos el formulario para usuarios logueados que no hayan votado aun
//We show the form if the user is legged in and it hasn't rate yet

//if (!count_annotations($vars['entity']->guid, $vars['entity']->getType(), $vars['entity']->getSubtype(), 'generic_rate', "", "", $_SESSION['guid'])){
if (allow_rate($vars['entity'])){
        $form_body = "<p><label>".elgg_echo("rate:text")."</label></p>";
        $form_body .= "<p>" . elgg_view('input/hidden', array('internalname' => 'guid', 'value' => $vars['entity']->getGUID()));
        $form_body .= "<p>" . elgg_view('input/rate', array('internalname' => 'rate', 'options' => $opt));
        $form_body .= elgg_view('input/submit', array('value' => elgg_echo("rate:rateit"))) . "</p>";

        echo elgg_view('input/form', array('body' => $form_body, 'action' => "{$vars['url']}action/rate/add"));       


Is the function used improperly?  I have read ElggEntity Class Reference here but cannot seem to find an error in the above usage.  Can any bright PHP'ers out there shed some light on this?