我的SIMCA毕设MATLAB编程文档格式.docx
《我的SIMCA毕设MATLAB编程文档格式.docx》由会员分享,可在线阅读,更多相关《我的SIMCA毕设MATLAB编程文档格式.docx(8页珍藏版)》请在冰豆网上搜索。
y3=(x3-m3)./s3;
y4=(x4-m4)./s4;
%将各组数据进行主成分分析
[p1,princ1,eigenvalue1,t21]=princomp(y1);
[p2,princ2,eigenvalue2,t22]=princomp(y2);
[p3,princ3,eigenvalue3,t23]=princomp(y3);
[p4,princ4,eigenvalue4,t24]=princomp(y4);
%[特征向量,主成分得分特征值t2检验]=princomp(标准化原始数据)
cor1=corrcoef(y1);
cor2=corrcoef(y2);
cor3=corrcoef(y3);
cor4=corrcoef(y4);
%计算相关系数矩阵
[vec1,val1]=eig(cor1);
[vec2,val2]=eig(cor2);
[vec3,val3]=eig(cor3);
[vec4,val4]=eig(cor4);
%求X标准化的协差矩阵的特征向量和特征根
newval1=diag(val1);
newval2=diag(val2);
newval3=diag(val3);
newval4=diag(val4);
[px1,sy1]=sort(newval1);
[px2,sy2]=sort(newval2);
[px3,sy3]=sort(newval3);
[px4,sy4]=sort(newval4);
%对特征值进行排序px为排序结果sy为索引
eigenvalue1;
eigenvalue2;
eigenvalue3;
eigenvalue4;
%输出相关矩阵的各特征值
per1=100*eigenvalue1/sum(eigenvalue1);
per2=100*eigenvalue2/sum(eigenvalue2);
per3=100*eigenvalue3/sum(eigenvalue3);
per4=100*eigenvalue4/sum(eigenvalue4);
%求出各个主成分的贡献率
figure(11)
pareto(per1);
xlabel('
1主成分'
)
ylabel('
1方差占的比重%'
figure(12)
pareto(per2);
2主成分'
2方差占的比重%'
figure(13)
pareto(per3);
3主成分'
3方差占的比重%'
figure(14)
pareto(per4);
4主成分'
4方差占的比重%'
)%将贡献率绘成直方图如何调整横轴显示个数
cums1=cumsum(per1);
cums2=cumsum(per2);
cums3=cumsum(per3);
cums4=cumsum(per4);
%求出各个主成分的累计贡献率
figure(21)
plot(eigenvalue1,'
r+'
);
figure(22)
plot(eigenvalue2,'
figure(23)
plot(eigenvalue3,'
figure(24)
plot(eigenvalue4,'
%绘制方差贡献散点图纵轴为什么是400%
holdon%图形上每次绘制的点都能继续保持
figure(31)
g-'
figure(32)
figure(33)
figure(34)
%绘制方差贡献山麓图
holdoff%关闭图形
%按照累计贡献率准则循环验证取各式样组的主成分个数
sumrate=0;
i1=0
whilesumrate<
85;
i1=i1+1;
sumrate=sumrate+per1(i1);
end
k1=i1%按累计贡献率准则记下第一组中累计贡献率达到85%的特征值的个数
i2=0
i2=i2+1;
sumrate=sumrate+per2(i2);
k2=i2%按累计贡献率准则记下第二组中累计贡献率达到85%的特征值的个数
i3=0
i3=i3+1;
sumrate=sumrate+per3(i3);
k3=i3%按累计贡献率准则记下第三组中累计贡献率达到85%的特征值的个数
i4=0
i4=i4+1;
sumrate=sumrate+per4(i4);
k4=i4%按累计贡献率准则记下第四组中累计贡献率达到85%的特征值的个数
p11=p1(:
1:
k1);
p22=p2(:
k2);
p33=p3(:
k3);
p44=p4(:
k4);
%提取前k个主成分系数
sc11=princ1(:
sc22=princ2(:
sc33=princ3(:
sc44=princ4(:
%提出前k个主成分得分值
figure(41)
plot3(princ1(:
1),princ1(:
2),princ1(:
3),'
gridon
pc1'
pc2'
zlabel('
pc3'
%主成分分析显示线性投影坐标图
figure(42)
plot3(princ2(:
1),princ2(:
2),princ2(:
figure(43)
plot3(princ3(:
1),princ3(:
2),princ3(:
figure(44)
plot3(princ4(:
1),princ4(:
2),princ4(:
p1sce1=p1(:
1);
df1sce1=princ1(:
p1sce2=p1(:
2);
df1sce2=princ1(:
p1sce3=p1(:
3);
df1sce3=princ1(:
p1sce4=p1(:
4);
df1sce4=princ1(:
p1sce5=p1(:
5);
df1sce5=princ1(:
p1sce6=p1(:
6);
df1sce6=princ1(:
p1sce7=p1(:
7);
df1sce7=princ1(:
p1sce8=p1(:
8);
df1sce8=princ1(:
p1sce9=p1(:
9);
df1sce9=princ1(:
Esce1=y1-df1sce1*p1sce1'
-df1sce2*p1sce2'
-df1sce3*p1sce3'
-df1sce4*p1sce4'
-df1sce5
*p1sce5'
-df1sce6*p1sce6'
-df1sce7*p1sce7'
-df1sce8*p1sce8'
-df1sce9*p1sce9'
Esce11=Esce1.*Esce1;
Dsce1=sum(sum(Esce11))*(1/(19-9-1)/(751-9));
p2sce1=p2(:
df2sce1=princ2(:
p2sce2=p2(:
df2sce2=princ2(:
p2sce3=p2(:
df2sce3=princ2(:
Esce2=y2-df2sce1*p2sce1'
-df2sce2*p2sce2'
-df2sce3*p2sce3'
Esce22=Esce2.*Esce2;
Dsce2=sum(sum(Esce22))*(1/(12-3-1)/(751-3));
p3sce1=p3(:
df3sce1=princ3(:
p3sce2=p3(:
df3sce2=princ3(:
p3sce3=p3(:
df3sce3=princ3(:
p3sce4=p3(:
df3sce4=princ3(:
p3sce5=p3(:
df3sce5=princ3(:
p3sce6=p3(:
df3sce6=princ3(:
p3sce7=p3(:
df3sce7=princ3(:
p3sce8=p3(:
df3sce8=princ3(:
p3sce9=p3(:
df3sce9=princ3(:
p3sce10=p3(:
10);
df3sce10=princ3(:
p3sce11=p3(:
11);
df3sce11=princ3(:
p3sce12=p3(:
12);
df3sce12=princ3(:
Esce3=y3-df3sce1*p3sce1'
-df3sce2*p3sce2'
-df3sce3*p3sce3'
-df3sce4*p3sce4'
-df3sce5
*p3sce5'
-df3sce6*p3sce6'
-df3sce7*p3sce7'
-df3sce8*p3sce8'
-df3sce9*p3sce9'
-df3sce1
0*p3sce10'
-d