Search in sources :

Example 6 with DataSet

use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.

the class ScatterPlot method getCorrelationCoeff.

public double getCorrelationCoeff() {
    DataSet dataSet = getDataSet();
    TetradMatrix data = dataSet.getDoubleData();
    int _x = dataSet.getColumn(dataSet.getVariable(x));
    int _y = dataSet.getColumn(dataSet.getVariable(y));
    double[] xdata = data.getColumn(_x).toArray();
    double[] ydata = data.getColumn(_y).toArray();
    double correlation = StatUtils.correlation(xdata, ydata);
    if (correlation > 1)
        correlation = 1;
    else if (correlation < -1)
        correlation = -1;
    return correlation;
}
Also used : DataSet(edu.cmu.tetrad.data.DataSet) TetradMatrix(edu.cmu.tetrad.util.TetradMatrix)

Example 7 with DataSet

use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.

the class PurifyParamsEditor method setVarNames.

private boolean setVarNames(Object[] parentModels, Parameters params) {
    DataModel dataModel = null;
    for (Object parentModel : parentModels) {
        if (parentModel instanceof DataWrapper) {
            DataWrapper dataWrapper = (DataWrapper) parentModel;
            dataModel = dataWrapper.getSelectedDataModel();
        }
    }
    boolean discreteModel;
    if (dataModel instanceof ICovarianceMatrix) {
        discreteModel = false;
    } else {
        DataSet dataSet = (DataSet) dataModel;
        assert dataSet != null;
        discreteModel = dataSet.isDiscrete();
    // try {
    // new DataSet((DataSet) dataModel);
    // discreteModel = true;
    // }
    // catch (IllegalArgumentException e) {
    // discreteModel = false;
    // }
    }
    getParams().set("varNames", params.get("varNames", null));
    return discreteModel;
}
Also used : DataWrapper(edu.cmu.tetradapp.model.DataWrapper) DataSet(edu.cmu.tetrad.data.DataSet) DataModel(edu.cmu.tetrad.data.DataModel) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix)

Example 8 with DataSet

use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.

the class QQPlotAction method createQQPlotDialog.

/**
 * Creates a dialog that is showing the histogram for the given node (if null
 * one is selected for you)
 */
private JPanel createQQPlotDialog(Node selected) {
    String dialogTitle = "Q-Q Plots";
    // new JPanel(findOwner(), dialogTitle, false);
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    // dialog.setResizable(false);
    // dialog.getContentPane().setLayout(new BorderLayout());
    DataSet dataSet = (DataSet) dataEditor.getSelectedDataModel();
    QQPlot qqPlot = new QQPlot(dataSet, selected);
    QQPlotEditorPanel editorPanel = new QQPlotEditorPanel(qqPlot, dataSet);
    QQPlotDisplayPanel display = new QQPlotDisplayPanel(qqPlot);
    editorPanel.addPropertyChangeListener(new QQPlotListener(display));
    JMenuBar bar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menu.add(new JMenuItem(new SaveComponentImage(display, "Save Q-Q Plot")));
    bar.add(menu);
    Box box = Box.createHorizontalBox();
    box.add(display);
    box.add(Box.createHorizontalStrut(3));
    box.add(editorPanel);
    box.add(Box.createHorizontalStrut(5));
    box.add(Box.createHorizontalGlue());
    Box vBox = Box.createVerticalBox();
    vBox.add(Box.createVerticalStrut(15));
    vBox.add(box);
    vBox.add(Box.createVerticalStrut(5));
    panel.add(bar, BorderLayout.NORTH);
    panel.add(vBox, BorderLayout.CENTER);
    // return dialog;
    return panel;
}
Also used : DataSet(edu.cmu.tetrad.data.DataSet)

Example 9 with DataSet

use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.

the class QQPlotAction method actionPerformed.

