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.");
}
}
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);
}
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;
}
}
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;
}
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();
}
Aggregations