- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
How to graph the last N values of a column?
Hi All,
I'm still relatively new to JSL, so building my script codes as I move along.
I'm trying to add to a control chart window the graph of the last 25 data points in a column of M values, e.g. colum(M-25) to (M).
I'm thinking of modifying the chart builder script to do this:
Control Chart Builder(
Size( 534, 454 ),
Show Two Shewhart Charts( 0 ),
Show Control Panel( 0 ),
Show Limit Summaries( 0 ),
Show Capability( 0 ),
Variables( Y( :Name( "MyColumn" ) ) ),
Chart(
Points( Statistic( "Individual" ) ),
Limits( Sigma( "Moving Range" ) ),
Warnings( Test Beyond Limits( 1 ) )
),
SendToReport(
Dispatch(
{},
"graph display 1 title",
TextEditBox,
{Set Text( "Last 25 Observations" )}
),
Dispatch( {}, "MyColumn Limit Summaries", OutlineBox, {Close( 1 )} )
)
)
The problem I'm having is how to chose only those last N values to display (N could be 25 or 30 or 100). My experience with other programming languages like Igor or Matlab aren't translating over to JSL for how to graph just a subset of data from a column.
If possible, I'd prefer to have it plot the data vs row index, like in the control charts, and I know the Overlay plot can do that, but I also like having the Avg show up in the graph. I would prefer to NOT plot the data as a Fit Y by X.
Thanks!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to graph the last N values of a column?
Here is an example with Bivariate and Big Class that could be adapted:
Names Default to Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
last n = 5;
n = N Row( dt );
biv = dt << Bivariate(
Y( :weight ),
X( :height ),
Where( Row() > (n - last n) )
)
It is simple.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to graph the last N values of a column?
Here is an example with Bivariate and Big Class that could be adapted:
Names Default to Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
last n = 5;
n = N Row( dt );
biv = dt << Bivariate(
Y( :weight ),
X( :height ),
Where( Row() > (n - last n) )
)
It is simple.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to graph the last N values of a column?
Worked! Thanks.
Had to modify slightly for the specifics, but worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to graph the last N values of a column?
Can you share the exact code you used to control chart the last N column please. I'm not having luck for the modification.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to graph the last N values of a column?
Hi @Godwin ,
Each particular situation is a little different and might require a slight modification of the code for the specifics at hand. If you can share a data table and your code that you're working with, that might help me and others on this thread to better address the specifics of what you're trying to do.
Thanks!,
DS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to graph the last N values of a column?
@Mark_Bailey Thanks for the help.
I'm now looking to try and modify that code so it graphs the last N non-zero values. I have several rows in a column that might have missing values and want to graph only those rows which have an entry. Right now, if there is only one or two rows within the past N (in my case 25) that are non-zero, then it only graphs those one or two rows.
Your help/fedback is greatly appreciated. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to graph the last N values of a column?
Here is a simple modification to the script that @Mark_Bailey wrote, that finds the row that has the last x number of nonzero values
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt:weight[38] = 0;
last n = 0;
For( i = N Rows( dt ), i >= 1, i--,
If( :weight[i] > 0, last n++ );
If( last n == 5, Break() );
);
last n = N Row( dt ) - i;
n = N Row( dt );
biv = dt << Bivariate(
Y( :weight ),
X( :height ),
Where( Row() > (n - last n) )
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to graph the last N values of a column?
Hi @txnelson, thanks for the suggestion. I ended up slightly changing the code so that it looked for empty entries rather than just non-zero entries. Your method worked and I just needed to slightly adapt it to my specific situation.
Thanks again!
lastNmiss = 0;
For( ii = N Rows( dt ), ii >= 1, ii--,
If( IsMissing(dt:weight[ii])!=1, lastNmiss++ );
If( lastnmiss == 8, Break() );
);
lastNmiss = N Row( dt ) - ii;
n = N Row( dt );
biv = dt << Bivariate(
Y( :weight ),
X( :height ),
Where( Row() > (n - lastnmiss) )
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to graph the last N values of a column?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content