This could be done with column formulas but it would get messy. This script should do the trick:
dlg = Column Dialog(
Title( "Evaluate Model" ),
yCol = Col List( "Response",
Data Type( Numeric ),
Min Col( 1 ),
Max Col( 1 )
),
mCol = Col List( "Model",
Data Type( Numeric ),
Min Col( 1 ),
Max Col( 1 )
)
);
If( dlg["Button"] == -1,
Throw( "User cancelled" );
);
Remove From( dlg );
Eval List( dlg );
dt = Current Data Table();
response = yCol[1] << Get As Matrix;
model = mCol[1] << Get As Matrix;
residual = model - response;
sst = Sum( (response - Mean( response ) )^2 );
sse = Sum( residual^2 );
ssm = sst - sse;
r square = ssm / sst;
dt << New Column( "Residual", Values( residual ) );
New Window( "Evaluate Model",
dt << Graph Builder(
Variables( X( mCol[1] ), Y( yCol[1] ) ),
Elements( Points( X, Y, Legend( 3 ) ) ),
Show Control Panel( 0 )
),
dt << Graph Builder(
Variables( X( :Residual ), Y( yCol[1] ) ),
Elements( Points( X, Y, Legend( 3 ) ) ),
Show Control Panel( 0 )
),
Text Box( "R square is " || Char( r square ) )
);