Choose Language Hide Translation Bar
Staff

## 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;

Community Trekker

## 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 ),
);

// 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.

Staff

## 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.

Community Trekker

## 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.

Staff

## 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;
dt1 << clearSelect;
dt2 << clearSelect;
);

// Look at the open tables in the session and see which pairs are linked
nt = NTable();
tblNames = {};
for(t1=1, t1<=nt, t1++,
InsertInto(tblNames, DataTable(t1) << getName);
for(t2=t1+1, t2<=nt, t2++,
);
);
);

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

dt4 << moveSelectedColumns({"Column"}, ToFirst);
Highlighted
Community Trekker

## 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...

Staff

## 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));
Community Trekker