MATLAB: Can I do a group regression in MATLAB using any toolbox

groupmultipleregressionStatistics and Machine Learning Toolbox

For a mixed data set, can I perform regression on data corresponding to one variable and then with another and so on, without having to separate the data into homogeneous groups?

Best Answer

Currently, MATLAB does not provide functionality for this kind of regression.
However, the example below demonstrates a simple method that can be used to perform the above regression with the functionalities with MATLAB.
The example uses the REGRESS function from the Statistics Toolbox. You can also use the 'backslash operator' to get just the coefficients, or REGSTATS to get different types of results.
% define data and grouping variable
y = rand(30,1);
g = repmat(('abc')',10,1);
x = rand(30,3);
x = [ones(30,1) x]; % include a column of ones
ncols = size(x,2);
% get list of unique group letters
gnames = unique(g)
ngroups = length(gnames);
% set up an array to receive
b = zeros(ncols,ngroups);
% store one column of coefficients per group
for j=1:length(gnames)
t = (g==gnames(j));
b(:,j) = regress(y(t),x(t,:));
end
For the case of a single x variable, this is analysis of covariance and the AOCTOOL function can compute the desired coefficients. For more information, refer to the documentation by typing the following in MATLAB:
doc aoctool