Search in sources :

Example 51 with ContinuousVariable

use of edu.cmu.tetrad.data.ContinuousVariable 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)

Example 52 with ContinuousVariable

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

the class RemovalListener method redrawScatterPlot.

/**
 * Redraws the scatter plot.
 */
public void redrawScatterPlot() {
    ScatterPlotOld newPlot = new ScatterPlotOld(scatterPlot.getDataSet(), (ContinuousVariable) (yVariableBox.getSelectedItem()), (ContinuousVariable) (xVariableBox.getSelectedItem()));
    if (regressionBox.isSelected())
        newPlot.setDrawRegLine(true);
    for (int i = 0; i < scrollers.size(); i++) {
        boolean breakNow = false;
        // if(((JCheckBox)boxes.get(i)).isSelected())
        // {
        double low = ((JScrollBar) scrollers.get(i)).getValue();
        double high = ((JScrollBar) scrollers.get(i)).getValue() + ((JScrollBar) scrollers.get(i)).getVisibleAmount();
        if (low > high)
            breakNow = true;
        ContinuousVariable currentNode = (ContinuousVariable) (condVariables.get(i));
        int variableIndex = newPlot.getDataSet().getColumn(currentNode);
        // edit the index set here
        Vector newIndexSet = new Vector();
        Vector newComplementSet = new Vector();
        for (int j = 0; j < newPlot.getIndexSet().size(); j++) {
            int currentIndex = (Integer) newPlot.getIndexSet().get(j);
            // lookup value at this index
            double value = newPlot.getDataSet().getDouble(currentIndex, variableIndex);
            // check if value is in the right interval -- if so we add to the new indexSet
            if (value >= low && value <= high) {
                newIndexSet.add(currentIndex);
            } else {
                newComplementSet.add(currentIndex);
            }
        }
        newPlot.setIndexSet(newIndexSet);
        newPlot.setComplementIndexSet(newComplementSet);
        // }
        if (breakNow)
            break;
    }
    changeScatterPlot(newPlot);
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) Vector(java.util.Vector)

Example 53 with ContinuousVariable

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

the class TimeoutComparison method getSubgraph.

private Graph getSubgraph(Graph graph, boolean discrete1, boolean discrete2, DataModel DataModel) {
    if (discrete1 && discrete2) {
        Graph newGraph = new EdgeListGraph(graph.getNodes());
        for (Edge edge : graph.getEdges()) {
            Node node1 = DataModel.getVariable(edge.getNode1().getName());
            Node node2 = DataModel.getVariable(edge.getNode2().getName());
            if (node1 instanceof DiscreteVariable && node2 instanceof DiscreteVariable) {
                newGraph.addEdge(edge);
            }
        }
        return newGraph;
    } else if (!discrete1 && !discrete2) {
        Graph newGraph = new EdgeListGraph(graph.getNodes());
        for (Edge edge : graph.getEdges()) {
            Node node1 = DataModel.getVariable(edge.getNode1().getName());
            Node node2 = DataModel.getVariable(edge.getNode2().getName());
            if (node1 instanceof ContinuousVariable && node2 instanceof ContinuousVariable) {
                newGraph.addEdge(edge);
            }
        }
        return newGraph;
    } else {
        Graph newGraph = new EdgeListGraph(graph.getNodes());
        for (Edge edge : graph.getEdges()) {
            Node node1 = DataModel.getVariable(edge.getNode1().getName());
            Node node2 = DataModel.getVariable(edge.getNode2().getName());
            if (node1 instanceof DiscreteVariable && node2 instanceof ContinuousVariable) {
                newGraph.addEdge(edge);
            }
            if (node1 instanceof ContinuousVariable && node2 instanceof DiscreteVariable) {
                newGraph.addEdge(edge);
            }
        }
        return newGraph;
    }
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) TakesInitialGraph(edu.cmu.tetrad.algcomparison.utils.TakesInitialGraph) Graph(edu.cmu.tetrad.graph.Graph) Node(edu.cmu.tetrad.graph.Node) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Edge(edu.cmu.tetrad.graph.Edge)

Example 54 with ContinuousVariable

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

the class FactorAnalysisAction method createDialog.

