FITMODEL Fits response by polynomial CALL: [fit,res,sd,dof ] = fitmodel(y,model) fit = fitted response res = residual, i.e., y-fit sd = standard deviation of residual dof = degrees of freedom y = Response in standard order model = character array of model parameters Example D = ffd(3); % complete 2^3 design in standard order. y = [60 72 54 68 52 83 45 80]; % Responses to design D. [ef, id] = yates(y); % Calculate effects nplot(ef,id) % Identify model model = strvcat('A','B','AC'); % model parameters [fit,res,sd,dof] = fitmodel(y,model); wnormplot(res) % Diagnostic check on fitted model. See also nplot, yates
Column Number to Column Label. | |
Reverse Yates' algorithm to give estimated responses | |
Calculates main and interaction effects using Yates' algorithm. | |
Display message and abort function. | |
True for numeric arrays. | |
Standard deviation. | |
Find possible matches for string. | |
Display warning message; disable or enable warning messages. |
001 function [fit,res,sd,dof] = fitmodel(y,model) 002 %FITMODEL Fits response by polynomial 003 % 004 % CALL: [fit,res,sd,dof ] = fitmodel(y,model) 005 % 006 % fit = fitted response 007 % res = residual, i.e., y-fit 008 % sd = standard deviation of residual 009 % dof = degrees of freedom 010 % y = Response in standard order 011 % model = character array of model parameters 012 % 013 % Example 014 % D = ffd(3); % complete 2^3 design in standard order. 015 % y = [60 72 54 68 52 83 45 80]; % Responses to design D. 016 % [ef, id] = yates(y); % Calculate effects 017 % nplot(ef,id) % Identify model 018 % model = strvcat('A','B','AC'); % model parameters 019 % [fit,res,sd,dof] = fitmodel(y,model); 020 % wnormplot(res) % Diagnostic check on fitted model. 021 % 022 % See also nplot, yates 023 024 error(nargchk(2,2,nargin)) 025 sz = size(y); 026 n = length(y); 027 if prod(sz) == n, 028 y = y(:); % Make sure it is a column vector 029 else 030 n = sz(1); % Number of runs 031 end 032 if isnumeric(model) 033 model = cnr2cl(model); % Transform into columnlabels 034 end 035 model = fliplr(sort(model,2)); 036 p = size(model,1); 037 038 [ef,id] = yates(y); % Calculate the effects 039 id = fliplr(sort(id,2)); 040 ind = ones(n,1); 041 for ix=1:p 042 k = strmatch(model(ix,:),id,'exact'); 043 if any(k), 044 ind(k+1)=0; 045 else 046 warning('Something wrong!') 047 end 048 end 049 050 ef2 = ef; 051 ind(1) = 0; 052 ind = find(ind); 053 ef2(ind,:) = 0; % Neglect effects from variables not in the model 054 055 fit = ryates(ef2); % Calculate the fit 056 res = y-fit; % Residual 057 058 sd = std(res); 059 dof = n-p-1; 060 061 062 063 064
Comments or corrections to the WAFO group