Search in sources :

Example 11 with DataModelList

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

the class SubsetContinuousVariablesAction method actionPerformed.

/**
 * Performs the action of loading a session from a file.
 */
public void actionPerformed(ActionEvent e) {
    DataModel selectedDataModel = getDataEditor().getSelectedDataModel();
    if (selectedDataModel instanceof DataSet) {
        DataSet dataSet = (DataSet) selectedDataModel;
        List variables = dataSet.getVariables();
        int n = 0;
        for (Object variable : variables) {
            if (variable instanceof ContinuousVariable) {
                n++;
            }
        }
        if (n == 0) {
            JOptionPane.showMessageDialog(getDataEditor(), "There are no continuous variables in this data set.");
            return;
        }
        int[] indices = new int[n];
        int m = -1;
        for (int i = 0; i < variables.size(); i++) {
            if (variables.get(i) instanceof ContinuousVariable) {
                indices[++m] = i;
            }
        }
        dataSet = dataSet.subsetColumns(indices);
        DataModelList list = new DataModelList();
        list.add(dataSet);
        getDataEditor().reset(list);
        getDataEditor().selectFirstTab();
    } else {
        JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Requires a tabular data set.");
    }
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) DataSet(edu.cmu.tetrad.data.DataSet) DataModelList(edu.cmu.tetrad.data.DataModelList) DataModel(edu.cmu.tetrad.data.DataModel) DataModelList(edu.cmu.tetrad.data.DataModelList) List(java.util.List)

Aggregations

DataModelList (edu.cmu.tetrad.data.DataModelList)11 DataSet (edu.cmu.tetrad.data.DataSet)7 DataModel (edu.cmu.tetrad.data.DataModel)6 DataWrapper (edu.cmu.tetradapp.model.DataWrapper)3 ArrayList (java.util.ArrayList)3 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 File (java.io.File)2 List (java.util.List)2 Comparison (edu.cmu.tetrad.algcomparison.Comparison)1 RandomGraph (edu.cmu.tetrad.algcomparison.graph.RandomGraph)1 SingleGraph (edu.cmu.tetrad.algcomparison.graph.SingleGraph)1 BayesNetSimulation (edu.cmu.tetrad.algcomparison.simulation.BayesNetSimulation)1 BooleanGlassSimulation (edu.cmu.tetrad.algcomparison.simulation.BooleanGlassSimulation)1 ConditionalGaussianSimulation (edu.cmu.tetrad.algcomparison.simulation.ConditionalGaussianSimulation)1 GeneralSemSimulation (edu.cmu.tetrad.algcomparison.simulation.GeneralSemSimulation)1 LeeHastieSimulation (edu.cmu.tetrad.algcomparison.simulation.LeeHastieSimulation)1 LoadContinuousDataAndGraphs (edu.cmu.tetrad.algcomparison.simulation.LoadContinuousDataAndGraphs)1 SemSimulation (edu.cmu.tetrad.algcomparison.simulation.SemSimulation)1