function ANOVA_visualization
%built by keith regner 11/2016 with R2014b (8.4 OSX)
clear all
close all

%% description
% This demo helps visualize how one-way analysis of variance (ANOVA) works 
% for three samples (I = 3) each with ten measurements (J1 = J2 = J3 = 10). 
% The data in each sample are shown as blue circles. The sample mean 
% (red circle), sample variances (green bars), grand mean (mean of the 
% sample means, shown with a dashed black line), and the difference 
% between each sample mean and the grand mean (orange bars) are shown 
% illustratively in the plot. The slider bars are used to change the 
% spread and offset of the ith sample.
% 
% The relative sizes of the treatment mean square (MSTr) and error mean 
% square (MSE) are shown in the lower left of the window. The MSTr is 
% proportional to the sum of the square of the length of the orange bars 
% and the MSE is proportional to the sum of the length of the green bars. 
% The F statistic is the ratio between the MSTr and MSE. The p-value is the 
% area to the right of the F statistic under the F-distribution shown in 
% the lower right of the window. In practice, one of the samples is 
% ?different? from the others if the p-value is less than 0.05 as indicated 
% in the lower plot window (?Dependence??).

%% create random data
b.data = rand([10,3])-.5;
b.xtot = 0:0.01:10;             %for F distribution plotting
slide_mino = -2.5;
slide_maxo = 2.5;
slide_mins = 0;
slide_maxs = 10;

%% sample properties
b.mean = mean(b.data);
b.std = std(b.data);
b.I = size(b.data,2);
b.J = size(b.data,1);
b.N = b.J*size(b.data,2);
b.nu1 = b.I - 1;
b.nu2 = b.N - b.I;
b.grand = sum(b.J*b.mean)/b.N;
b.SSTr = sum(b.J*((b.mean - b.grand).^2));
b.SSE = sum((b.J - 1)*(b.std.^2));
b.MSTr = b.SSTr/b.nu1;
b.MSE = b.SSE/b.nu2;
b.F = b.MSTr/b.MSE;
b.pVal = 1 - fcdf(b.F,b.nu1,b.nu2);

%% plot
%define axes properties
b.fig = figure('Units','inches','Position',[5 .25 8 9],...
    'Name','ANOVA_visualization','NumberTitle','off');
b.ax1 = axes('Units','inches','Position',[1 3.7 6 5],'FontSize',12,...
    'LineWidth',1.5,'XLim',[0.5 3.5],'YLim',[-2 2],'Box','on','XTick',...
    [1 2 3],'XTickLabel',{'level 1 ({\iti} = 1, {\itJ}_1 = 10)',...
    'level 2 ({\iti} = 2), {\itJ}_2 = 10','level 3 ({\iti} = 3, {\itJ}_3 = 10)'});
hold on
b.ax1.XLabel.String = 'Factor';
b.ax1.YLabel.String = 'Dependent Variable';
b.ax2 = axes('Units','inches','Position',[4 .5 3 1.8],'FontSize',12,...
    'LineWidth',1.5,'XLim',[0 10],'YLim',[0 1],'Box','on','XTick',...
    [b.F],'XTickLabel',{'{\itF}'});
hold on
b.ax2.YLabel.String = '{\itF} ({\itx} | \nu_1,\nu_2)';

%plot data
b.d1 = plot(b.ax1,1*ones(b.J,1),b.data(:,1),'o','MarkerFaceColor',...
    [0 0.5 1],'MarkerEdgeColor',[0 0 0]);
b.d2 = plot(b.ax1,2*ones(b.J,1),b.data(:,2),'o','MarkerFaceColor',...
    [0 0.5 1],'MarkerEdgeColor',[0 0 0]);
b.d3 = plot(b.ax1,3*ones(b.J,1),b.data(:,3),'o','MarkerFaceColor',...
    [0 0.5 1],'MarkerEdgeColor',[0 0 0]);

%plot sample mean and grand mean
b.gm = plot(b.ax1,[0 4],[b.grand b.grand],'--k');
b.m1 = plot(b.ax1,1,b.mean(1),'o','MarkerFaceColor',[1 0 0],...
    'MarkerEdgeColor',[0 0 0]);
b.m2 = plot(b.ax1,2,b.mean(2),'o','MarkerFaceColor',[1 0 0],...
    'MarkerEdgeColor',[0 0 0]);
