Search in sources :

Example 41 with DataCell

use of org.knime.core.data.DataCell in project knime-core by knime.

the class OneWayANOVANodeModel method getGroups.

private List<String> getGroups(final BufferedDataTable inData, final ExecutionMonitor exec) throws InvalidSettingsException, CanceledExecutionException {
    DataTableSpec spec = inData.getSpec();
    int gIndex = spec.findColumnIndex(m_settings.getGroupingColumn());
    LinkedHashSet<String> groups = new LinkedHashSet<String>();
    if (gIndex < 0) {
        throw new InvalidSettingsException("Grouping column not found.");
    }
    final int rowCount = inData.getRowCount();
    int rowIndex = 0;
    for (DataRow row : inData) {
        exec.checkCanceled();
        exec.setProgress(rowIndex++ / (double) rowCount, rowIndex + "/" + rowCount + " (\"" + row.getKey() + "\")");
        DataCell group = row.getCell(gIndex);
        if (!group.isMissing()) {
            groups.add(group.toString());
        }
    }
    return Arrays.asList(groups.toArray(new String[groups.size()]));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow)

Example 42 with DataCell

use of org.knime.core.data.DataCell in project knime-core by knime.

the class LeveneTestStatistics method getLeveneTestTwoGroupsCells.

/**
 * Get the test result of the Levene test. This is an optimized version for
 * two groups.
 * @return the Levene test
 */
public List<List<DataCell>> getLeveneTestTwoGroupsCells() {
    SummaryStatistics statsX = m_denStats.get(0);
    SummaryStatistics statsY = m_denStats.get(1);
    // overall sample mean
    double m = m_lstats.getMean();
    // first sample mean
    double m1 = statsX.getMean();
    // second sample mean
    double m2 = statsY.getMean();
    // first sample variance
    double v1 = statsX.getVariance();
    // second sample variance
    double v2 = statsY.getVariance();
    // first sample count
    double n1 = statsX.getN();
    // second sample count
    double n2 = statsY.getN();
    // Levene's test
    double num = n1 * (m1 - m) * (m1 - m) + n2 * (m2 - m) * (m2 - m);
    double den = (n1 - 1) * v1 + (n2 - 1) * v2;
    double L = (n1 + n2 - 2) / den * num;
    long df1 = 1;
    long df2 = (long) n1 + (long) n2 - 2;
    FDistribution distribution = new FDistribution(df1, df2);
    double pValue = 1 - distribution.cumulativeProbability(L);
    List<DataCell> cells = new ArrayList<DataCell>();
    cells.add(new StringCell(m_column));
    cells.add(new DoubleCell(L));
    cells.add(new IntCell((int) df1));
    cells.add(new IntCell((int) df2));
    cells.add(new DoubleCell(pValue));
    return Collections.singletonList(cells);
}
Also used : StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) ArrayList(java.util.ArrayList) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) DataCell(org.knime.core.data.DataCell) FDistribution(org.apache.commons.math3.distribution.FDistribution) IntCell(org.knime.core.data.def.IntCell)

Example 43 with DataCell

use of org.knime.core.data.DataCell in project knime-core by knime.

the class LeveneTestStatistics method getTTestTable.

/**
 * Get the test result of the t-test, for the assumption of equal
 * variance and the assumption of unequal variances.
 * @param exec the execution context
 * @return the t-test results
 */
public BufferedDataTable getTTestTable(final ExecutionContext exec) {
    DataTableSpec outSpec = getTableSpec();
    BufferedDataContainer cont = exec.createDataContainer(outSpec);
    int r = 0;
    for (List<DataCell> cells : getTTestCells()) {
        cont.addRowToTable(new DefaultRow(RowKey.createRowKey(r), cells));
        r++;
    }
    cont.close();
    BufferedDataTable outTable = cont.getTable();
    return outTable;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 44 with DataCell

use of org.knime.core.data.DataCell in project knime-core by knime.

the class NodeViewUtil method renderDataTable.

/**
 * Create HTML from the given table using column rowHeader as row headers.
 * @param table the table
 * @param rowHeader the column with row headers
 * @param exclude columns to exclude
 * @param colHeaders override column headers
 * @param buffer append to this buffer
 */
public static void renderDataTable(final BufferedDataTable table, final String rowHeader, final Collection<String> exclude, final Map<String, String> colHeaders, final StringBuilder buffer) {
    int rowHeaderI = table.getDataTableSpec().findColumnIndex(rowHeader);
    Set<Integer> excludeI = new HashSet<Integer>();
    for (String toExclude : exclude) {
        excludeI.add(table.getDataTableSpec().findColumnIndex(toExclude));
    }
    buffer.append("<table>\n");
    buffer.append("<tr>");
    buffer.append("<th class=\"left\"></th>");
    for (DataColumnSpec colSpec : table.getDataTableSpec()) {
        String colName = colSpec.getName();
        if (!exclude.contains(colName)) {
            String value = colHeaders.containsKey(colName) ? colHeaders.get(colName) : colName;
            buffer.append("<th>");
            buffer.append(escapeHtml(value));
            buffer.append("</th>");
        }
    }
    buffer.append("</tr>");
    int r = 0;
    for (Iterator<DataRow> it = table.iteratorFailProve(); it.hasNext(); ) {
        DataRow row = it.next();
        buffer.append("<tr class=\"");
        buffer.append(r % 2 == 0 ? "odd" : "even");
        buffer.append("\">");
        renderDataCell(row.getCell(rowHeaderI), buffer);
        for (int i = 0; i < row.getNumCells(); i++) {
            if (excludeI.contains(i)) {
                continue;
            }
            DataCell cell = row.getCell(i);
            renderDataCell(cell, buffer);
        }
        buffer.append("</tr>");
        r++;
    }
    buffer.append("</table>\n");
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow) HashSet(java.util.HashSet)

Example 45 with DataCell

use of org.knime.core.data.DataCell in project knime-core by knime.

the class OneWayANOVAStatistics method getGroupStatistics.

/**
 * Get descriptive statistics for the given Group.
 * @param groupIndex the index of the group
 * @return the descriptive statistics for this group.
 */
public List<DataCell> getGroupStatistics(final int groupIndex) {
    List<DataCell> cells = new ArrayList<DataCell>();
    cells.add(new StringCell(m_column));
    cells.add(new StringCell(m_groups.get(groupIndex)));
    SummaryStatistics stats = m_gstats.get(groupIndex);
    cells.add(new IntCell((int) stats.getN()));
    cells.add(new IntCell(m_missing.get(groupIndex).intValue()));
    cells.add(new IntCell(m_missingGroup.intValue()));
    cells.add(new DoubleCell(stats.getMean()));
    cells.add(new DoubleCell(stats.getStandardDeviation()));
    cells.add(new DoubleCell(StatsUtil.getStandardError(stats)));
    cells.add(new DoubleCell(m_confidenceIntervalProp));
    long df = stats.getN() - 1;
    TDistribution distribution = new TDistribution(df);
    double tValue = FastMath.abs(distribution.inverseCumulativeProbability((1 - m_confidenceIntervalProp) / 2));
    double confidenceDelta = tValue * StatsUtil.getStandardError(stats);
    double confidenceLowerBound = stats.getMean() - confidenceDelta;
    double confidenceUpperBound = stats.getMean() + confidenceDelta;
    cells.add(new DoubleCell(confidenceLowerBound));
    cells.add(new DoubleCell(confidenceUpperBound));
    cells.add(new DoubleCell(stats.getMin()));
    cells.add(new DoubleCell(stats.getMax()));
    return cells;
}
Also used : StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) ArrayList(java.util.ArrayList) DataCell(org.knime.core.data.DataCell) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) TDistribution(org.apache.commons.math3.distribution.TDistribution) IntCell(org.knime.core.data.def.IntCell)

Aggregations

DataCell (org.knime.core.data.DataCell)780 DataRow (org.knime.core.data.DataRow)268 DataTableSpec (org.knime.core.data.DataTableSpec)175 DataColumnSpec (org.knime.core.data.DataColumnSpec)170 DefaultRow (org.knime.core.data.def.DefaultRow)169 ArrayList (java.util.ArrayList)141 StringCell (org.knime.core.data.def.StringCell)131 DoubleCell (org.knime.core.data.def.DoubleCell)129 DoubleValue (org.knime.core.data.DoubleValue)111 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)109 DataType (org.knime.core.data.DataType)97 RowKey (org.knime.core.data.RowKey)94 BufferedDataTable (org.knime.core.node.BufferedDataTable)93 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)91 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)84 LinkedHashMap (java.util.LinkedHashMap)81 IntCell (org.knime.core.data.def.IntCell)79 HashMap (java.util.HashMap)60 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)57 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)56