private JPanel createDialog(FactorAnalysis analysis) {
    double threshold = .2;
    TetradMatrix unrotatedSolution = analysis.successiveResidual();
    TetradMatrix rotatedSolution = analysis.successiveFactorVarimax(unrotatedSolution);
    DataSet dataSet = (DataSet) dataEditor.getSelectedDataModel();
    NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat();
    String output = "Unrotated Factor Loading Matrix:\n";
    output += tableString(unrotatedSolution, nf, Double.POSITIVE_INFINITY);
    if (unrotatedSolution.columns() != 1) {
        output += "\n\nRotated Matrix (using sequential varimax):\n";
        output += tableString(rotatedSolution, nf, threshold);
    // temp = rotatedSolution.toString();
    // temp = temp.split("\n", 2)[1];
    // output += temp;
    }
    JTextArea display = new JTextArea(output);
    JScrollPane scrollPane = new JScrollPane(display);
    scrollPane.setPreferredSize(new Dimension(500, 400));
    display.setEditable(false);
    display.setFont(new Font("Monospaced", Font.PLAIN, 12));
    // editorPanel.addPropertyChangeListener(new NormalityTestListener(display));
    SemGraph graph = new SemGraph();
    Vector<Node> observedVariables = new Vector<>();
    for (Node a : dataSet.getVariables()) {
        graph.addNode(a);
        observedVariables.add(a);
    }
    Vector<Node> factors = new Vector<>();
    for (int i = 0; i < rotatedSolution.columns(); i++) {
        ContinuousVariable factor = new ContinuousVariable("Factor" + (i + 1));
        factor.setNodeType(NodeType.LATENT);
        graph.addNode(factor);
        factors.add(factor);
    }
    for (int i = 0; i < rotatedSolution.rows(); i++) {
        for (int j = 0; j < rotatedSolution.columns(); j++) {
            if (Math.abs(rotatedSolution.get(i, j)) > threshold) {
                graph.addDirectedEdge(factors.get(j), observedVariables.get(i));
            // HEY JOE -- rotatedSolution.get(i, j) is the edge coeficient
            }
        }
    }
    GraphUtils.circleLayout(graph, 225, 200, 150);
    GraphUtils.fruchtermanReingoldLayout(graph);
    GraphWorkbench workbench = new GraphWorkbench(graph);
    JScrollPane graphPane = new JScrollPane(workbench);
    graphPane.setPreferredSize(new Dimension(500, 400));
    Box box = Box.createHorizontalBox();
    box.add(scrollPane);
    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));
    box.add(graphPane);
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(vBox, BorderLayout.CENTER);
    return panel;
}
Also used : DataSet(edu.cmu.tetrad.data.DataSet) TetradMatrix(edu.cmu.tetrad.util.TetradMatrix) ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) GraphWorkbench(edu.cmu.tetradapp.workbench.GraphWorkbench) Vector(java.util.Vector) NumberFormat(java.text.NumberFormat)

Example 55 with ContinuousVariable

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

the class FactorAnalysisAction method main.

public static void main(String[] args) {
    java.util.List<Node> nodes = new ArrayList<>();
    for (int i = 0; i < 9; i++) {
        nodes.add(new ContinuousVariable("X" + (i + 1)));
    }
    Graph graph = new Dag(GraphUtils.randomGraph(nodes, 0, 9, 30, 15, 15, false));
    SemPm pm = new SemPm(graph);
    SemIm im = new SemIm(pm);
    DataSet data = im.simulateData(500, false);
    ICovarianceMatrix cov = new CovarianceMatrix(data);
    FactorAnalysis factorAnalysis = new FactorAnalysis(cov);
    // factorAnalysis.centroidUnity();
    factorAnalysis.successiveResidual();
}
Also used : DataSet(edu.cmu.tetrad.data.DataSet) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) ArrayList(java.util.ArrayList) CovarianceMatrix(edu.cmu.tetrad.data.CovarianceMatrix) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) FactorAnalysis(edu.cmu.tetrad.search.FactorAnalysis) SemPm(edu.cmu.tetrad.sem.SemPm) SemIm(edu.cmu.tetrad.sem.SemIm)

Aggregations

ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)91 DataSet (edu.cmu.tetrad.data.DataSet)48 Node (edu.cmu.tetrad.graph.Node)46 Test (org.junit.Test)42 ArrayList (java.util.ArrayList)28 Graph (edu.cmu.tetrad.graph.Graph)22 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)19 SemPm (edu.cmu.tetrad.sem.SemPm)18 SemIm (edu.cmu.tetrad.sem.SemIm)16 DiscreteVariable (edu.cmu.tetrad.data.DiscreteVariable)15 LinkedList (java.util.LinkedList)13 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)12 TetradMatrix (edu.cmu.tetrad.util.TetradMatrix)8 DMSearch (edu.cmu.tetrad.search.DMSearch)7 Dag (edu.cmu.tetrad.graph.Dag)6 CovarianceMatrix (edu.cmu.tetrad.data.CovarianceMatrix)5 RandomUtil (edu.cmu.tetrad.util.RandomUtil)5 ParseException (java.text.ParseException)4 CovarianceMatrixOnTheFly (edu.cmu.tetrad.data.CovarianceMatrixOnTheFly)3 Knowledge2 (edu.cmu.tetrad.data.Knowledge2)3