g02caf

g02caf © Numerical Algorithms Group, 2002.

Purpose

G02CAF Simple linear regression with constant term, no missing values

Synopsis

[result,ifail] = g02caf(x,y<,ifail>)

Description

 
 The routine fits a straight line of the form
 
                              y=a+bx
 
 to the data points
 
                   (x ,y ),(x ,y ),...,(x ,y ),
                     1  1    2  2        n  n
 
 such that
 
                  y =a+bx +e  , i=1,2,...,n(n>2).
                   i     i  i
 
 The routine calculates the regression coefficient, b, the 
 regression constant, a (and various other statistical quantities)
 by minimizing
 
                               n    
                               --  2
                               >  e .
                               --  i
                               i=1  
 
 The input data consist of the n pairs of observations
 
                    (x ,y ),(x ,y ),...,(x ,y )
                      1  1    2  2        n  n
 
 on the independent variable x and the dependent variable y.
 
 The quantities calculated are:
 
 (a)   Means: 
                              n            n   
                         _  1 --      _  1 --  
                         x= - >  x ;  y= - >  y 
                            n --  i      n --  i
                              i=1          i=1 
 
 (b)   Standard deviations: 
                    _______________            _______________
                   /     n                    /     n        
                  /   1  --     _ 2          /   1  --     _ 2
           s =   /   --- >  (x -x) ;  s =   /   --- >  (y -y) 
            x   /    n-1 --   i        y   /    n-1 --   i   
              \/         i=1             \/         i=1      
 
 (c)   Pearson product-moment correlation coefficient: 
                               n             
                               --     _     _
                               >  (x -x)(y -y)
                               --   i     i  
                               i=1           
                     r= ----------------------------
                              ______________________
                             / n          n        
                            /  --     _ 2 --     _ 2
                           /   >  (x -x)  >  (y -y) 
                          /    --   i     --   i   
                        \/     i=1        i=1      
 
 (d)   The regression coefficient, b, and the regression constant,
       a:
       
                           n                     
                           --     _     _        
                           >  (x -x)(y -y)       
                           --   i     i          
                           i=1                _  _
                       b= ----------------; a=y-bx
                             n                   
                             --     _ 2          
                             >  (x -x)           
                             --   i              
                             i=1                 
 
 (e)   The sum of squares attributable to the regression, SSR, the
       sum of squares of deviations about the regression, SSD, and
       the total sum of squares, SST:
                 n                n             
                 --     _ 2       --           2
            SST= >  (y -y) ; SSD= >  (y -a-bx ) ; SSR=SST-SSD
                 --   i           --   i     i  
                 i=1              i=1           
 
 (f)   The degrees of freedom attributable to the regression, DFR,
       the degrees of freedom of deviations about the regession, 
       DFD, and the total degrees of freedom, DFT:
                         DFT=n-1; DFD=n-2; DFR=1
 
 (g)   The mean square attributable to the regression, MSR, and 
       the mean square of deviations about the regression, MSD:
                        MSR=SSR/DFR; MSD=SSD/DFD
 
 (h)   The F-value for the analysis of variance:
                                F=MSR/MSD
 
 (i)   The standard error of the regression coefficient, se(b), 
       and the standard error of the regression constant, se(a):
       
                                        
                     ____________       
                    /     MSD           
       se(b)=      /  -----------; se(a)
                  /    n                
                 /     --     _ 2       
                /      >  (x -x)        
               /       --   i           
             \/        i=1              
                 ____________________
                /   (        _2     )
               /    ( 1      x      )
       =      /  MSD( -+ -----------)
             /      ( n   n         )
            /       (     --     _ 2)
           /        (     >  (x -x) )
          /         (     --   i    )
        \/          (     i=1       )
 
 (j)   The t-value for the regression coefficient, t(b), and the t
       -value for the regression constant, t(a):
                                b            a  
                        t(b)= -----; t(a)= -----.
                              se(b)        se(a)
 

Parameters

g02caf

Required Input Arguments:

x (:)                                 real
y (:)                                 real

Optional Input Arguments:                       <Default>

ifail                                 integer  -1

Output Arguments:

result (20)                           real
ifail                                 integer