cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
SDF1
Super User

How to use graph builder to graph a matrix in memory

Hi All,

 

  I have a script where I am testing out the autocorrelation of two columns in a data table. This is done on the Big Clas.jmp file.

SDF1_0-1692044308055.png

  I want to add to this script a panel that also shows the graph of the autocorrelation between the two columns -- specifically, I'm trying to graph the column called Lag and the column called Corr vs weight in the Time Series report shown above.

 

  I can get those two columns as a list of numbers in a matrix form by using the command <<Get As Matrix to the number column box in the report sub-panel.

 

I have a variable in memory called LagData, which is: [-39, -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24, -23,
-22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5,
-4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39]

 

And another variable in memory called CorrData, which is:[-0.0647505789131993, -0.0562977495028363, -0.160576535513772, -0.0235481399032656,
-0.207169184582488, -0.177727203882624, -0.082867673832995, -0.301048676439611,
-0.18208292918265, -0.12254560898792, -0.249310826860239, -0.088652621497092,
-0.0624774347722481, -0.137178123667694, -0.136824220987067, -0.144133672506173,
-0.0234936933370152, -0.117060117438199, 0.00715972346191791, -0.0454901061021466,
0.045163426704645, 0.0733531363807509, 0.0781580458523421, 0.0903268534092898,
0.0715972346191779, 0.269592172788486, 0.201125615728702, 0.207931436509992,
0.240014075672996, 0.198879694870876, 0.242681957419262, 0.29961945407554,
0.123566482105113, 0.342536959922359, 0.348675810267083, 0.0338521525661397,
0.352909030793046, 0.122885900026984, 0.0684665570597841, 0.709166525410487,
-0.132073758081727, 0.239510444935181, 0.186710887313928, -0.0461434648971507,
0.148366893032136, -0.0517650728624969, -0.0831943532304971, 0.025549051212965,
0.0530445671693793, -0.0655672774069544, -0.107858647741894, -0.0662478594850834,
-0.125907684453877, -0.0405899151396176, -0.151470347308405, -0.0967923831515159,
-0.0551815948947048, -0.136388648457065, -0.141914974931473, -0.158684517336573,
-0.0462523580296514, -0.0891426405933452, -0.019900219964494, -0.22426540638509,
-0.0337568710752018, -0.13129789451266, -0.0399637796277388, -0.00593467572128552,
-0.217418750679112, 0.092137201737113, -0.0450409219305816, -0.106334143886885,
0.105109096146253, -0.174569303040105, 0.0144827866225865, 0.0175998525404177,
-0.0346688510598947, 0.0216697333676295, -0.0202813459282462]

 

  I'd like to be able to send these matrices to Graph Builder to get something like this:

SDF1_1-1692044518016.png

But GB doesn't like that the data is a list of numbers -- it wants the inputs for X() and Y() to be columns. The above example was done by right clicking on the report and selecting Make Into Data Table and then using GB in the normal way. I'd prefer to not have to do that though.

 

Is there a way to send to GB the data that's in memory instead of as columns? I tried the below code, but it doesn't work.

gb = Graph Builder(
Graph Spacing( 4 ),
Variables( X( LagData ), Y( CorrData ) ),
Elements( Points( X, Y, Legend( 3 ) ) )
);

Below is my full code if you're interested.

//GUI for quickly reporting statistics and outlier analysis written by D. Schmidt, ver1.0
Names Default To Here( 1 );
Clear Symbols();
//the width of the column list box in pixels
lbWidth = 150;

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );//Current Data Table();

//Expression to recall roles
RecallRoles = Expr(
	::ycolRecall = ColListY << GetItems;
	::xcolRecall = ColListX << GetItems;
	::ALRecall = AlBox << Get;
	::FPRecall = FPBox << Get;
);

//Expression to clear roles
ClearRoles = Expr(
	Try(
		ColListY << Remove All;
		ColListX << Remove All;
		ALBox << Set( . );
		FPBox << Set( . );
	)
);

