OK, thanks for clarifying.
Names Default to Here( 1 );
// check for sufficient tables
n tables = N Table();
If( n tables < 2,
Throw( "Two data tables are required for this analysis" )
);
tables = List();
For( t = 1, t <= n tables, t++,
Insert Into( tables, Eval( Data Table( t ) << Get Name ) );
);
// identify the calibration and unknown data tables
dlg = New Window( "Assay Unknown Samples", << Modal,
H List Box(
lb = List Box( tables ),
Line Up Box( N Col( 2 ),
Button Box( "Calibrator Table",
sel = lb << Get Selected;
cal lb << Append( sel );
),
cal lb = List Box( {},
N Lines( 1 )
),
Button Box( "Unknown Table",
sel = lb << Get Selected;
unk lb << Append( sel );
),
unk lb = List Box( {},
N Lines( 1 )
)
)
),
H List Box(
Button Box( "OK",
cal table = cal lb << Get Items;
Show( cal table );
unk table = unk lb << Get Items;
Show( unk table );
),
Button Box( "Cancel" )
)
);
If( dlg["Button"] == -1,
Throw( "User cancelled" )
);
// unload the dialog
cal table = Data Table( cal table[1] );
unk table = Data Table( unk table[1] );
// include AU 2 values for calibrators from calibration table
combined = cal table << Join(
With( unk table ),
Copy formula( 0 ),
Select With( :Sample, :Peps, :AU 1 ),
Select( :AU 2 ),
By Matching Columns( :Peps = :Peps ),
Drop Multiples( 0, 0 ),
Include Nonmatches( 0, 1 ),
Preserve Main Table Order( 0 )
);
Close( cal table, No Save );
Close( unk table, No Save );
// distinquish peps
Current Data Table( combined );
combined << New Column( "Status", "Character", "Nominal" );
For Each Row(
:Status = If( 1 <= Num( Regex( :Peps, "\w{3}(\d+)", "\1" ) ) <= 29, "Calibrator", "Unknown" );
);
// fit the calibration curve
dlg = combined << Fit Model(
Y( :AU 1 ),
Effects( :AU 2 ),
Personality( "Standard Least Squares" ),
Emphasis( "Minimal Report" ),
Where( :Status == "Calibrator" )
);
fit = dlg << Run;
// determine the assay for the unknown samples from the calibration curve
For Each Row(
fit << Inverse Prediction( Response( :AU 1[] ) );
);
// extract the assays into a new data table
assays = Report( fit )["Inverse Prediction"][TableBox(1)] << Make Combined Data Table;
fit << Close Window;
assays << Delete Columns( Column( assays, 1 ) );
// add the assays to the unknown table
final = combined << Join(
With( assays ),
Copy formula( 0 ),
By Matching Columns( :AU 1 = :Specified AU 1 ),
Drop Multiples( 0, 0 ),
Include Nonmatches( 1, 0 ),
Preserve Main Table Order( 1 )
);
Close( combined, No Save );
Close( assays, No Save );
final << Sort(
By( :Peps, :Sample ),
Order( Ascending, Ascending ),
Replace Table
);
Some of the predicted AU 2 values are missing due to the random measurements of AU 1.