%%% Compute SSE when alpha=1


function [sse, r, error_mean,error_std]=SSE4(data, alpha, New_Plant)


%%% Change alpha to w

   w=1-alpha;
   
   z=data;
   
%%% Compute sample size of data

   n=length(z);
   
%%% Compute the ordinary least estimate of beta, Let it as an initial estimate of beta_0 
%%% 
    
 X=[ones(n,1) (1:n)'];

t=(1:n)';

for i=1:3
    
  X=[X (mod((1:n)',4)==i) ];
 
end

beta_int=inv(X'*X)*X'*z;

%%%% Construct Matrix L and f(0)

L=[1 0 0 0 0 ; 1 1 0 0 0;1 0 -1 -1 -1; 0  0 1 0 0; 0 0 0 1 0];

f_0=[1 0 0 0 0]';

%%%% Compute Matrix F using limited value of F when alpha=1 and n tend to
%%%% infinite 

t=(-10000:1:0)';

f_ast=[1 1/4 -1/4 -2/4 -3/4]';

%%%% Update estimate of beta and compete one step forecast estimate
    
beta_old=beta_int;
   

n_old=n;

z=log(New_Plant');

n=length(z);

f_1=[1 1 1 0 0];


z_pred=zeros(n+1,1);

z_pred(1)=f_1*beta_int;



for i=1:n
              
       
 %%%%% Updating the estimate of beta

       beta(:,i)=L'*beta_old+f_ast*(z(i)-z_pred(i));
              
 %%%%% Updating one step forecast
       
       z_pred(i+1)=f_1*beta(:,i);
       
       beta_old=beta(:,i);
       
 end
   
 forecast_error=zeros(n,1);
   
  %%% Compute forecast error 
  
 forecast_error(1:n)=z(1:n)-z_pred(1:n);
   
  %%% Compute SSE
  
 sse=sum(forecast_error(1:n_old).^2);
  
  %%% Compute mean of forecast error
  
 error_mean=mean(forecast_error);
   
  %%% Compute standard deviation of the estimate of mean of forecast error
  
 error_std=std(forecast_error)/sqrt(n);
   
  %%% Compute auto-correlation of the forecast error from lag=1 to lag=6
   
   r=zeros(1,8);
   
   for i=1:8 
   
        r(i)=auto_corr(forecast_error(1:n_old),i);
        
   end 
       


