% 20061121 %% Exempel 8.22 i Montgomerys bok % (c) Jan Rohlén % Exemplet skall illustrera EWMA % Data X=[ 953 945 972 945 975 970 959 973 940 936 985 973 955 950 948 957 940 933 965 973 949 941 966 966 934 937 946 952 935 941 937 946 954 935 941 933 960 968 959 956 959 939 948 958 963 973 949 942 965 962 948 937 955 927 940 962 963 943 950 938 958 955 947 941 938 945 963 967 969 981 952 931 928 937 950 970 933 960 934 927 ]; % Vi antar att Mu0=950; %Sigma0=std(X); Sigma0=mean(abs(diff(X)))/1.128 %% Börjar med att rita ett Shewhartdiagram close all hidden %% Konstruera CUMSUM K=0.5*Sigma0; H=5*Sigma0; CP=[0,0]; CM=[0,0]; for k=1: length(X) NP=CP(k,2); CP_new=max(0,X(k)-(Mu0+K)+CP(k,1)); if CP_new>0 NP=NP+1; else NP=0; end CP=[CP; CP_new , NP]; NM=CM(k,2); CM_new=max(0,(Mu0-K)-X(k)+CM(k,1)); if CM_new>0 NM=NM+1; else NM=0; end CM=[CM; CM_new , NM]; % CP=[CP,max(0,X(k)-(Mu0+K)+CP(length(CP)))]; % CM=[CM,max(0,(Mu0-K)-X(k)+CM(length(CM)))]; end figure plot(CP(:,1),'o-k','MarkerFaceColor','b') hold plot(-CM(:,1),'o-k','MarkerFaceColor','g') plot(find(CM(:,1)==-CP(:,1)),find(CM(:,1)==-CP(:,1))*0,'o','MarkerFaceColor','w') plot(X*0+H*1,'r') plot(X*0-H*1,'r') ylabel('CumSum','FontSize',12) xlabel('Provnummer','FontSize',12) title('Ex. 8-1 Tabell-Cumsum','FontSize',18) legend('Positiv CumSUM','Negativ CumSum') %% Konstruera EWMA-plot L=0.4; % Parametern Lambda z=Mu0; % Initiera for i=1: length(X) z=[z;L*X(i)+(1-L)*z(length(z))]; UCL(i)=Mu0+ 3*sqrt(L/(2-L)*(1-(1-L).^(2*i)))*Sigma0; LCL(i)=Mu0- 3*sqrt(L/(2-L)*(1-(1-L).^(2*i)))*Sigma0; CL(i)=Mu0; end z(1)=[]; figure hold plot(z,'o-k','MarkerFaceColor','b') k=(0.5:1:length(X))'; stairs(k,UCL,'r') stairs(k,LCL,'r') plot(CL,'r--') title('Ex 8-1: EWMA styrdiagram, L=3.0 och \lambda=0.4','FontSize',18)