b.m3 = plot(b.ax1,3,b.mean(3),'o','MarkerFaceColor',[1 0 0],...
    'MarkerEdgeColor',[0 0 0]);

%plot f distribution
b.Ftot = fpdf(b.xtot,b.nu1,b.nu2);
b.xshade = b.F:.01:b.xtot(end);
b.Fshade = fpdf(b.xshade,b.nu1,b.nu2);
b.Fplot = plot(b.ax2,b.xtot,b.Ftot,'LineWidth',1.5,'Color',[0 0 0]);
b.shade = area(b.xshade,b.Fshade,'FaceColor',[0 0.5 1]);

%plot variances for each data set
b.d1var = plot(b.ax1,[.9 .9],[b.mean(1),b.mean(1)+(b.std(1)^2)],...
    'LineWidth',6,'Color',[0 0.5 0]);
b.d2var = plot(b.ax1,[1.9 1.9],[b.mean(2),b.mean(2)+(b.std(2)^2)],...
    'LineWidth',6,'Color',[0 0.5 0]);
b.d3var = plot(b.ax1,[2.9 2.9],[b.mean(3),b.mean(3)+(b.std(3)^2)],...
    'LineWidth',6,'Color',[0 0.5 0]);

%plot sample mean - grand mean for each data set
b.d1gr = plot(b.ax1,[1.1 1.1],[b.mean(1),b.grand],'LineWidth',6,...
    'Color',[0.9 0.5 0]);
b.d2gr = plot(b.ax1,[2.1 2.1],[b.mean(2),b.grand],'LineWidth',6,...
    'Color',[0.9 0.5 0]);
b.d3gr = plot(b.ax1,[3.1 3.1],[b.mean(3),b.grand],'LineWidth',6,...
    'Color',[0.9 0.5 0]);

%% annotate and add UI control
%legend
b.varleg = annotation('line','Units','inches','Position',...
    [1.2 8.5 .15 0],'LineWidth',6,'Color',[0 0.5 0]);
b.txtboxvarleg = annotation('textbox','Units','inches','Position',...
    [1.4 8.18 4 .4],'String','variance within each sample ','FontSize',...
    12,'LineStyle','none');
b.grleg = annotation('line','Units','inches','Position',...
    [1.2 8.2 .15 0],'LineWidth',6,'Color',[0.9 0.5 0]);
b.txtboxgrleg = annotation('textbox','Units','inches','Position',...
    [1.4 7.88 4 .4],'String','sample mean - grand mean','FontSize',12,...
    'LineStyle','none');
b.leg1 = legend(b.ax1,[b.d1 b.m1 b.gm],...
    {'data','sample mean','grand mean'},'Location','NorthEast','Box',...
    'off','FontSize',12);

%F
b.txtboxF = annotation('textbox','Units','inches','Position',...
    [.6 .5 1 .4],'String','{\itF}   = ','FontSize',12,'LineStyle','none');
b.txtboxmstr1 = annotation('textbox','Units','inches','Position',...
    [1.1 .6 1 .4],'String','MSTr','FontSize',12,'LineStyle','none');
b.txtboxmse1 = annotation('textbox','Units','inches','Position',...
    [1.1 .4 1 .4],'String','MSE','FontSize',12,'LineStyle','none');
b.divide = annotation('line','Units','inches','Position',...
    [1.15 .83 .45 0],'LineWidth',.5,'Color',[0 0 0]);
b.txtboxFnum = annotation('textbox','Units','inches','Position',...
    [1.7 .5 1.5 .4],'String',['=   ' num2str(b.F)],'FontSize',12,...
    'LineStyle','none');

%MSE and MSTr
b.txtboxmstr2a = annotation('textbox','Units','inches','Position',...
    [.1 1.6 1 .4],'String','MSTr   = ','FontSize',12,'LineStyle','none');
b.txtboxmstr2b = annotation('textbox','Units','inches','Position',...
    [.88 1.71 1 .4],'String','$${\frac{J}{I-1}}\sum{\frac{}{}}$$',...
    'FontSize',12,'LineStyle','none','Interpreter','latex');
b.txtboxmse2a = annotation('textbox','Units','inches','Position',...
    [.1 1 1 .4],'String','MSE  = ','FontSize',12,'LineStyle','none');
b.txtboxmse2b = annotation('textbox','Units','inches','Position',...
    [.8 1.11 1 .4],'String','$${\frac{J-1}{N-I}}\sum{\frac{}{}}$$',...
    'FontSize',12,'LineStyle','none','Interpreter','latex');
