📄 modlgui.m
字号:
function modlgui(action,fighand)
%MODLGUI linear regression with graphical user interface.
% MODLGUI constructs linear regression models using a graphical
% user interface. Data, variable and sample scales, and variable
% and sample lables can be loaded from the workspace into the
% tool by using the MODL_File menu. Choice of regression method
% (PCR or PLS), scaling, and cross validation options can selected
% using the REGRESSION PARAMETERS window. Models can be calculated by
% by pressing the calc button. PRESS, scores, loadings, biplots
% and raw data can be viewed by clicking on the appropriate buttons.
% Models can be saved to the work space using the MODL_File menu,
% Models can be reloaded and used with new data. Models are saved
% as structured arrays with the following fields:
%
% xname: name of the original workspace input predictor block
% yname: name of the original workspace input predicted block
% date: model creation date stamp
% time: model creation time stamp
% reg: regresion vector(s)
% ypred: fits for the calibration Y-block
% wts: for NIP it is the X-block weights
% scores: X-block scores
% loads: X-block loadings
% ssq: sum of squares captured information
% rmsec: root mean squared error of calibration (fit error)
% rmsecv: root mean squared error of cross validation (cv error)
% meanx: means of the X-block
% meany: mean(s) of the Y-block
% stdx: standard deviations of the X-block
% stdy: standard deviation(s) of the Y-block
% press: cumulative prediction error sum of squares
% res: Q residuals
% reslim: 95% Q limit
% reseig: Eigenvalues of X-residuals
% yres: studentized residuals for the Y-block (fit error)
% tsq: T^2 values
% tsqlim: 95% T^2 limit
% lev: sample leverages
% irow: samples included in model
% icol: variables included in model
% drow: samples deleted from model
% dcol: variables deleted from model
% sscl: scale for plotting scores against
% vscl: scale for plotting loadings against
% slbl: sample labels
% slbln: sample labels original workspace name
% vlbl: variable labels
% vlbln: variable labels original workspace name
% scale: scaling used (e.g. 'auto')
% name: type of model, 'NIP, 'PCR', 'SIM'
% cv: cross validation method used
% split: number of times the data was split for cross validation
% iter: number of iterations for random cross validation
% samps: number of samples in original data
%
%I/O: modlgui
%
%See also: CROSSVAL, MODLRDER, MODLPRED, PCAGUI, PCR, PLS, SIMPLS, XPLDST
%Copyright Eigenvector Research, Inc. 1997-99
%nbg 6/97,7/97,12/97,1/98,5/98,9/98,10/98,12/98
%bmw 1/00
%nbg 10/00 changed table header and guisize, added ";" on line 920
if nargin<1
bgc0 = [0 0 0];
bgc1 = [1 0 1]*0.6;
bgc2 = [1 1 1]*0.85;
bgc3 = [1 1 1];
load pcaprefg
p = get(0,'ScreenSize');
ww = pcaprefg.moduser.widthheight(1); %380;
wh = pcaprefg.moduser.widthheight(2); %323;
a = figure('Color',bgc0,'Resize','on', ...
'Name','Linear Regression', ...
'HandleVisibility','off', ...
'NumberTitle','Off','Position',[6 p(4)-wh-40 ww wh]);
as = int2str(a);
% I/O Menu
b = zeros(3,1);
bb = zeros(14,1);
b(1,1) = uimenu(a,'Label','&MODL_File');
bb(1,1)= uimenu(b(1,1),'Label','&Load Data', ...
'CallBack',['modlgui(''loaddata'',',as,');']);
bb(2,1)= uimenu(b(1,1),'Label','&Load Model', ...
'CallBack',['modlgui(''loadmodl'',',as,');']);
b(3,1) = uimenu(b(1,1),'Label','&Load Scale','Enable','off');
bb(3,1)= uimenu(b(3,1),'Label','&Sample','Enable','off', ...
'CallBack',['modlgui(''loadsscl'',',as,');']);
bb(4,1)=uimenu(b(3,1),'Label','&Variable','Enable','off', ...
'CallBack',['modlgui(''loadvscl'',',as,');']);
b(2,1) = uimenu(b(1,1),'Label','&Load Labels','Enable','off');
bb(5,1)= uimenu(b(2,1),'Label','&Sample','Enable','off', ...
'CallBack',['modlgui(''loadslbl'',',as,');']);
bb(6,1)= uimenu(b(2,1),'Label','&Variable','Enable','off', ...
'CallBack',['modlgui(''loadvlbl'',',as,');']);
bb(7,1)= uimenu(b(1,1),'Label','&Save Data','Enable','off', ...
'CallBack',['modlgui(''savemat'',',as,');'],'Separator','on');
bb(12,1)= uimenu(b(1,1),'Label','&Save Test','Enable','off', ...
'CallBack',['modlgui(''savetst'',',as,');']);
bb(8,1)= uimenu(b(1,1),'Label','&Save Model','Enable','off', ...
'CallBack',['modlgui(''savemodl'',',as,');']);
bb(14,1)= uimenu(b(1,1),'Label','&Print Info','Enable','off', ...
'CallBack',['modlgui(''printssqtable'',',as,');']);
bb(13,1)= uimenu(b(1,1),'Label','&Preferences','Enable','on', ...
'CallBack',['prefpls(',as,');']);
bb(9,1)= uimenu(b(1,1),'Label','&Clear Data','Enable','off', ...
'CallBack',['modlgui(''cleardata'',',as,');'],'Separator','on');
bb(10,1)= uimenu(b(1,1),'Label','&Clear Model','Enable','off', ...
'CallBack',['modlgui(''clearmodl'',',as,');']);
bb(11,1)=uimenu(b(1,1),'Label','&Exit MODLGUI', ...
'CallBack',['modlgui(''exitmodl'',',as,');'],'Separator','on');
% Internal StatusBar
d = zeros(4,1);
e = zeros(8,1);
d(1,1) = uicontrol('Parent',a,'Style','frame', ...
'Units','normalized','Position', ...
[0.0263158 0.736842 0.947368 0.250774]);
% Variance Captured List/text
d(2,1) = uicontrol('Parent',a,'Style','frame', ...
'Units','normalized','Position', ...
[0.0263158 0.0309598 0.778947 0.696594]);
s = str2mat(...
' Percent Variance Captured by Model', ...
' X-Block Y-Block', ...
' Latent This This', ...
'Variable LV Cum LV Cum');
e(1,1) = uicontrol('Parent',a, ...
'Units','normalized','Position', ...
[0.0342105 0.482972 0.763158 0.170279], ...
'HorizontalAlignment','left', ...
'String',s,'Style','text', ...
'FontName',pcaprefg.moduser.tableheader.FontName, ...
'FontUnits',pcaprefg.moduser.tableheader.FontUnits, ...
'FontSize',pcaprefg.moduser.tableheader.FontSize, ...
'FontWeight',pcaprefg.moduser.tableheader.FontWeight, ...
'FontAngle',pcaprefg.moduser.tableheader.FontAngle, ...
'UserData','%3.0f %6.2f %6.2f %6.2f %6.2f');
e(2,1) = uicontrol('Parent',a, ...
'Units','normalized','Position', ...
[0.0342105 0.659443 0.271053 0.055728], ...
'String','No. LVs Selected:', ...
'HorizontalAlignment','center','FontWeight','bold', ...
'Style','text','FontName','geneva','Fontsize',10);
e(3,1) = uicontrol('Parent',a, ...
'Units','normalized','Position', ...
[0.313158 0.659443 0.131579 0.061920], ...
'FontSize',10,'FontName','geneva','FontWeight','bold', ...
'String',' ','Style','edit', ...
'Callback',['modlgui(''actssq2'',',as,');'], ...
'TooltipString','edit to select number of latent variables');
e(4,1) = uicontrol('Parent',a,'BackgroundColor',bgc3, ...
'Units','normalized','Style','listbox','String',[], ...
'Position',[0.034211 0.040248 0.76315 0.433437], ...
'FontName',pcaprefg.moduser.tablebody.FontName, ...
'FontUnits',pcaprefg.moduser.tablebody.FontUnits, ...
'FontSize',pcaprefg.moduser.tablebody.FontSize, ...
'FontWeight',pcaprefg.moduser.tablebody.FontWeight, ...
'FontAngle',pcaprefg.moduser.tablebody.FontAngle, ...
'HorizontalAlignment','left', ...
'SelectionHighlight','off','Value',1, ...
'Callback',['modlgui(''actssq'',',as,');']);% , ...
%'TooltipString','click to select number of latent variables');
%Text for internal status bar
s = str2mat('Data: none loaded');
e(5,1) = uicontrol('Parent',a,'BackgroundColor',bgc3, ...
'Units','normalized','Position', ...
[0.034211 0.746130 0.461842 0.232198], ...
'HorizontalAlignment','left', ...
'Style','text','String',s, ...
'FontName',pcaprefg.moduser.statwindow.FontName, ...
'FontUnits',pcaprefg.moduser.statwindow.FontUnits, ...
'FontSize',pcaprefg.moduser.statwindow.FontSize, ...
'FontWeight',pcaprefg.moduser.statwindow.FontWeight, ...
'FontAngle',pcaprefg.moduser.statwindow.FontAngle);
s = ['Model: none loaded'];
e(6,1) = uicontrol('Parent',a,'BackgroundColor',bgc3, ...
'Units','normalized','Position', ...
[0.503947 0.746130 0.461842 0.232198], ...
'HorizontalAlignment','left', ...
'Style','text','String',s, ...
'FontName',pcaprefg.moduser.statwindow.FontName, ...
'FontUnits',pcaprefg.moduser.statwindow.FontUnits, ...
'FontSize',pcaprefg.moduser.statwindow.FontSize, ...
'FontWeight',pcaprefg.moduser.statwindow.FontWeight, ...
'FontAngle',pcaprefg.moduser.statwindow.FontAngle);
if strcmp(lower(computer),'mac2')
s = str2mat(...
' Percent Variance Captured by Model', ...
' X-Block Y-Block', ...
' This This', ...
' LV LV Cum LV Cum');
set(e(1,1),'String',s, ...
'UserData',' %3.0f %6.2f %6.2f %6.2f %6.2f')
end
e(7,1) = uicontrol('Parent',a,'BackgroundColor',bgc3, ...
'Units','normalized','Position', ...
[0.503947 0.659443 0.293421 0.055728], ...
'String','show parameters', ...
'HorizontalAlignment','center','FontWeight','bold', ...
'Style','text','FontName','geneva','Fontsize',10);
e(8,1) = uicontrol('Parent',a,'Style','checkbox', ...
'Value',1,'Units','normalized','Position', ...
[0.453947 0.662539 0.042105 0.049536], ...
'BackgroundColor',bgc1,'ForegroundColor',bgc3, ...
'Callback',['modlgui(''showp'',',as,');']);
% Buttons
d(3,1) = uicontrol('Parent',a, ...
'Units','normalized','Position', ...
[0.810526 0.544892 0.160526 0.1826623],'Style','frame');
d(4,1) = uicontrol('Parent',a, ...
'Units','normalized','Position', ...
[0.810526 0.030960 0.160526 0.507740],'Style','frame');
c = uicontrol('Parent',a, ...
'BackgroundColor',bgc1,'ForegroundColor',bgc3, ...
'Style','text','Units','normalized','Position', ...
[0.818421 0.464396 0.144737 0.061920], ...
'FontName',pcaprefg.moduser.buttons.FontName, ...
'FontUnits',pcaprefg.moduser.buttons.FontUnits, ...
'FontSize',pcaprefg.moduser.buttons.FontSize, ...
'FontWeight',pcaprefg.moduser.buttons.FontWeight, ...
'FontAngle',pcaprefg.moduser.buttons.FontAngle, ...
'String','plots');
f = zeros(7,1);
f(1,1) = uicontrol('Parent',a, ...
'CallBack',['modlgui(''calculate'',',as,');'], ...
'Units','normalized','Position', ...
[0.818421 0.640867 0.1447368 0.077399],'String','calc', ...
'TooltipString','calculate regression model');
f(2,1) = uicontrol('Parent',a, ...
'CallBack',['modlgui(''apply'',',as,');'], ...
'Units','normalized','Position', ...
[0.818421 0.554180 0.1447368 0.077399],'String','apply', ...
'TooltipString','apply regression model');
f(3,1) = uicontrol('Parent',a, ...
'CallBack',['modlplt1(''plotscree'',',as,');'], ...
'Units','normalized','Position', ...
[0.818421 0.386997 0.1447368 0.077399],'String','press', ...
'TooltipString','plot cross-validation results');
f(4,1) = uicontrol('Parent',a, ...
'CallBack',['modlplts(''plotscores'',',as,');'], ...
'Units','normalized','Position', ...
[0.818421 0.300310 0.1447368 0.077399],'String','scores', ...
'TooltipString','plot scores, predictions and sample statistics');
f(5,1) = uicontrol('Parent',a, ...
'CallBack',['modlplts(''plotloads'',',as,');'], ...
'Units','normalized','Position', ...
[0.818421 0.21362 0.1447368 0.077399],'String','loads', ...
'TooltipString','plot loads, regression coef and variable statistics');
f(6,1) = uicontrol('Parent',a, ...
'CallBack',['modlplt1(''biplot'',',as,');'], ...
'Units','normalized','Position', ...
[0.818421 0.126935 0.1447368 0.077399],'String','biplot', ...
'TooltipString','plot scores and loadings biplots');
f(7,1) = uicontrol('Parent',a, ...
'CallBack',['modlplt1(''rawplot'',',as,');'], ...
'Units','normalized','Position', ...
[0.818421 0.040248 0.1447368 0.077399],'String','data', ...
'TooltipString','plot raw data');
%Set common properties
set(d(1:length(d),1),'BackgroundColor',bgc1)
set(e(1:length(e),1),'BackgroundColor',bgc3)
set(f(1:length(f),1),'BackgroundColor',bgc2, ...
'FontName',pcaprefg.moduser.buttons.FontName, ...
'FontUnits',pcaprefg.moduser.buttons.FontUnits, ...
'FontSize',pcaprefg.moduser.buttons.FontSize, ...
'FontWeight',pcaprefg.moduser.buttons.FontWeight, ...
'FontAngle',pcaprefg.moduser.buttons.FontAngle, ...
'Enable','off')
[p2,e2,f2] = regset(a);
set(a,'CloseRequestFcn',['modlgui(''exitmodl'',',as,');'])
%Assign Handles
stat.data = 'none';
stat.modl = 'none';
modl = [];
test = [];
set(a,'UserData',d) %Frame Handles
set(d(1,1),'UserData',b) %UIMenu Handles
set(d(2,1),'UserData',e) %Text Handles
set(d(3,1),'UserData',f) %Button Handles
set(e(7,1),'UserData',e2) %Params Slider/Popups
set(e(8,1),'UserData',p2) %Params Window
set(p2,'UserData',f2) %Slider Text Values
set(b(3,1),'UserData',bb) %SubMenu Handles
set(b(1,1),'UserData',stat)
set(f(2,1),'UserData',modl)
set(f(5,1),'UserData',test)
modlgui('cleardata',a);
modlgui('clearmodl',a);
figure(a)
else
%Get handles
d = get(fighand,'UserData'); %Frame Handles
a = get(d(1,1),'Parent');
as = int2str(a);
b = get(d(1,1),'UserData'); %UIMenu Handles
e = get(d(2,1),'UserData'); %Text Handles
f = get(d(3,1),'UserData'); %Button Handles
x = get(f(1,1),'UserData'); %X-block data
y = get(f(7,1),'UserData'); %Y-block data
stat = get(b(1,1),'UserData'); %Data/Model Status
modl = get(f(2,1),'UserData'); %Model
test = get(f(5,1),'UserData'); %Test Data
p2 = get(e(8,1),'UserData'); %Params Widow
e2 = get(e(7,1),'UserData'); %Params Slider/Popups
f2 = get(p2,'UserData'); %Slider Text Values
bb = get(b(3,1),'UserData'); %SubMenu Handles
%CallBacks
switch lower(action)
case 'loaddata'
if strcmp(stat.modl,'none')
lddlgpls(f(1,1),d(4,1),'double','cal X-block')
x = get(f(1,1),'UserData');
if size(x,1)>0&size(x,2)>0
lddlgpls(f(7,1),f(6,1),'double','cal Y-block')
y = get(f(7,1),'UserData');
end
if isempty(x)|isempty(y)
modlgui('cleardata',a);
elseif size(x,1)~=size(y,1)
erdlgpls('number of samples in X and Y must be equal', ...
'Error on Load Data!')
modlgui('cleardata',a);
elseif size(x,1)==1|size(x,2)==1
erdlgpls('X-block must be a matrix','Error on Load Data!')
modlgui('cleardata',a);
elseif ~isempty(find(isinf(x)))|~isempty(find(isnan(x)))
erdlgpls('X-block contains "inf" or "NaN" please see mdpca', ...
'Error on Load Data!')
modlgui('cleardata',a);
elseif ~isempty(find(isinf(y)))|~isempty(find(isnan(y)))
erdlgpls('Y-block contains "inf" or "NaN" please see mdpca', ...
'Error on Load Data!')
modlgui('cleardata',a);
else
stat.data = 'new';
if strcmp(stat.modl,'none')
modl.xname = get(d(4,1),'UserData');
modl.yname = get(f(6,1),'UserData');
modl.irow = 1:size(x,1);
modl.icol = 1:size(x,2);
s = min(size(x)');
s = min([size(x) 40 rank(x)]');
set(f2(4,1),'String',int2str(s))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -