|
PLearn 0.1
|
#include <TestDependencyCommand.h>


Public Member Functions | |
| TestDependencyCommand () | |
| virtual void | run (const vector< string > &args) |
| The actual implementation of the 'TestDependencyCommand' command. | |
Static Protected Attributes | |
| static PLearnCommandRegistry | reg_ |
| This allows to register the 'TestDependencyCommand' command in the command registry. | |
Definition at line 49 of file TestDependencyCommand.h.
| PLearn::TestDependencyCommand::TestDependencyCommand | ( | ) | [inline] |
Definition at line 52 of file TestDependencyCommand.h.
:
PLearnCommand("test-dependency",
"Compute dependency statistics between two selected columns of a vmat.",
" test-dependency <VMat> <x> <y>\n"
"Reads a VMatrix (or any matrix format) and computes dependency statistics between\n"
"two variables <x> and <y>. The current implementation only computes the Spearman rank correlation\n"
"and the linear correlation. The format of <x> and <y> is the following:\n"
" - column number (starting at 0 for the first column), or\n"
" - @<fieldname> \n")
{}
| void PLearn::TestDependencyCommand::run | ( | const vector< string > & | args | ) | [virtual] |
The actual implementation of the 'TestDependencyCommand' command.
Implements PLearn::PLearnCommand.
Definition at line 53 of file TestDependencyCommand.cc.
References PLearn::TMat< T >::column(), PLearn::VMat::columns(), PLearn::correlations(), PLearn::endl(), PLearn::VMat::fieldName(), PLearn::getDataSet(), PLERROR, PLearn::testSpearmanRankCorrelation(), PLearn::toint(), PLearn::VMat::toMat(), and x.
{
if(args.size()<3 || args.size()>3)
PLERROR("test-dependencies expects 3 arguments, check the help");
VMat data = getDataSet(args[0]);
string x_spec = args[1];
string y_spec = args[2];
int x_col=0, y_col=0;
if (x_spec[0]!='@')
x_col = toint(x_spec);
else {
string x_name = x_spec.substr(1,x_spec.length()-1);
x_col = data->fieldIndex(x_name);
if (x_col<0) PLERROR("could not find field named %s in %s",x_name.c_str(),args[0].c_str());
}
if (y_spec[0]!='@')
y_col = toint(y_spec);
else {
string y_name = y_spec.substr(1,y_spec.length()-1);
y_col = data->fieldIndex(y_name);
if (y_col<0) PLERROR("could not find field named %s in %s",y_name.c_str(),args[0].c_str());
}
// extract the two columns
TVec<int> columns(2);
columns[0]=x_col;
columns[1]=y_col;
Mat xy_mat = data.columns(columns).toMat();
VMat x = VMat(xy_mat.column(0));
VMat y = VMat(xy_mat.column(1));
Mat spearman_pvalue(1,1);
Mat spearman_r(1,1);
testSpearmanRankCorrelation(x,y,spearman_r,spearman_pvalue);
Mat linear_pvalue(1,1);
Mat linear_r(1,1);
correlations(x,y,linear_r,linear_pvalue);
cout << "test-dependency between " << data->fieldName(x_col) << " (column " << x_col << ") and "
<< data->fieldName(y_col) << " (column " << y_col << "):" << endl;
cout << "rank correlation = " << spearman_r(0,0) << " {p-value = " << spearman_pvalue(0,0) << "}" << endl;
cout << "linear correlation = " << linear_r(0,0) << " {p-value = " << linear_pvalue(0,0) << "}" << endl;
}

PLearnCommandRegistry PLearn::TestDependencyCommand::reg_ [static, protected] |
This allows to register the 'TestDependencyCommand' command in the command registry.
Definition at line 66 of file TestDependencyCommand.h.
1.7.4