NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page [PHP] PMCC Calculator

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search
7 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 01-18-2007, 12:13 PM THREAD STARTER               #1 (permalink)
NamePros Regular
Join Date: Mar 2006
Location: United Kingdom
Posts: 413
lee101 is a jewel in the roughlee101 is a jewel in the roughlee101 is a jewel in the rough
 




[PHP] PMCC Calculator


Possibly one of the most useless functions, but i thought i'd post it anyway, as it may be of use to someone. It calculates PMCC between to set's of data, i created it because excel was continously throwing up errors with all the data I entered.

pmcc.class.php
PHP Code:
  <?php
/*
    PMCC (Product Moment Correlation Coefficient) Class
    Takes 2 sets of data, and calculates their relationship using the PMCC formula
    and returns a value between -1 and 1
    


    Created by: Lee Findlow
    Contact:     leefindlow@gmail.com
    Website:     http://conceptsublime.com
*/ 
class PMCC{
    
//Variables Used, for range x and range y
    
var $DataX;
    var 
$DataY;

    
//Function to create Sxx
    
function Sxx(){
    
//Disable Error Reporting
    
error_reporting(0);
        
$NumOfAll count($this->DataX);
        
$SumOfAll array_sum($this->DataX);
        
$MeanOfAll $SumOfAll/$NumOfAll;
        
//Calculate Σ(Xi-[Mean Of All X's])^2
        
$RunningTotal 0;
            foreach(
$this->DataX as $Sxx){
????: NamePros.com http://www.namepros.com/code/282994-php-pmcc-calculator.html
                
$RunningTotal += pow(($Sxx-$MeanOfAll),2);
            }
        return 
$RunningTotal;
    }
    
    
//Function to create Syy
    
function Syy(){
    
//Disable Error Reporting
    
error_reporting(0);
        
$NumOfAll count($this->DataY);
        
$SumOfAll array_sum($this->DataY);
        
$MeanOfAll $SumOfAll/$NumOfAll;
        
//Calculate Σ(Yi-[Mean Of All Y's])^2
        
$RunningTotal 0;
            foreach(
$this->DataY as $Syy){
                
$RunningTotal += pow(($Syy-$MeanOfAll),2);
            }
        return 
$RunningTotal;
    }
    
    
//Function to create Sxy
    
function Sxy(){
    
//Disable Error Reporting
    
error_reporting(0);
        
$NumOfAll_X count($this->DataX);
        
$SumOfAll_X array_sum($this->DataX);
        
$MeanOfAll_X $SumOfAll_X/$NumOfAll_X;
        
$NumOfAll_Y count($this->DataX);
        
$SumOfAll_Y array_sum($this->DataX);
        
$MeanOfAll_Y $SumOfAll_Y/$NumOfAll_Y;
        
$NumOfAll min($NumOfAll_X,$NumOfAll_Y);
        
//Loop Through and create Σ(Xi-[Mean Of All X's])(Yi-[Mean Of All Y's])
        
$i 0;
        
$RunningTotal 0;
        while(
$i $NumOfAll){
            
$X $this->DataX[$i] - $MeanOfAll_X;
            
$Y = ($this->DataY[$i]-$MeanOfAll_Y);
            
$RunningTotal+= $X $Y;
            
$i++;
        }
        return 
$RunningTotal;
    }
    
    
//Combine All Functions to Create PMCC Value
    
function PMCC(){
    
//Disable Error Reporting
    
error_reporting(0);
????: NamePros.com http://www.namepros.com/showthread.php?t=282994
        
//Calculate Lower Part
        
$SxxSyy $this->Sxx()*$this->Syy();
        
$SxxSyy sqrt($SxxSyy);
        
//Do Calculation
        
$PMCC $this->Sxy()/$SxxSyy;
        
//Return Answer
        
return $PMCC;
    }
};
?>
The data you want to compare is entered as an array, as displayed above


More Information - http://en.wikipedia.org/wiki/PMCC

Lee
__________________
Linux Screenshots
Last edited by lee101; 01-21-2007 at 09:49 AM.
lee101 is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 03:25 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger