📄 da_plsgo.m
字号:
%
% mv_pcrgo.m
%
% Gets all the parameters for the principal
% components regression subprogramme
%
%
% Separate input and output variables
%
y=data(:,output_var & include_var);
x=pcincl(data,include_var,output_var);
%
% Scale the data
%
[y my sdy]=mcen(y);
[x mx sdx]=mcen(x);
%
% Split the data correctly
%
%
% Check radio button 4 for the percentage partition
%
if get(pcr_rad4,'Value') == 1
[tx ty vx vy]=psplit(x,y,get(pcr_rad4sl,'Value'));
end
%
% Check radio button 5 for the random partition
%
if get(pcr_rad5,'Value') == 1
disp('Bollocks')
[tx ty vx vy]=rsplit(x,y,get(pcr_rad5sl,'Value'));
end
%
% Check radio button 6 for the block splitting
%
if get(pcr_rad6,'Value') == 1
[tx ty vx vy]=bsplit(x,y,ceil(get(pcr_rad6sl,'Value')));
end
%
% Check radio button 7 for alternate split
%
if get(pcr_rad7,'Value') == 1
[tx ty vx vy]=asplit(x,y);
end
%
% Check radio button 1 for include number of latent variables
%
if get(pcr_rad1,'Value') == 1
%
% Determine number of latent varibles to include
%
lv=ceil(get(sl2,'Value'));
%
% Calculate scores etc
%
[P Q W T U b ssq]=pls(tx,ty,lv);
%
% Calculate predicted y based on this information
%
py=plspred(vx,b,P,Q,W,lv);
%
% Convert the pls model to a regression vector
% which gives the impact of each variable
%
impact=conpred1(b,W,P,Q,lv);
%
% Delete the pls model to save memory
%
clear P Q W b ssq
end
%
% Include the optimum number of latent variables
%
if get(pcr_rad3,'Value') == 1
%
% maximum number of latent variables = number of variables
% included in the analysis -1 (output variables)
%
max_lv=sum(include_var)-sum(output_var);
%
% Build a pls model using this number of lv's
%
[P Q W T U b ssq]=pls(tx,ty,max_lv);
%
% Progressively increase the number of lv's to
% find the minimum sse
%
max_err=1e100;
for i = 1 : max_lv
py=plspred(vx,b,P,Q,W,i);
e=sse(py,vy);
if e < max_err
max_err=e;
best_lv=i;
best_py=py;
acty=plspred(tx,b,P,Q,W,i);
impact=conpred1(b,W,P,Q,i);
end
end
py=best_py;
lv=best_lv;
%
% Now clear the model out of memory
%
clear P Q b ssq best_lv best_py max_err max_lv e
acty=rescale(acty,my,sdy);
end
%
% Rescale the data
%
%tx=rescale(tx,mx,sdx);
ty=rescale(ty,my,sdy);
%vx=rescale(vx,mx,sdx);
vy=rescale(vy,my,sdy);
py=rescale(py,my,sdy);
%
% Print the results in the little blue box at the top of the screen
%
[D L]=size(vy);
e=((sse(vy(:,1),py(:,1)).^0.5)/D)/my(1);
c=corrcoef(vy(:,1),py(:,1));
c=c(2,1);
regv=impact;
impact=impact';
text1=uicontrol(w1,...
'Style','text',...
'Position',[275 385 130 15],...
'BackGroundColor',[0 0 1],...
'ForeGroundColor',[1 1 1],...
'String',['Error = ' num2str(e)]);
text2=uicontrol(w1,...
'Style','text',...
'Position',[275 365 145 15],...
'BackGroundColor',[0 0 1],...
'ForeGroundColor',[1 1 1],...
'String',['Latent variables = ' num2str(lv)]);
text3=uicontrol(w1,...
'Style','text',...
'Position',[410 385 130 15],...
'BackGroundColor',[0 0 1],...
'ForeGroundColor',[1 1 1],...
'String',['Correlation = ' num2str(c)]);
%
% Save results button
%
sl1_value=1;
pca_but2=uicontrol(w1,...
'Style','push',...
'Position',[380 10 100 20],...
'String','More detail',...
'CallBack',[...
'py=py(:,sl1_value);',...
'vy=vy(:,sl1_value);',...
'impact=impact(sl1_value,:);',...
'da_det1;']);
clear x y regv
if sum(output_var) > 1
set(text4,'visible','on');
set(text5,'visible','on');
set(sl1,'visible','on','enable','on');
sl1_value=1;
old_sl1_value=1;
set(sl1,'value',1);
set(text4,'string','Viewing output variable 1');
end
%
% Button to plot U v T
%
%but4=uicontrol(w1,...
% 'Style','push',...
% 'Position',[500 10 100 20],...
% 'String','U v T plot',...
% 'CallBack','da_plsut;');
pca_but3=uicontrol(w1,...
'style','push',...
'position',[500 10 100 20],...
'string','Save model',...
'callback',[...
'[D L]=size(tx);',...
'out=svlin2('''',include_var,sdx,mx,sdy,my,impact,ones(L,1),zeros(L,1))']);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -