eeg_regress

eeg_regress - function[H =...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: function [H] = eeg_regress(data,robust,GP,labels) % eeg_regress - plot multiple linear regression results % % [H] = eeg_regress(data,[robust],[GP],labels) % % data is NxP matrix, with N observations, P-1 predictors % and the last column is the observed values to predict. % So, if only 2 columns are given it does a simple linear % regression. % % robust = 1, use robust least-squares regression % robust = 0, use least-squares regression % note, current robust is forced to 1. % % GP is Nx1 grouping variable % % labels = cell strings with variable names, keep to % 5 characters or less for best format of figure text % % H is an array of handles to figures % % All the results are plotted to new figures, which can % be saved/exported using print(H(i)...) % % $Revision: 1.1 $ $Date: 2009/04/28 22:13:53 $ % Licence: GNU GPL, no express or implied warranties % History: 11/2002, Darren.Weber_at_radiology.ucsf.edu % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if ~exist('data','var'), fprintf('...no input data.\n\n'); return end if ~exist('robust','var'), robust = 1; else, warning('must use robust method, at present'); robust = 1; % cheat for now, as some plotting stuff below requires it end if ~exist('labels','var'), for i = 1:size(data,2), if i == size(data,2), labels{i} = 'Y'; else labels{i} = sprintf('X%d',i); end end end if ~exist('GP','var'), error('GP input variable is undefined\n'); end plotmatrix(data); % to explore relationships H(1) = gcf; y = data(:,end); % values to fit from last column e = ones(length(data),1); % for constant term in model X = [e data(:,1:end-1)]; % predictor values from first columns if ~robust, %beta = X\y; % 3 x 1 matrix, const, beta1 & beta2 [B,BCI,R,RCI,STATS] = regress(y,X,.05); P = X*B; % fitted values % use B slope, with BCI intercepts, not strictly correct CI = [ [BCI(1,1); B(2:end)] [BCI(1,2); B(2:end)] ]; YCI = [X*CI(:,1), X*CI(:,2) ]; % Note if BCI(x,:) < or > 0, B(x) is significant % define figure rows & columns cols = 6; rows = size(X,2); else [B,BCI,R,RCI,STATS] = regress(y,X,.05); clear B BCI R RCI; R2 = STATS(1); F = STATS(2); Fp = STATS(3); % for total regression clear STATS; [B,STATS] = robustfit(X(:,2:end),y); P = X*B; % predicted values R = STATS.resid; % residuals BCI = [B - 2*STATS.se, B + 2*STATS.se]; % beta CI YCI = [P - 2*STATS.s, P + 2*STATS.s ]; % predicted CI % define figure rows & columns...
View Full Document

This note was uploaded on 10/06/2010 for the course ENG 42325 taught by Professor Lagerstrom during the Spring '10 term at UC Davis.

Page1 / 7

eeg_regress - function[H =...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online