% Calculates the lack-of-fit function [LOF] = calculateLOF(RSS,N,D,k,RSS0,nbetas) % RSS0 is equivalent to SS_{all} in thesis, and is basically the RSS with % only intercept in model. nbetas is the number of slope parameters in % the model. % k is the dimension of y (i.e. number of time points). T = N*k; % T is number of data points. LOF = RSS/(1-D/N)^2; %LOF = 0.5*RSS-D*log(N)/2; %m-BIC for variance unknown case. % mainpenaltyterm = -D*log(N)/2; % firstterm = ((T-nbetas+1)/2)*log(RSS0/RSS); % sumsq_overall_term = (nbetas/2)*log(RSS0); % gamma_term = gammaln((T-nbetas-1)/2) - gammaln((T-1)/2); % LOF= firstterm+sumsq_overall_term+gamma_term + mainpenaltyterm; % LOF=-LOF;