% This function calculates the effective number of parameters in the model. function [D,nbetas] = calculateEffectiveParameters(Xinmodel,peinmodel,N,T,lambda) Npe = length(peinmodel); nbetas=0; if isnan(lambda) % BIC-derived dimension for each change-point. D = log(N); % add 1 dim for intercept term. for i=1:Npe if containsInteractions(peinmodel{i}) % the ith predictor in model has change-point. % log(sum(Xinmodel(:,i)))/log(N) "effective dimensions" for % the slope parameter, and 2 "effective dimensions" for the % change-point parameter. D = D+log(sum(Xinmodel(:,i+1)))+2*log(N); nbetas=nbetas+2; else % the ith predictor in model is simple linear function. nbetas=nbetas+1; D = D+log(N); end end D = D/log(N); else % hard-coded dimension (value=lambda) for each change-point. D = Npe+1; % start off with 1 dimension for each slope parameter. for i=1:Npe if containsInteractions(peinmodel{i}) % the ith predictor in model has change-point. D = D+lambda; nbetas=nbetas+2; else % the ith predictor in model is simple linear function. % in this case there is nothing to add. nbetas=nbetas+1; end end end D = T*D;