b.txtboxmstrnum = annotation('textbox','Units','inches','Position',...
    [1.78 1.64 1 .4],'String','^2  =','FontSize',12,'LineStyle','none');
b.txtboxmsenum = annotation('textbox','Units','inches','Position',...
    [1.85 1 1 .4],'String','  =','FontSize',12,'LineStyle','none');
b.mstrsum = annotation('line','Units','inches','Position',...
    [1.7 1.91 .06 0],'LineWidth',6,'Color',[0.9 0.5 0]);
b.msesum = annotation('line','Units','inches','Position',...
    [1.7 1.31 .06 0],'LineWidth',6,'Color',[0 0.5 0]);
b.ax3 = axes('Units','inches','Position',[2.25 1.25 3 .72],...
    'YLim',[0 0.72],'XLim',[0 2],'Visible',...
    'off');
hold on
b.mstrind = plot(b.ax3,[0 b.MSTr],[0.66 0.66],'LineWidth',6,'Color',[0.9 0.5 0]);
b.mseind = plot(b.ax3,[0 b.MSE],[0.06 0.06],'LineWidth',6,'Color',[0 0.5 0]);

%p
b.txtboxp = annotation('textbox','Units','inches','Position',...
    [4.5 1.8 1.5 .4],'String','area = {\itp}-value  = ','FontSize',12,...
    'LineStyle','none');
b.txtboxp1 = annotation('textbox','Units','inches','Position',...
    [5.9 1.8 1.5 .4],'String',num2str(b.pVal),'FontSize',12,'LineStyle',...
    'none');
b.txtboxques = annotation('textbox','Units','inches','Position',...
    [4.5 1.5 1 .4],'String','Dependence?','FontSize',12,'LineStyle',...
    'none');
b.txtboxans = annotation('textbox','Units','inches','Position',...
    [5.9 1.5 1 .4],'String','NO','FontSize',12,'LineStyle',...
    'none','Color',[1 0 0]);

%slider labels
b.txtboxs = annotation('textbox','Units','inches','Position',...
    [.6 2.7 1 .4],'String','spread','FontSize',12,'LineStyle','none');
b.txtboxo = annotation('textbox','Units','inches','Position',...
    [.6 2.4 1 .4],'String','offset','FontSize',12,'LineStyle','none');

%sliders
%level1
b.sl1a = uicontrol('Parent',b.fig,'Style','slide','Units','inches',...
    'Position',[1.5 2.9 1 .2],'Min',slide_mins,'Max',slide_maxs,...
    'Value',1,'SliderStep',[1/100 1/20],'Tag','slider1a','UserData',...
    struct('OFF1',0,'SPR1',1),'Callback',{@slider_call1a,b},...
    'BackgroundColor',b.fig.Color);
b.sl1b = uicontrol('Parent',b.fig,'Style','slide','Units','inches',...
    'Position',[1.5 2.6 1 .2],'Min',slide_mino,'Max',slide_maxo,...
    'Value',0,'SliderStep',[1/100 1/20],'Tag','slider1b','UserData',...
    struct('OFF1',0,'SPR1',1),'Callback',{@slider_call1b,b},...
    'BackgroundColor',b.fig.Color);
%level2
b.sl2a = uicontrol('Parent',b.fig,'Style','slide','Units','inches',...
    'Position',[3.5 2.9 1 .2],'Min',slide_mins,'Max',slide_maxs,...
    'Value',1,'SliderStep',[1/100 1/20],'Tag','slider2a','UserData',...
    struct('OFF2',0,'SPR2',1),'Callback',{@slider_call2a,b},...
    'BackgroundColor',b.fig.Color);
b.sl2b = uicontrol('Parent',b.fig,'Style','slide','Units','inches',...
    'Position',[3.5 2.6 1 .2],'Min',slide_mino,'Max',slide_maxo,...
    'Value',0,'SliderStep',[1/100 1/20],'Tag','slider2b','UserData',...
    struct('OFF2',0,'SPR2',1),'Callback',{@slider_call2b,b},...
    'BackgroundColor',b.fig.Color);
