Test Solutions

Easy: Skinny PP Index Implementation

This test evaluated the ability to integrate external statistical measures into the tourr framework as projection pursuit indices. The task involved implementing a new projection pursuit index based on the scagnostic "skinny" measure.

Overview

Projection pursuit (PP) indices quantify how "interesting" a 2D projection is. This test involved implementing a new index based on the "skinny" scagnostic—a measure from the cassowaryr package that detects elongated point patterns.

The objective was to create a PP index that integrates seamlessly with tourr's optimization and guided tour methods.

Approach

tourr defines PP indices as factory functions: an outer function that returns an inner function accepting a 2D projection matrix and returning a numerical score. This pattern allows efficient optimization without recomputing the original data.

The implementation wraps cassowaryr's sc_skinny(x, y) function, extracting columns from the projection matrix and passing them to the scagnostics function.

Implementation

Code snippetFull code available in PR #141

skinny <- function(){
  function(mat){
    sc_skinny(mat[,1], mat[,2])
  }
}

The function returns a closure that delegates directly to cassowaryr::sc_skinny(), making it immediately compatible with tourr's guided tour and optimization methods.

Results

✓ Implementation passes R CMD check
✓ Integrates cleanly with scagnostics
✓ Works with all tourr guided tour methods
✓ Produces meaningful PP scores on real datasets