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
anne_sa
Level VI

How to know if a table is a linked subset?

Hello everybody,

 

I would like to determine (using JSL) if the current data table is linked to a main table or not.

I tried "<< Get Table Variable Names" but it didn't work.

Do you have any idea of how we can get this information?

 

Thanks in advance for your help!

24 REPLIES 24
ian_jmp
Level X

Re: How to know if a table is a linked subset?

Regarding "In particular, it saves the residuals and other columns from the Fit Model platform, in the current data table" then perhaps I have mis-understood. But you should always be able to get the 'Fit Model' predictions to go to the correct table:

NamesDefaultToHere(1);

// Open a table
dt1 = Open("$SAMPLE_DATA/Big Class.jmp");
// Open another table
dt2 = Open("$SAMPLE_DATA/Bands Data.jmp");
// Direct the analysis to the first table
fml = dt1 << Fit Model(
				Y( :height ),
				Effects( :weight )
				);
fm = fml << Run;
// Prediction formula goes to the first, not the current table
Print(CurrentDataTable());
fm << predictionFormula;

 

anne_sa
Level VI

Re: How to know if a table is a linked subset?

In fact, if I work with a subset linked to a table and if I save the Fit Model residuals, they are stored in the first main table. However, I have just remarked that prediction formula are saved in both tables! That is quite strange...

 

NamesDefaultToHere(1);

// Open a table
dt1 = Open("$SAMPLE_DATA/Big Class.jmp");

// Create a subset
dt2=dt1 << Subset(
	Selected Rows( 0 ),
	Rows( [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ),
	Selected columns only( 0 ),
	link to original data table(1)
);


// Direct the analysis to the subset table
fml = dt2 << Fit Model(
				Y( :height ),
				Effects( :weight )
				);
fm = fml << Run;
// Prediction formula are saved in both dt1 and dt2 and residulas are saved only in dt1
fm << prediction formula;
fm << residuals;

In this example I would like to have residuals and prediction formula only in dt2.

ian_jmp
Level X

Re: How to know if a table is a linked subset?

I suppose that the 'correct' behaviour in this case is open to interpretation, but if you see something that you regard as undesirable, please do send an email to support@jmp.com.

In this case though, if you are are intending to use the linked subset tables to 'isolate' certain rows for analysis, a more conventional approach might be to use the data filter, or the local version thereof. If you are saving formulas that were generated using just part of the data, you may need some additional code to curate these.

 

anne_sa
Level VI

Re: How to know if a table is a linked subset?

Thank you for the additional information Ian.

Your are completely right, a "correct" behavior depends on the situation. I was not saying that one is better than another but just trying to explain why sometimes things go wrong with my script.

 

I also agree that creating a linked subset may not always be the best way to focus on some specific rows. However since my script can be used by other persons, I can't control what they have done before and what kind of table they are working with. So the idea is just to find a way to detect if a table is a linked one (ie not compatible with my script). In that case I could display a warning and stop the script.

 

Well if it is not feasible maybe I can find another way to deal with this particular case.

ian_jmp
Level X

Re: How to know if a table is a linked subset?

You could test this (along the lines I mentioned earlier):

NamesDefaultToHere(1);

// Function to determine if two tables are linked
rLinked = Function({dt1, dt2}, {Default Local},
	dt1 << selectAllRows;
	if(NRow(dt2 << getSelectedRows) > 0, linked = 1, linked = 0);
	dt1 << clearSelect;
	dt2 << clearSelect;
	linked;
);

// Look at the open tables in the session and see which pairs are linked
linkedTables = Function({}, {Default Local},
	nt = NTable();
	linkMat = J(nt, nt, .);
	tblNames = {};
	for(t1=1, t1<=nt, t1++,
		InsertInto(tblNames, DataTable(t1) << getName);
		for(t2=t1+1, t2<=nt, t2++,
			if(rLinked(DataTable(t1), DataTable(t2)), linkMat[t1, t2] = 1, linkMat[t1, t2] = 0);
			);
		);
	EvalList({linkMat, tblNames});
);

// Make some active tables
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
// Unlinked subset
dt << selectRandomly(0.1);
dt2 = dt << Subset(LinkToOriginalDataTable( 0 ) );
dt2 << setName("Unlinked");
// Linked subset
dt << selectRandomly(0.1);
dt3 = dt << Subset(LinkToOriginalDataTable( 1 ) );
dt3 << setName("Linked");

// Get the 'link matrix'
linkedOrNot = linkedTables();
dt4 = AsTable(linkedOrNot[1], << setName("Linked Tables"), << columnNames(linkedOrNot[2]));
dt4 << NewColumn("Column", Character, Values(linkedOrNot[2]));
dt4 << moveSelectedColumns({"Column"}, ToFirst);
anne_sa
Level VI

Re: How to know if a table is a linked subset?

Hello Ian,

 

Thank you for the code! I think I can use something like that to solve my problem. I just need to add an additional control for summary table. Maybe something like that could work: trying to get the "Source" script of a table and check if it contains the word "summary".

 

I need to do some tests...

Thanks again for your help.

ian_jmp
Level X

Re: How to know if a table is a linked subset?

Untested (as usual . . . ):

NamesDefaultToHere(1);
ClearLog();

// See if a table is a summary of another table
isSummary = 
Function({dt}, {Default Local},
	ts = dt << Get Table Script Names;
	if (Contains(ts, "Source"),
		ss = dt << getProperty("Source");
		if (Head(Arg(ss, 2)) == Expr(Summary), 1, 0),
		0
		);
	);

// Make a summary table
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt2 = dt1 << Summary(Mean( :height ));
Print(isSummary(dt1));
Print(isSummary(dt2));
anne_sa
Level VI

Re: How to know if a table is a linked subset?

Thank you one more time for your very fast answer Ian!

I am gonna combine the two parts and do some tests but I trust it should do the job! :)

 

 

hogi
Level XII

Re: How to know if a table is a linked subset?

It's strange that a user has to set up a decision tree to find out if a table is linked or not.

I would assume that Jmp knows which tables are linked.

So, why is such an information not accessible via JSL?

Is it?

edit: thanks for providing the feature with JMP18 : )
(see below)

 

 

Re: How to know if a table is a linked subset?

A JSL query to query a table about whether it is a linked subset did not previously exist. However, this conversation has caught the attention of JMP Development, and now a JSL message has been added in the next major release of JMP (JMP 18). 

dt << Is Linked Subset; //will return 1 or 0