public void actionPerformed(ActionEvent e) {
    DataSet dataSet = (DataSet) dataEditor.getSelectedDataModel();
    if (dataSet == null || dataSet.getNumColumns() == 0) {
        JOptionPane.showMessageDialog(findOwner(), "Cannot display a Q-Q plot for an empty data set.");
        return;
    }
    // if there are missing values warn and don't display q-q plot.
    // if(DataUtils.containsMissingValue(dataSet)){
    // JOptionPane.showMessageDialog(findOwner(), new JLabel("<html>Data has missing values, " +
    // "remove all missing values before<br>" +
    // "displaying data in a Q-Q plot.</html>"));
    // return;
    // }
    int[] selected = dataSet.getSelectedIndices();
    // if more then one column is selected then open up more than one histogram
    if (selected != null && 0 < selected.length) {
        // warn user if they selected more than 10
        if (10 < selected.length) {
            int option = JOptionPane.showConfirmDialog(findOwner(), "You are about to open " + selected.length + " Q-Q plots, are you sure you want to proceed?", "Q-Q Plot Warning", JOptionPane.YES_NO_OPTION);
            // if selected no, return
            if (option == JOptionPane.NO_OPTION) {
                return;
            }
        }
        for (int index : selected) {
            JPanel dialog = createQQPlotDialog(dataSet.getVariable(index));
            EditorWindow editorWindow = new EditorWindow(dialog, "QQPlot", "Save", true, dataEditor);
            DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
            editorWindow.pack();
            editorWindow.setVisible(true);
        // dialog.pack();
        // setLocation(dialog, index);
        // dialog.setVisible(true);
        }
    } else {
        JPanel dialog = createQQPlotDialog(null);
        EditorWindow editorWindow = new EditorWindow(dialog, "QQPlot", "Save", true, dataEditor);
        DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
        editorWindow.pack();
        editorWindow.setVisible(true);
    // JDialog dialog = createQQPlotDialog(null);
    // dialog.pack();
    // dialog.setLocationRelativeTo(dialog.getOwner());
    // dialog.setVisible(true);
    }
}
Also used : DataSet(edu.cmu.tetrad.data.DataSet)

Example 10 with DataSet

use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.

the class MimSearchEditor2 method getIndTestParamBox.

/**
 * Factory to return the correct param editor for independence test params.
 * This will go in a little box in the search editor.
 */
private JComponent getIndTestParamBox(Parameters params) {
    if (params == null) {
        throw new NullPointerException();
    }
    if (params instanceof Parameters) {
        MimRunner runner = getMimRunner();
        params.set("varNames", runner.getParams().get("varNames", null));
        DataModel dataModel = runner.getData();
        if (dataModel instanceof DataSet) {
            DataSet data = (DataSet) runner.getData();
            boolean discrete = data.isDiscrete();
            return new BuildPureClustersIndTestParamsEditor2(params, discrete);
        } else if (dataModel instanceof ICovarianceMatrix) {
            return new BuildPureClustersIndTestParamsEditor2(params, false);
        }
    }
    if (params instanceof Parameters) {
        MimRunner runner = getMimRunner();
        params.set("varNames", runner.getParams().get("varNames", null));
        boolean discreteData = false;
        if (runner.getData() instanceof DataSet) {
            discreteData = ((DataSet) runner.getData()).isDiscrete();
        }
        return new PurifyIndTestParamsEditor(params, discreteData);
    }
    if (params instanceof Parameters) {
        MimRunner runner = getMimRunner();
        params.set("varNames", runner.getParams().get("varNames", null));
        return new MimBuildIndTestParamsEditor(params);
    }
    throw new IllegalArgumentException("Unrecognized Parameters: " + params.getClass());
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) DataSet(edu.cmu.tetrad.data.DataSet) DataModel(edu.cmu.tetrad.data.DataModel) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) MimRunner(edu.cmu.tetradapp.model.MimRunner)

Aggregations

DataSet (edu.cmu.tetrad.data.DataSet)216 Test (org.junit.Test)65 Graph (edu.cmu.tetrad.graph.Graph)64 Node (edu.cmu.tetrad.graph.Node)60 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)48 ArrayList (java.util.ArrayList)45 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)36 GeneralBootstrapTest (edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)32 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)29 SemIm (edu.cmu.tetrad.sem.SemIm)28 SemPm (edu.cmu.tetrad.sem.SemPm)28 BootstrapEdgeEnsemble (edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble)26 DataModel (edu.cmu.tetrad.data.DataModel)22 Parameters (edu.cmu.tetrad.util.Parameters)22 DiscreteVariable (edu.cmu.tetrad.data.DiscreteVariable)20 File (java.io.File)16 ParseException (java.text.ParseException)16 LinkedList (java.util.LinkedList)14 ICovarianceMatrix (edu.cmu.tetrad.data.ICovarianceMatrix)13 DMSearch (edu.cmu.tetrad.search.DMSearch)10