File: regression.mpi

package info (click to toggle)
mathpiper 0.0.svn2556-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 7,416 kB
  • ctags: 2,729
  • sloc: java: 21,643; xml: 751; sh: 105; makefile: 5
file content (25 lines) | stat: -rw-r--r-- 412 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

/* Finds the rengression of y onto x, that is
   y == alpha + beta * x
 
   Example usage:
   x := 1 .. 5;
   y := (2.34*x+2) +(2*Random()-1); 
   ans :=Regress(x,y);
    
   To find the residuals, we do
   (y-alpha-beta*x) /: ans
 */


Regress(x,y) :=
[
 Local(xy,x2,i,mx,my);

 mx := Mean(x);
 my := Mean(y);
 xy := Add((x-mx)*(y-my));
 x2 := Add((x-mx)^2);  
 {alpha <- (my-xy*mx/x2) , beta <-  xy/x2}; 
];