Externally Studentized ResidualsHi, all!
I have a customer that's would like to access the externally studentized residuals used for the studentized residuals plot in Least Squares Regression. Anybody have a way to calculate that outside of the platform or know how to get at those values?
Best,
M
Re: Externally Studentized ResidualsLooks to me like the Save Columns > studentized residuals are the values that are plotted on that graph.
Ledi
Re: Externally Studentized ResidualsI thought so too, but in the doc’s say they’re different (https://www.jmp.com/support/help/14-2/row-diagnostics.shtml ).
M
Re: Externally Studentized ResidualsI didn't look at any of the numbers, but you can always get the values directly from the marker seg in the report:
NamesDefaultToHere(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
// Fit Model
fm = dt << Fit Model(
Y( :height ),
Effects( :weight ),
Personality( "Standard Least Squares" ),
Emphasis( "Effect Leverage" ),
Run(
:height << {Summary of Fit( 0 ), Analysis of Variance( 0 ),
Parameter Estimates( 0 ), Effect Tests( 0 ), Effect Details( 0 ),
Lack of Fit( 0 ), Scaled Estimates( 0 ), Plot Actual by Predicted( 1 ),
Plot Residual by Predicted( 1 ), Plot Studentized Residuals( 1 ),
Plot Effect Leverage( 1 ), Plot Residual by Normal Quantiles( 0 ),
Box Cox Y Transformation( 0 )}
),
SendToReport(
Dispatch(
{"Response height", "Whole Model"},
"Regression Plot",
OutlineBox,
{Close( 1 )}
),
Dispatch(
{"Response height", "Whole Model"},
"Actual by Predicted Plot",
OutlineBox,
{Close( 1 )}
)
)
);
// Get values directly from the marker seg . . .
fmRep = Report(fm);
frame = fmRep[FrameBox(4)];
mySeg = (frame << Find Seg( Marker Seg( 1 ) ));
xVals = mySeg << Get X Values;
yVals = mySeg << Get Y Values;
dt2 = asTable(xVals||yVals, << columnNames({"Row Number", "Studentized Residual"}));
dt2 << setName("Residuals");Re: Externally Studentized ResidualsThat is interesting. I tried right-clicking and selecting Customize in the plot to see what might be available. There is nothing I can use so I didn't think of the segments.
Re: Externally Studentized ResidualsFWIW, this method has never failed me (yet . . . ).
Re: Externally Studentized ResidualsAwesome! Thanks, @ian_jmp!
That got them!
Also, I was puzzling over this last night and stumbled onto an equation that will convert the studentized residuals to the externally studentized residuals. You just need to provide the number of factors in the model. The equation is out of Weisburg's Applied Linear Regression. it's on page 216 in the 4th edition. I added a script at the end of your script so that everything is in one place.
Best,
M
</CODE></P>
<PRE><CODE class=" language-jsl">Names Default To Here( 1 );
Clear Log();
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
// Fit Model
fm = dt << Fit Model(
Y( :height ),
Effects( :weight ),
Personality( "Standard Least Squares" ),
Emphasis( "Effect Leverage" ),
Run(
:height << {Summary of Fit( 0 ), Analysis of Variance( 0 ), Parameter Estimates( 0 ), Effect Tests( 0 ), Effect Details( 0 ),
Lack of Fit( 0 ), Scaled Estimates( 0 ), Plot Actual by Predicted( 1 ), Plot Residual by Predicted( 1 ),
Plot Studentized Residuals( 1 ), Plot Effect Leverage( 1 ), Plot Residual by Normal Quantiles( 0 ),
Box Cox Y Transformation( 0 )}
),
SendToReport(
Dispatch( {"Response height", "Whole Model"}, "Regression Plot", OutlineBox, {Close( 1 )} ),
Dispatch( {"Response height", "Whole Model"}, "Actual by Predicted Plot", OutlineBox, {Close( 1 )} )
)
);
/*METHOD 1
Pull Externally Studentized Residuals from the plot */
// Grab the report object
fmRep = Report( fm );
// Grab the ESR plot frame box
frame = fmRep[FrameBox( 4 )];
// Grab the marker segment in the frame box and pull the values
mySeg = (frame << Find Seg( Marker Seg( 1 ) ));
yVals = mySeg << Get Y Values;
/*METHOD 2
Convert Studentized Residuals to Externally Studentized Residuals (Applied Linear Regression, 4th Ed, 2014 - pg 216)
note the denominator removes one df for the intercept so p should be the df from the model ANOVA*/
// define the total number of terms in the model from the model ANOVA
p = 1;
//export the studentized residuals to the data table and gather table information
fm << Studentized Residuals;
r = Column( N Cols() );
n = N Rows( dt );
// create a blank matrix for the values
ESR = [];
// loop through the residuals matrix (last column in the dt) and calculate the ESR.
For( i = 1, i <= n, i++,
// calculation per reference above
k = r[i] * Sqrt( (n - p - 2) / (n - p - 1 - (r[i] ^ 2)) );
// insert the ESR value into the matrix
ESR = V Concat( ESR, k );
);
// create a new column in the data table with the values (from both methods and method 2 as a formula column)
dt << New Column( "Externally Studentized Residuals (From Report)", Set Values( yVals ) );
dt << New Column( "Externally Studentized Residuals", Set Values( ESR ) );
dt << New Column( "Externally Studentized Residuals (Formula)",
Formula(
Parameter(
{p = 1},
:Studentized Resid height * Sqrt( (N Rows() - p - 2) / (N Rows() - p - 1 - :Studentized Resid height ^ 2) )
)
)
);