Autocorrelation and Durbin-Watson test
/////////////////////////////////////
Usually, the closing stock prices are autocorrelated. 
 returns are negatively autocorrelated. 
    DW Test        Description 
    --------     -----------------  
    close to 2   not  autocorrelated 

       >   2     negatively autocorrelated 
  
       <   2     positively  autocorrelated 
/////////////////////////////////////

Row, column and matrix 
/////////////////////////////////////
1)  A row is a special case for matrix

Example 1:
    1,2,3,10,5,10,11

Example 2: 
    2.5, 3.5, 0.1

    Its dimensions are  1 * m  or 1 by m.

2)  A column is also a special case for matrix 

Example #1:
     1
     2
     3
     4
     10
     20
     3
     4

Its dimension are n * 1   or n by 1.
 
/////////////////////////////////////

Durbin-Watson Autocorrelation Test
/////////////////////////////////////
library(lmtest)
x<-read.csv('http://canisius.edu/~yany/data/ibmDaily.csv')
 n<-nrow(x)
 p<-x$Adj.Close
 ret<-p[2:n]/p[1:(n-1)]-1

 n2<-length(ret2)
 m<-as.integer(n2/2)
 x<-rep(c(-1,1),m)
 dwtest(ret[1:(2*m)]~x)

     Durbin-Watson test

data:  ret[1:(2 * m)] ~ x
DW = 1.452, p-value = 0.107
alternative hypothesis: true autocorrelation is greater than 0

/////////////////////////////////////

Dimension requirement for matrix manipulation 
/////////////////////////////////////

 Rule #1: addition:  A + B

         Matrices A and B should have the same dimensions

            A (n*m) and B (n *m)

         Note: A(n*m) means that matrix has n rows and m columns

 Rule #2: subtraction: A-B

         Matrices A and B should have the same dimensions

            A (n*m) and B (n *m)

 Rule #3: Multiplication : A * B

          The second dimension of the first  matrix should be the same as 
          the first  dimension of the second matrix
      
            A (n*k) and B (k *m)

/////////////////////////////////////

Grange Causality Test
/////////////////////////////////////
 A couses (leads to ) B              ----> (logic reason)

Existence of A could help explain B  --- > (Grange Causality) 

 The Granger causality test is a statistical hypothesis test for determining 
 whether one time series is useful in forecasting another, first proposed in 1969.

 Ordinarily, regressions reflect 'mere' correlations, but Clive Granger 
 argued that causality in economics could be tested for by measuring the 
 ability to predict the future values of a time series using prior values 
  of another time series. Since the question of 'true causality' 
 is deeply philosophical, and because of the post hoc ergo propter 
hoc fallacy of assuming that one thing preceding another can be used as 
 a proof of causation, econometricians assert that the Granger test finds
 only 'predictive causality'
   https://en.wikipedia.org/wiki/Granger_causality
/////////////////////////////////////