Search in sources :

Example 1 with Group

use of org.knime.base.node.stats.testing.ttest.Grouping.Group in project knime-core by knime.

the class TwoSampleTTest method execute.

public TwoSampleTTestStatistics[] execute(final BufferedDataTable table, final ExecutionContext exec) throws InvalidSettingsException, CanceledExecutionException {
    DataTableSpec spec = table.getDataTableSpec();
    int groupingIndex = spec.findColumnIndex(m_grouping.getColumn());
    if (groupingIndex == -1) {
        throw new InvalidSettingsException("Grouping column not found.");
    }
    int[] testColumnsIndex = new int[m_testColumns.length];
    for (int i = 0; i < testColumnsIndex.length; i++) {
        testColumnsIndex[i] = spec.findColumnIndex(m_testColumns[i]);
    }
    int testColumnCount = m_testColumns.length;
    TwoSampleTTestStatistics[] result = new TwoSampleTTestStatistics[testColumnCount];
    for (int i = 0; i < testColumnCount; i++) {
        result[i] = new TwoSampleTTestStatistics(m_testColumns[i], m_grouping.getGroupLabels(), m_confidenceIntervalProb);
    }
    final int rowCount = table.getRowCount();
    int rowIndex = 0;
    for (DataRow row : table) {
        exec.checkCanceled();
        exec.setProgress(rowIndex++ / (double) rowCount, rowIndex + "/" + rowCount + " (\"" + row.getKey() + "\")");
        DataCell groupCell = row.getCell(groupingIndex);
        Group group = m_grouping.getGroup(groupCell);
        for (int i = 0; i < testColumnCount; i++) {
            if (group == null) {
                if (groupCell.isMissing()) {
                    result[i].addMissingGroup();
                } else {
                    result[i].addIgnoredGroup();
                }
                continue;
            }
            DataCell cell = row.getCell(testColumnsIndex[i]);
            if (!cell.isMissing()) {
                DoubleValue value = (DoubleValue) cell;
                result[i].addValue(value.getDoubleValue(), group);
            } else {
                result[i].addMissing(group);
            }
        }
    }
    return result;
}
Also used : Group(org.knime.base.node.stats.testing.ttest.Grouping.Group) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DoubleValue(org.knime.core.data.DoubleValue) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow)

Example 2 with Group

use of org.knime.base.node.stats.testing.ttest.Grouping.Group in project knime-core by knime.

the class TwoSampleTTestNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    Map<Group, String> groups = new LinkedHashMap<Group, String>();
    groups.put(Group.GroupX, m_settings.getGroupOne());
    groups.put(Group.GroupY, m_settings.getGroupTwo());
    Grouping grouping = new StringValueGrouping(m_settings.getGroupingColumn(), groups);
    DataTableSpec spec = inData[0].getSpec();
    FilterResult filter = m_settings.getTestColumns().applyTo(spec);
    TwoSampleTTest test = new TwoSampleTTest(filter.getIncludes(), grouping, m_settings.getConfidenceIntervalProb());
    TwoSampleTTestStatistics[] result = test.execute(inData[0], exec);
    LeveneTest leveneTest = new LeveneTest(filter.getIncludes(), m_settings.getGroupingColumn(), Arrays.asList(new String[] { m_settings.getGroupOne(), m_settings.getGroupTwo() }), getGroupSummaryStats(result));
    LeveneTestStatistics[] leveneResult = leveneTest.execute(inData[0], exec);
    leveneResult[0].getTTestCells();
    m_descStats = getDescriptiveStatisticsTable(result, exec);
    m_leveneStats = getLeveneStatistices(leveneResult, exec);
    m_stats = getTestStatisticsTable(result, exec);
    return new BufferedDataTable[] { m_stats, m_leveneStats, m_descStats };
}
Also used : Group(org.knime.base.node.stats.testing.ttest.Grouping.Group) DataTableSpec(org.knime.core.data.DataTableSpec) LeveneTest(org.knime.base.node.stats.testing.levene.LeveneTest) LeveneTestStatistics(org.knime.base.node.stats.testing.levene.LeveneTestStatistics) LinkedHashMap(java.util.LinkedHashMap) BufferedDataTable(org.knime.core.node.BufferedDataTable) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)

Aggregations

Group (org.knime.base.node.stats.testing.ttest.Grouping.Group)2 DataTableSpec (org.knime.core.data.DataTableSpec)2 LinkedHashMap (java.util.LinkedHashMap)1 LeveneTest (org.knime.base.node.stats.testing.levene.LeveneTest)1 LeveneTestStatistics (org.knime.base.node.stats.testing.levene.LeveneTestStatistics)1 DataCell (org.knime.core.data.DataCell)1 DataRow (org.knime.core.data.DataRow)1 DoubleValue (org.knime.core.data.DoubleValue)1 BufferedDataTable (org.knime.core.node.BufferedDataTable)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 FilterResult (org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)1