function New_sigma2=Error_Var_Updater(Current_Complete_Data, FAC_ARRAY_Sum, CURRENT_PARS, PRIORS)
% function New_sigma2=Error_Var_Updater(Current_Complete_Data, FAC_ARRAY_Sum, CURRENT_PARS, PRIORS)
% Updates the error variance. 

% First deal with the first parameter - alpha
alpha_post=numel(Current_Complete_Data)/2+PRIORS.sigma2(1);

% Now get the sum of squares between the Current_Complete_Data and
% (FAC_ARRAY_Sum + Grand Mean);
squared_diff_array=(Current_Complete_Data - (FAC_ARRAY_Sum+CURRENT_PARS.GM)).^2;
%sum them:
sum_squares=sum(squared_diff_array(:));

% can now calculate the posterior beta:
beta_post=(1/2)*sum_squares + PRIORS.sigma2(2);

% and now make the draw:
New_sigma2=1/randraw('gamma', [0,1/beta_post, alpha_post], [1,1]);