|
|
|
<?php
$myarray = array(2, 4, 4, 8, 10, 12, 20, 25, 28, 12); //X-array
$otherarray=array(3, 4, 5, 6, 8, 10, 12, 14, 16, 9); //Y-array
$sumX=0;
$sumY=0;
$sumXX=0;
$sumXY=0;
$n=10; //number of items
for ($i=0; $i<$n; $i++) {
$sumX +=$myarray[$i];
$sumY +=$otherarray[$i];
$meanX = $sumX/$n;
$meanY = $sumY/$n;
$sumXX += pow($myarray[$i],2);
$sumXY += ($myarray[$i])*($otherarray[$i]);
$m =($sumXY - $meanY*$sumX)/($sumXX-$meanX*$sumX);
$b =$meanY-$meanX*$m;
}
echo ("Sum of X : " .$sumX);
echo "<br>";
echo ("Sum of Y : " .$sumY);
echo "<br>";
echo ("Mean of X: " .$meanX);
echo "<br>";
echo ("Mean of Y: " .$meanY);
echo "<br>";
echo ("Sums of Squares for X: " .$sumXX);
echo "<br>";
echo ("A_hat : " .$m); //Estimation of line passing through two points
echo "<br>";
echo ("B_hat : " .$b);
echo "<br>";
echo ("The equation of the regression line is : y = " . $m );
echo ("x + " . $b);
?> |
|
| Latitude-Longitude to Miles Categories : PHP, Utilities, Math. | | | Math operations on big numbers Categories : PHP, Math. | | | Weighted Random - Random Scripts usually chose one out of each item, and each item have an equal chance to be chosen. But what if you want an item to be chosed more frequently than other? Categories : PHP, Math., Arrays | | | Diffusion-Limited Aggregation visualization Categories : PHP, Graphics, Algorithms, Math. | | | Temperature Conversion Categories : PHP, Math., Beginner Guides | | | decoct -- Decimal to octal Categories : PHP, PHP Functions, Math. | | | How to judge if an integer is odd or is even in Php3? Categories : Math., PHP, Algorithms | | | Calculator for Baroque Violin strings Categories : Math., PHP, Strings | | | Show the steps for converting a number from a given base to base 10. Shows the steps involved in converting a number from a given base to base 10. Categories : PHP, Math., Algorithms | | | Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | 3dLib - a class for drawing in 3D space. Supported functions: Line, SetPixel, Polygon, FilledPolygon, etc. 3dChart() function has been added for one-call drawing of 3d charts. Support of mostly used 3d-transformations. Categories : Graphics, Math., PHP Classes, PHP, Charts and Graphs | | | Easy to use random number function that seeds with uniqid and allows a max value Categories : Math., PHP | | | Greatest Common Denominator - A simple class that finds the greatest common denominator for two integers.
Categories : PHP, PHP Classes, Math. | | | Arbitrary Precision Math using BCMATH routines Categories : PHP, Math., BC math | | | Prime number finder (Sieve of Erastothenes) Categories : PHP, Algorithms, Math. | |
|
|
|