Regression - Diagnostic - Prediction-Accuracy Table extension

From Q
Jump to: navigation, search

Create a table showing the observed and predicted values, as a heatmap

Creates a table showing the observed and predicted values, as a heatmap. This is also referred to as a confusion matrix, classification-accuracy, and hit-miss table.


The footer of the table firstly describes the data that were used to fit the model. In this example there were 149 cases in the 70% of data used for training, of which only 116 were used after removing cases with missing values. It then gives the accuracy for the prediction data and a count of the number of predictions that are paired with observations (after accounting for missing values in the prediction data).


includeWeb("QScript R Output Functions");

var is_displayr = (!!Q.isOnTheWeb && Q.isOnTheWeb());
if (!is_displayr)
    if (Q.fileFormatVersion() >= 17.13)
        alert("Please update Q to use this feature from the extension button, or run it from the menu via Create > Regression > Diagnostic > Prediction-Accuracy Table.");

function main() {

    // The following 2 variables contain information specific to this diagnostic.
    var required_class = ["MachineLearning", "MachineLearningEnsemble", "Regression"];
    var output_name_suffix = "prediction.accuracy.table";
    var item = checkSelectedItemClass(required_class);
    if (item == null)
        return false;
    var r_name = stringToRName(item.referenceName);

    // The following lines contain the R code to run
    var expression = "library(flipRegression)\nConfusionMatrix(" + r_name + ", QFilter, QPopulationWeight)";

    return createROutput(item, expression, output_name_suffix);