use of edu.cmu.tetrad.data.DiscreteVariable in project tetrad by cmu-phil.
the class DataCellRenderer method getTableCellRendererComponent.
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
// Have to set the alignment here, since this is the only place the col
// index of the component is available...
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) c;
if (dataSet.getNumColumns() > 0 && col >= getNumLeadingCols() && col < dataSet.getNumColumns() + getNumLeadingCols()) {
int dataCol = col - getNumLeadingCols();
Node variable = dataSet.getVariable(dataCol);
if (variable instanceof DiscreteVariable) {
renderer.setHorizontalAlignment(JLabel.RIGHT);
} else {
renderer.setHorizontalAlignment(JLabel.RIGHT);
}
}
return renderer;
}
use of edu.cmu.tetrad.data.DiscreteVariable in project tetrad by cmu-phil.
the class SubsetDiscreteVariablesAction 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;
for (int i = dataSet.getNumColumns(); i >= 0; i--) {
if (dataSet.getVariable(i) instanceof DiscreteVariable) {
dataSet.removeColumn(i);
}
}
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.DiscreteVariable in project tetrad by cmu-phil.
the class TabularDataTable method swapDiscreteColumnForContinuous.
private Node swapDiscreteColumnForContinuous(int col) {
Node variable = dataSet.getVariable(col - getNumLeadingCols());
if (variable == null) {
throw new NullPointerException();
}
if (!isEmpty(dataSet, col - getNumLeadingCols())) {
throw new IllegalArgumentException("Old column not empty.");
}
String name = variable.getName();
DiscreteVariable var = new DiscreteVariable(name);
var.setCategoryNamesDisplayed(true);
dataSet.removeColumn(col - getNumLeadingCols());
dataSet.addVariable(col - getNumLeadingCols(), var);
pcs.firePropertyChange("modelChanged", null, null);
return var;
}
use of edu.cmu.tetrad.data.DiscreteVariable 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.DiscreteVariable in project tetrad by cmu-phil.
the class DescriptiveStats method generateDescriptiveStats.
/**
* Constructs a readable table of normality test results
*/
public static String generateDescriptiveStats(DataSet dataSet, Node variable) {
NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat();
int col = dataSet.getColumn(variable);
double[] data = new double[dataSet.getNumRows()];
boolean continuous = false;
if (variable instanceof ContinuousVariable) {
continuous = true;
for (int i = 0; i < dataSet.getNumRows(); i++) {
data[i] = dataSet.getDouble(i, col);
}
} else {
try {
for (int i = 0; i < dataSet.getNumRows(); i++) {
DiscreteVariable var = (DiscreteVariable) variable;
String category = var.getCategory(dataSet.getInt(i, col));
int value = Integer.parseInt(category);
data[i] = value;
}
} catch (NumberFormatException e) {
return "Not a numerical discrete column.";
}
}
String result = "Descriptive Statistics for: " + variable.getName() + "\n";
result += "------------------------------------\n\n";
double[] normalValues = normalParams(data);
result += "Sample Size:\t\t" + dataSet.getNumRows() + "\n";
result += "Mean:\t\t\t" + nf.format(normalValues[0]) + "\nStandard Deviation:\t" + nf.format(normalValues[1]) + "\nVariance:\t\t" + nf.format(normalValues[2]) + "\n";
result += "Skewness:\t\t" + nf.format(StatUtils.skewness(data)) + "\n";
result += "Excess Kurtosis:\t" + nf.format(StatUtils.kurtosis(data)) + "\n";
if (continuous) {
result += "SE Mean:\t\t" + nf.format(standardErrorMean(normalValues[1], dataSet.getNumRows())) + "\n";
}
double[] median = median(data);
result += "Median:\t\t\t" + nf.format(median[0]) + "\n";
if (continuous) {
result += "Minimum Value:\t\t" + nf.format(median[1]) + "\nMaximum Value:\t\t" + nf.format(median[2]);
}
return result;
}
Aggregations