[advanced search]
Results from the most recent live auction are here.
26 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming > CODE
User Name
Password

Old 01-18-2007, 12:13 PM   · #1
lee101
NamePros Regular
 
Name: Lee
Location: United Kingdom
Trader Rating: (8)
Join Date: Mar 2006
Posts: 344
NP$: 2.90 (Donate)
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){
                
$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);
        
//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


Please register or log-in into NamePros to hide ads
__________________
http://bypasstopsite.com - Submit your proxy!
http://biggertwitter.com - Make twitter a bit bigger!
Currently Developing - Linux Screenshots

Last edited by lee101 : 01-21-2007 at 09:49 AM.
lee101 is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


Site Sponsors
Find out how! Get Your Site Linked at LinkedKeywords.com Get Your Site Linked at LinkedKeywords.com
Advertise your business at NamePros
All times are GMT -7. The time now is 11:09 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0