use of edu.cmu.tetrad.search.FactorAnalysis in project tetrad by cmu-phil.
the class FactorAnalysisRunner method execute.
// ===================PUBLIC METHODS OVERRIDING ABSTRACT================//
public void execute() {
DataSet selectedModel = (DataSet) getDataModel();
if (selectedModel == null) {
throw new NullPointerException("Data not specified.");
}
FactorAnalysis analysis = new FactorAnalysis(selectedModel);
threshold = .2;
TetradMatrix unrotatedSolution = analysis.successiveResidual();
rotatedSolution = analysis.successiveFactorVarimax(unrotatedSolution);
NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat();
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);
}
SemGraph graph = new SemGraph();
Vector<Node> observedVariables = new Vector<>();
for (Node a : selectedModel.getVariables()) {
graph.addNode(a);
observedVariables.add(a);
}
Vector<Node> factors = new Vector<>();
for (int i = 0; i < getRotatedSolution().columns(); i++) {
ContinuousVariable factor = new ContinuousVariable("Factor" + (i + 1));
factor.setNodeType(NodeType.LATENT);
graph.addNode(factor);
factors.add(factor);
}
for (int i = 0; i < getRotatedSolution().rows(); i++) {
for (int j = 0; j < getRotatedSolution().columns(); j++) {
if (Math.abs(getRotatedSolution().get(i, j)) > getThreshold()) {
graph.addDirectedEdge(factors.get(j), observedVariables.get(i));
}
}
}
setResultGraph(graph);
}
use of edu.cmu.tetrad.search.FactorAnalysis in project tetrad by cmu-phil.
the class FactorAnalysisAction method actionPerformed.
public void actionPerformed(ActionEvent e) {
DataSet dataSet = (DataSet) dataEditor.getSelectedDataModel();
if (dataSet == null || dataSet.getNumColumns() == 0) {
JOptionPane.showMessageDialog(findOwner(), "Cannot perform factor analysis on an empty data set.");
return;
}
FactorAnalysis factorAnalysis = new FactorAnalysis(dataSet);
// factorAnalysis.centroidUnity();
JPanel panel = createDialog(factorAnalysis);
EditorWindow window = new EditorWindow(panel, "Factor Loading Matrices", "Close", false, dataEditor);
DesktopController.getInstance().addEditorWindow(window, JLayeredPane.PALETTE_LAYER);
window.setVisible(true);
/*
EditorWindow window2 = new EditorWindow(new GraphEditor(new DirectedGraph()), "Factor Analysis", "Close", false, dataEditor);
window2.setLocation(800, 400);
DesktopController.getInstance().addEditorWindow(window2, JLayeredPane.PALETTE_LAYER);
window2.setVisible(true);
*/
}
use of edu.cmu.tetrad.search.FactorAnalysis 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