%level3
b.sl3a = uicontrol('Parent',b.fig,'Style','slide','Units','inches',...
    'Position',[5.5 2.9 1 .2],'Min',slide_mins,'Max',slide_maxs,...
    'Value',1,'SliderStep',[1/100 1/20],'Tag','slider3a','UserData',...
    struct('OFF3',0,'SPR3',1),'Callback',{@slider_call3a,b},...
    'BackgroundColor',b.fig.Color);
b.sl3b = uicontrol('Parent',b.fig,'Style','slide','Units','inches',...
    'Position',[5.5 2.6 1 .2],'Min',slide_mino,'Max',slide_maxo,...
    'Value',0,'SliderStep',[1/100 1/20],'Tag','slider3b','UserData',...
    struct('OFF3',0,'SPR3',1),'Callback',{@slider_call3b,b},...
    'BackgroundColor',b.fig.Color);

set(findall(b.fig,'-property','FontUnits'),'FontUnits','normalized')
set(findall(b.fig,'-property','Units'),'Units','normalized')

end

%% callback1
%data 1, spread
function [] = slider_call1a(varargin)
[H,b] = varargin{[1,3]};
h = findobj('Tag','slider1b');
data = h.UserData;
slider_value = H.Value;
newdata = b.data(:,1)*slider_value + data.OFF1;
newmean = mean(newdata);

set(b.d1,'YData',newdata);
set(b.m1,'YData',newmean);

