'SPSS vs R, Why fitted values of SMA are different?

In SPSS, fitted value of SMA(order=4) as follows:

 Yt     Year Quarter  Date   Y_fit
98.7    2004    1   Q1 2004 
98.6    2004    2   Q2 2004 
100.6   2004    3   Q3 2004 
99.5    2004    4   Q4 2004 
100.1   2005    1   Q1 2005  99.35
98.9    2005    2   Q2 2005  99.70
101.0   2005    3   Q3 2005  99.78
100.0   2005    4   Q4 2005  99.88
99.6    2006    1   Q1 2006  100.00
98.7    2006    2   Q2 2006  99.88
101.1   2006    3   Q3 2006  99.83
100.1   2006    4   Q4 2006  99.85
101.0   2007    1   Q1 2007  99.88
100.6   2007    2   Q2 2007  100.23
103.2   2007    3   Q3 2007  100.70
102.8   2007    4   Q4 2007  101.23
102.9   2008    1   Q1 2008  101.90
104.4   2008    2   Q2 2008  102.38
106.1   2008    3   Q3 2008  103.32
105.5   2008    4   Q4 2008  104.05

In R, fitted value of SMA(order=4) as follows:

gdp=ts(data$Yt, frequency=4, start=c(2004,1))
SMA(gdp, n=4)
         Qtr1    Qtr2    Qtr3    Qtr4
 2004      NA      NA      NA  99.350
 2005  99.700  99.775  99.875 100.000
 2006  99.875  99.825  99.850  99.875
 2007 100.225 100.700 101.225 101.900
 2008 102.375 103.325 104.050 104.725

I mean, why the number of NA is different? The values of R is pulled by one space.

If I enter that the order is 5 in R, the number of NA is 4 like SPSS. However the fitted values are different from values of SPSS.

I know the moving average.. that if order is 4,(t1+t2+t3+t4/4) is t5. But in R it seems to be (t1+t2+t3+t4/4)=t4.

Also, cma(data, n=4) in R, the result don't have NA. But the result of SPSS have 4 NA(2 in the front, 2 in the back).

  1. Result of SPSS, cma(data, n=4). Y_fit2 is fitted values.

    Yt     Year Quarter  Date    Y_fit1  Y_fit2
    98.7     2004    1   Q1 2004         
    98.6     2004    2   Q2 2004     
    100.6    2004    3   Q3 2004          99.52
    99.5     2004    4   Q4 2004          99.74
    100.1    2005    1   Q1 2005  99.35   99.83
    98.9     2005    2   Q2 2005  99.70   99.94
    101.0    2005    3   Q3 2005  99.78   99.94
    100.0    2005    4   Q4 2005  99.88   99.85
    99.6     2006    1   Q1 2006  100.00  99.84
    98.7     2006    2   Q2 2006  99.88   99.86
    101.1    2006    3   Q3 2006  99.83   100.05
    100.1    2006    4   Q4 2006  99.85   100.46
    101.0    2007    1   Q1 2007  99.88   100.96
    100.6    2007    2   Q2 2007  100.23  101.56
    103.2    2007    3   Q3 2007  100.70  102.14
    102.8    2007    4   Q4 2007  101.23  102.85
    102.9    2008    1   Q1 2008  101.90  103.69
    104.4    2008    2   Q2 2008  102.38  104.39
    106.1    2008    3   Q3 2008  103.32 
    105.5    2008    4   Q4 2008  104.05 
    
  2. Result of R, cma(data, n=4)

    cma(gdp, order=4)$fitted
               Qtr1      Qtr2      Qtr3      Qtr4
       2004  99.11958  99.20039  99.35312  99.52500
       2005  99.73750  99.82500  99.93750  99.93750
       2006  99.85000  99.83750  99.86250 100.05000
       2007 100.46250 100.96250 101.56250 102.13750
       2008 102.85000 103.68750 104.38750 104.91094
    

So, can we say that the result of SPSS and the result of R are the same?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source