//User window
ValueDlg = Expr(
	nwin = New Window( "GUI for visualizing cross correlations",
		<<Return Result,
		<<On Validate,
		Border Box( Left( 3 ), Top( 2 ),
			V List Box(
				Outline Box( "Cross Correlations",
					<<Set Font Size( 12 ),
					H List Box(
						Panel Box( "Select Columns",
							ColListData = Col List Box( dt, All, Grouped, width( lbWidth ), nLines( 10 ) )
						),
						V List Box(
							Panel Box( "Cast Selected Columns into Roles",
								Lineup Box( N Col( 2 ), Spacing( 3, 2 ),
									Button Box( "Y, Time Series", ColListy << Append( ColListData << Get Selected ) ),
									ColListY = Col List Box( width( lbWidth ), nLines( 2 ), Min Items( 1 ) ),
									Button Box( "Input List", ColListx << Append( ColListData << Get Selected ) ),
									ColListX = Col List Box( width( lbWidth ), nLines( 2 ) )
								)
							),
							Panel Box( "Enter values",
								Spacer Box( <<Set Auto Stretching( 1, 1 ) ),
								Lineup Box( N Col( 2 ), Spacing( 5, 3 ),
									Text Box( "Autocorrleation Lags" ),
									ALbox = Number Edit Box( 100, 6 ),
									Text Box( "Forecast Periods" ),
									FPbox = Number Edit Box( 100, 6 )
								),
								Spacer Box( <<Set Auto Stretching( 1, 1 ) )
							)
						),
						Panel Box( "Action",
							Lineup Box( N Col( 1 ),
								Button Box( "OK",
									ycols = ColListY << Get Items;
									xcols = ColListX << Get Items;
									AL = ALbox << Get;
									FP = FPbox << Get;
									RecallRoles;
									Try( ts << delete );
									Try( gb << Delete );
									TSPB << Append(
										ts = Time Series(
											Y( Eval( ycols ) ),
											Input List( Eval( xcols ) ),
											Cross Correlation( 1 ),
											Autocorrelation Lags( AL ),
											Forecast Periods( FP ),
											Input Series( Eval( xcols ), Autocorrelation Lags( AL ), Forecast Periods( FP ) )
										)
									);
									LagData = nwin[Number Col Box( 8 )] << Get As Matrix;
									CorrData = nwin[Number Col Box( 9 )] << Get As Matrix;
									GBPB << Append(
										gb = Graph Builder(
											Graph Spacing( 4 ),
											Variables( X( LagData ), Y( CorrData ) ),
											Elements( Points( X, Y, Legend( 3 ) ) )
										)
									);
								),
								Button Box( "Cancel/End", nwin << Close Window ),
								Spacer Box( <<Set Auto Stretching( 0, 1 ) ),
								Button Box( "Remove",
									ColListY << Remove Selected;
									ColListx << Remove Selected;
								),
								Button Box( "Recall",
									ClearRoles;
									Try(
										ColListY << Append( ::ycolRecall );
										ColListx << Append( ::xcolRecall );
										ALBox << Set( ::ALRecall );
										FPBox << Set( ::FPRecall );
									);
								),
								Button Box( "Relaunch",
									nwin << Close Window;
									ValueDlg;
								),
								Spacer Box( <<Set Auto Stretching( 0, 1 ) ),
								Button Box( "Help", Web( "https://www.jmp.com/en_ch/support/online-help-search.html?q=*%3A*" ) )
							)
						)
					),
					V List Box( H List Box(), H List Box( TSPB = Panel Box( "Time Series", ), GBPB = Panel Box( "Graph", ) ) )
				), 

			)
		), 

	), 

);

ValueDlg;

Any thoughts/feedback on how to do this are much appreciated.

Thanks!,

DS

2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: How to use graph builder to graph a matrix in memory

You will need to move the matrices to a data table to be able to use Graph Builder.  The data table will be in memory, so there isn't much difference between the two.  I suggest that when creating the new data table, that you specify it as being "private" and then no image of the table will be displayed.

Jim

View solution in original post

jthi
Super User

Re: How to use graph builder to graph a matrix in memory

I would also create new data table as needed as it is much easier to manage than matrices. With just lists/matrices you would have plot graph with Graph Box() and you would lose out the easy to use Graph Builder

-Jarmo

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: How to use graph builder to graph a matrix in memory

You will need to move the matrices to a data table to be able to use Graph Builder.  The data table will be in memory, so there isn't much difference between the two.  I suggest that when creating the new data table, that you specify it as being "private" and then no image of the table will be displayed.

Jim
jthi
Super User

Re: How to use graph builder to graph a matrix in memory

I would also create new data table as needed as it is much easier to manage than matrices. With just lists/matrices you would have plot graph with Graph Box() and you would lose out the easy to use Graph Builder

-Jarmo
SDF1
Super User

Re: How to use graph builder to graph a matrix in memory

Hi @txnelson and @jthi ,

 

  I was "afraid" of that. But, as you both pointed out, you can easily make the other data table (and in private) and it works just fine. I appreciate your input on this. I was hoping I could use the matrices, but as @jthi said, I would lose the easy use of GB, which I actually want to keep available.

 

Thank you both for your help!,

DS