note 118535 added to function.stats-covariance

From: Date: Tue, 22 Dec 2015 09:37:33 +0000
Subject: note 118535 added to function.stats-covariance
Groups: php.notes 
Request: Send a blank email to php-notes+get-204522@lists.php.net to get a copy of this message
// kanniprabu's function is wrong. // You can check this function with COVARIANCE.P Excel function: function getCovariance( $valuesA, $valuesB ) { $countA = count($valuesA); $countB = count($valuesB); if ( $countA != $countB ) { trigger_error( 'Arrays with different sizes: countA='. $countA .', countB='. $countB, E_USER_WARNING ); return false; } if ( $countA < 0 ) { trigger_error( 'Empty arrays', E_USER_WARNING ); return false; } // Use library function if available if ( function_exists( 'stats_covariance' ) ) { return stats_covariance( $valuesA, $valuesB ); } $meanA = array_sum( $valuesA ) / floatval( $countA ); $meanB = array_sum( $valuesB ) / floatval( $countB ); $add = 0.0; for ( $pos = 0; $pos < $countA; $pos++ ) { $valueA = $valuesA[ $pos ]; if ( ! is_numeric( $valueA ) ) { trigger_error( 'Not numerical value in array A at position '. $pos .', value='. $valueA, E_USER_WARNING ); return false; } $valueB = $valuesB[ $pos ]; if ( ! is_numeric( $valueB ) ) { trigger_error( 'Not numerical value in array B at position '. $pos .', value='. $valueB, E_USER_WARNING ); return false; } $difA = $valueA - $meanA; $difB = $valueB - $meanB; $add += ( $difA * $difB ); } // for return $add / floatval( $countA ); } ---- Server IP: 72.52.91.14 Probable Submitter: 85.251.188.122 ---- Manual Page -- http://php.net/manual/en/function.stats-covariance.php Edit -- https://master.php.net/note/edit/118535 Del: integrated -- https://master.php.net/note/delete/118535/integrated Del: useless -- https://master.php.net/note/delete/118535/useless Del: bad code -- https://master.php.net/note/delete/118535/bad+code Del: spam -- https://master.php.net/note/delete/118535/spam Del: non-english -- https://master.php.net/note/delete/118535/non-english Del: in docs -- https://master.php.net/note/delete/118535/in+docs Del: other reasons-- https://master.php.net/note/delete/118535 Reject -- https://master.php.net/note/reject/118535 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#204522) next »