function [ select_train select_test index1]=pr_feature_select(trainingdata, traininglabel,testingdata)

% *************************************************************************
% This function is used to select classified features which are likely to contribute
% to the classification power. Two-sample two-tailed t-tests were performed
% to determine these features. Note that the feature selection was always
% carried out on the training sample only.

%  function  [ select_train select_test index1]=pr_feature_select(trainingdata, traininglabel,testingdata)

% Input:

%          trainingdata:  the training data.A matrix n*m, n is the number of
%                        training subjects and m is the number of the features.

%         traininglabel:  the training label corresponding the training subject.
%                         A vector n*1, n is the number of training subjects.
%                         Note that the program requires the label of patient
%                         is -1 and the label of control is 1 to help us calculate
%                         the classification accuracy, sensitivity and  specificity  uniformly.

%          testingdata:  the testing data.A matrix 1*m, m is the number of the
%                        features. Note that the program used leave-one-out
%                        Cross validation.

% Output:

%         select_train:  the selected training data. A matrix n*s, n is
%                        the number of training subjects and s is the selected features.

%          select_test:  the selected testing data. A matrix k*s, k is
%                        the number of testing subjects and s is the selected
%                        features.

%               index1:  the index of selected features. A vector 1*k.

% Written by Zhengjia Dai, State Key Laboratory of Cognitive Neuroscience
% and Learning, Beijing Normal University, Beijing, P.R.China, 100875. 
% Contact information:
% Zhengjia Dai: daizhengjia13@gmail.com
% Yong He : yong.h.he@gmail.com; yong.he@bnu.edu.cn
% September 24th,2011
% *************************************************************************


%training data in the group of patients.
data1=trainingdata(find(traininglabel==-1),:);

%training data in the group of normal control.
data2=trainingdata(find(traininglabel==1),:);

% Two-sample two-tailed t-tests .
[betw_group_h betw_group_p]=ttest2(data1,data2);

index1=find(betw_group_h==1);

select_train=trainingdata(:,index1);

select_test=testingdata(:,index1);