function [h,sig] = ztest(y,X,omega,Omega,alpha) %FTEST Hypothesis test. % [H,SIG] = FTEST(Y,X,omega,OMEGA,ALPHA) performs an F-test to determine % whether a linear model defined by omega is sufficient compared to % the model defined by OMEGA. % Y contains the response variables, X the explanatory variables and % OMEGA, omega are subsets of the rows of X. omega is a subset of OMEGA. % ALPHA = 0.05 by default. % % The null hypothesis is: "omega is the true model". % % ALPHA is the desired significance level. % SIG is the probability of observing the given result by chance % given that the null hypothesis is true. Small values of SIG cast % doubt on the validity of the null hypothesis. % % H=0 => "Do not reject null hypothesis at significance level of alpha." % H=1 => "Reject null hypothesis at significance level of alpha." % Copyright (c) 2000 by Reinhard Furrer. % Parameter verification if nargin < 3, error('Requires at least three input arguments.'); end [n,m] = size(X); [n1,collhs] = size(y); if n ~= n1, error('The number of rows in Y must equal the number of rows in X.'); end if collhs ~= 1, error('Y must be a vector, not a matrix'); end omega=unique(omega); [m1 q] = size(omega); if (m1 ~= 1 & q ~= 1) error('Invalid variable selection.'); end if nargin < 4, Omega=[1:m]; p=m; else Omega=unique(Omega); [m1 p] = size(Omega); if (m1 ~= 1 & p ~= 1 & p > q & max(Omega)>m ) error('Invalid variable selection.'); end end oX=X(:,intersect(omega,Omega)); OX=X(:,Omega); if nargin < 5, alpha = 0.05; end % Actual Fobs calculation [b,bint,Or] = regress(y,OX); [b,bint,or] = regress(y,oX); Osc=sum(Or.^2); osc=sum(or.^2); Fobs=(osc-Osc)/(Osc)*(n-p)/(p-q); sig=finv(Fobs,p-q,n-p); if (alpha <= 0 | alpha >= 1) fprintf('Warning: significance level must be between 0 and 1\n'); h = NaN; sig = NaN; return; end % Determine if the actual significance exceeds the desired significance h = 0; if sig <= alpha, h = 1; end if isnan(sig), h = NaN; end