均值变点是统计学中常用的变点分析方法,其主要思想如下:
假设有一组数据,随着某个指标变化(增大),其值逐渐增加并趋于稳定,如何判断在这个过程中是否出现了突变的情况,异样的情况?
均值变点分析方法提供了一种思路,大概如下:
1 计算总的均值和方差;
2 循环将这组有序数据分成两组,X1,X2
计算各组的均值和方差,
计算总方差与分组方差之和的差;
3 得到变点
1 function pos = meanChangePoint(X) 2 % X = [0 X]; 3 len = length(X); 4 if(len<2) 5 pos = -1; 6 return; 7 end 8 meanT = mean(X); 9 meanT = repmat(meanT,1,size(X,2)); 10 stdT = sum((X - meanT).^2); 11 resS = []; 12 for i = 2:len 13 mean1 = mean(X(1:i-1)); 14 vecmean1 = repmat(mean1,1,i-1); 15 mean2 = mean(X(i:len)); 16 vecmean2 = repmat(mean2,1,len - i +1); 17 stdI = sum((X(1:i-1) - vecmean1).^2) + sum((X(i:len) - vecmean2).^2); 18 tmp = stdT - stdI; 19 resS = [resS tmp]; 20 end 21 [~,pos] = max(resS); 22 end
放松不放纵--忙碌不盲目