data = struct('OFF1',data.OFF1,'SPR1',slider_value);
H.UserData = data;
dat1 = get(b.d1,'Ydata');
dat2 = get(b.d2,'Ydata');
dat3 = get(b.d3,'Ydata');
dat = [dat1' dat2' dat3'];
nm = mean(dat);
nstd = std(dat);
newgrand = mean(nm);
set(b.gm,'YData',[newgrand newgrand]);
SSTr = sum(b.J*((nm - newgrand).^2));
SSE = sum((b.J - 1)*(nstd.^2));
MSTr = SSTr/b.nu1;
MSE = SSE/b.nu2;
F = MSTr/MSE;
pVal = 1 - fcdf(F,b.nu1,b.nu2);
xshade = F:.01:b.xtot(end);
Fshade = fpdf(xshade,b.nu1,b.nu2);

if pVal <= 0.05
    set(b.txtboxans,'String','YES!','Color',[0 1 0]);
else
    set(b.txtboxans,'String','NO!','Color',[1 0 0]);
end
set(b.txtboxFnum,'String',['=    ' num2str(F)]);
set(b.txtboxp1,'String',num2str(pVal));
set(b.ax2,'XTick',F)
set(b.shade,'Xdata',xshade,'Ydata',Fshade)
set(b.d1var,'YData',[nm(1),nm(1)+(nstd(1)^2)])
set(b.d1gr,'YData',[nm(1),newgrand])
set(b.d2gr,'YData',[nm(2),newgrand])
set(b.d3gr,'YData',[nm(3),newgrand])
set(b.mstrind,'XData',[0 MSTr])
set(b.mseind,'XData',[0 MSE])
end

%data 1, offset
function [] = slider_call1b(varargin)
[H,b] = varargin{[1,3]};
h = findobj('Tag','slider1a');
data = h.UserData;
slider_value = H.Value;
newdata = b.data(:,1)*data.SPR1 + slider_value;
newmean = mean(newdata);

set(b.d1,'YData',newdata);
set(b.m1,'YData',newmean);

data = struct('OFF1',slider_value,'SPR1',data.SPR1);
H.UserData = data;
dat1 = get(b.d1,'Ydata');
dat2 = get(b.d2,'Ydata');
dat3 = get(b.d3,'Ydata');
dat = [dat1' dat2' dat3'];
nm = mean(dat);
nstd = std(dat);
newgrand = mean(nm);
set(b.gm,'YData',[newgrand newgrand]);
SSTr = sum(b.J*((nm - newgrand).^2));
SSE = sum((b.J - 1)*(nstd.^2));
MSTr = SSTr/b.nu1;
MSE = SSE/b.nu2;
F = MSTr/MSE;
pVal = 1 - fcdf(F,b.nu1,b.nu2);
xshade = F:.01:b.xtot(end);
Fshade = fpdf(xshade,b.nu1,b.nu2);

if pVal <= 0.05
    set(b.txtboxans,'String','YES!','Color',[0 1 0]);
else
    set(b.txtboxans,'String','NO!','Color',[1 0 0]);
end
set(b.txtboxFnum,'String',['=    ' num2str(F)]);
set(b.txtboxp1,'String',num2str(pVal));
set(b.ax2,'XTick',F)
set(b.shade,'Xdata',xshade,'Ydata',Fshade)
set(b.d1var,'YData',[nm(1),nm(1)+(nstd(1)^2)])
set(b.d1gr,'YData',[nm(1),newgrand])
set(b.d2gr,'YData',[nm(2),newgrand])
set(b.d3gr,'YData',[nm(3),newgrand])
set(b.mstrind,'XData',[0 MSTr])
set(b.mseind,'XData',[0 MSE])
end

%% callback2
%data 2, spread
function [] = slider_call2a(varargin)
[H,b] = varargin{[1,3]};
h = findobj('Tag','slider2b');
data = h.UserData;
slider_value = H.Value;
newdata = b.data(:,2)*slider_value + data.OFF2;
newmean = mean(newdata);

set(b.d2,'YData',newdata);
set(b.m2,'YData',newmean);

data = struct('OFF2',data.OFF2,'SPR2',slider_value);
H.UserData = data;
dat1 = get(b.d1,'Ydata');
dat2 = get(b.d2,'Ydata');
dat3 = get(b.d3,'Ydata');
dat = [dat1' dat2' dat3'];
nm = mean(dat);
nstd = std(dat);
newgrand = mean(nm);
set(b.gm,'YData',[newgrand newgrand]);
SSTr = sum(b.J*((nm - newgrand).^2));
SSE = sum((b.J - 1)*(nstd.^2));
MSTr = SSTr/b.nu1;
MSE = SSE/b.nu2;
F = MSTr/MSE;
pVal = 1 - fcdf(F,b.nu1,b.nu2);
xshade = F:.01:b.xtot(end);
Fshade = fpdf(xshade,b.nu1,b.nu2);

if pVal <= 0.05
    set(b.txtboxans,'String','YES!','Color',[0 1 0]);
else
    set(b.txtboxans,'String','NO!','Color',[1 0 0]);
end
set(b.txtboxFnum,'String',['=    ' num2str(F)]);
set(b.txtboxp1,'String',num2str(pVal));
set(b.ax2,'XTick',F)
set(b.shade,'Xdata',xshade,'Ydata',Fshade)
set(b.d2var,'YData',[nm(2),nm(2)+(nstd(2)^2)])
set(b.d1gr,'YData',[nm(1),newgrand])
set(b.d2gr,'YData',[nm(2),newgrand])
set(b.d3gr,'YData',[nm(3),newgrand])
set(b.mstrind,'XData',[0 MSTr])
set(b.mseind,'XData',[0 MSE])

end

%data 2, offset
function [] = slider_call2b(varargin)
[H,b] = varargin{[1,3]};
h = findobj('Tag','slider2a');
data = h.UserData;
slider_value = H.Value;
newdata = b.data(:,2)*data.SPR2 + slider_value;
newmean = mean(newdata);

set(b.d2,'YData',newdata);
set(b.m2,'YData',newmean);

data = struct('OFF2',slider_value,'SPR2',data.SPR2);
H.UserData = data;
dat1 = get(b.d1,'Ydata');
dat2 = get(b.d2,'Ydata');
dat3 = get(b.d3,'Ydata');
dat = [dat1' dat2' dat3'];
nm = mean(dat);
nstd = std(dat);
newgrand = mean(nm);
set(b.gm,'YData',[newgrand newgrand]);
SSTr = sum(b.J*((nm - newgrand).^2));
SSE = sum((b.J - 1)*(nstd.^2));
MSTr = SSTr/b.nu1;
MSE = SSE/b.nu2;
F = MSTr/MSE;
pVal = 1 - fcdf(F,b.nu1,b.nu2);
xshade = F:.01:b.xtot(end);
Fshade = fpdf(xshade,b.nu1,b.nu2);

if pVal <= 0.05
    set(b.txtboxans,'String','YES!','Color',[0 1 0]);
else
    set(b.txtboxans,'String','NO!','Color',[1 0 0]);
end
set(b.txtboxFnum,'String',['=    ' num2str(F)]);
set(b.txtboxp1,'String',num2str(pVal));
set(b.ax2,'XTick',F)
set(b.shade,'Xdata',xshade,'Ydata',Fshade)
set(b.d2var,'YData',[nm(2),nm(2)+(nstd(2)^2)])
set(b.d1gr,'YData',[nm(1),newgrand])
set(b.d2gr,'YData',[nm(2),newgrand])
set(b.d3gr,'YData',[nm(3),newgrand])
set(b.mstrind,'XData',[0 MSTr])
set(b.mseind,'XData',[0 MSE])

end

%% callback3
%data 3, spread
function [] = slider_call3a(varargin)
[H,b] = varargin{[1,3]};
h = findobj('Tag','slider3b');
data = h.UserData;
slider_value = H.Value;
newdata = b.data(:,3)*slider_value + data.OFF3;
newmean = mean(newdata);

set(b.d3,'YData',newdata);
set(b.m3,'YData',newmean);

data = struct('OFF3',data.OFF3,'SPR3',slider_value);
H.UserData = data;
dat1 = get(b.d1,'Ydata');
dat2 = get(b.d2,'Ydata');
dat3 = get(b.d3,'Ydata');
dat = [dat1' dat2' dat3'];
nm = mean(dat);
nstd = std(dat);
newgrand = mean(nm);
set(b.gm,'YData',[newgrand newgrand]);
SSTr = sum(b.J*((nm - newgrand).^2));
SSE = sum((b.J - 1)*(nstd.^2));
MSTr = SSTr/b.nu1;
MSE = SSE/b.nu2;
F = MSTr/MSE;
pVal = 1 - fcdf(F,b.nu1,b.nu2);
xshade = F:.01:b.xtot(end);
Fshade = fpdf(xshade,b.nu1,b.nu2);

if pVal <= 0.05
    set(b.txtboxans,'String','YES!','Color',[0 1 0]);
else
    set(b.txtboxans,'String','NO!','Color',[1 0 0]);
end
set(b.txtboxFnum,'String',['=    ' num2str(F)]);
set(b.txtboxp1,'String',num2str(pVal));
set(b.ax2,'XTick',F)
set(b.shade,'Xdata',xshade,'Ydata',Fshade)
set(b.d3var,'YData',[nm(3),nm(3)+(nstd(3)^2)])
set(b.d1gr,'YData',[nm(1),newgrand])
set(b.d2gr,'YData',[nm(2),newgrand])
set(b.d3gr,'YData',[nm(3),newgrand])
set(b.mstrind,'XData',[0 MSTr])
set(b.mseind,'XData',[0 MSE])

end

%data 3, offset
function [] = slider_call3b(varargin)
[H,b] = varargin{[1,3]};
h = findobj('Tag','slider3a');
data = h.UserData;
slider_value = H.Value;
newdata = b.data(:,3)*data.SPR3 + slider_value;
newmean = mean(newdata);

set(b.d3,'YData',newdata);
set(b.m3,'YData',newmean);

data = struct('OFF3',slider_value,'SPR3',data.SPR3);
H.UserData = data;
dat1 = get(b.d1,'Ydata');
dat2 = get(b.d2,'Ydata');
dat3 = get(b.d3,'Ydata');
dat = [dat1' dat2' dat3'];
nm = mean(dat);
nstd = std(dat);
newgrand = mean(nm);
set(b.gm,'YData',[newgrand newgrand]);
SSTr = sum(b.J*((nm - newgrand).^2));
SSE = sum((b.J - 1)*(nstd.^2));
MSTr = SSTr/b.nu1;
MSE = SSE/b.nu2;
F = MSTr/MSE;
pVal = 1 - fcdf(F,b.nu1,b.nu2);
xshade = F:.01:b.xtot(end);
Fshade = fpdf(xshade,b.nu1,b.nu2);

if pVal <= 0.05
    set(b.txtboxans,'String','YES!','Color',[0 1 0]);
else
    set(b.txtboxans,'String','NO!','Color',[1 0 0]);
end
set(b.txtboxFnum,'String',['=    ' num2str(F)]);
set(b.txtboxp1,'String',num2str(pVal));
set(b.ax2,'XTick',F)
set(b.shade,'Xdata',xshade,'Ydata',Fshade)
set(b.d3var,'YData',[nm(3),nm(3)+(nstd(3)^2)])
set(b.d1gr,'YData',[nm(1),newgrand])
set(b.d2gr,'YData',[nm(2),newgrand])
set(b.d3gr,'YData',[nm(3),newgrand])
set(b.mstrind,'XData',[0 MSTr])
set(b.mseind,'XData',[0 MSE])

end
