@Mark_Bailey Below is one of my examples. I need a generic code which needs to read the scripts from Fit group model, and then get the Term Value into a factors list. Once I have the list, I will compare with column name in the data table to determine they are number or character so that I can make my simulation code. The last part is my code, but it's too complicated and it won't work if there are multiple Term Value in the profiler. So it's better to leave only Profiler on. I wonder if you have easier way to finish the same task? Thank you so much for your help.
factors = {"ELONG", "HARDNESS(+/-0.2)", "ABRASION For example (%)", "MODULUS"}
This is the script from an example model:
Fit Group(
Fit Model(
Y( :"SILICA (%)"n ),
Effects( :ELONG, :"HARDNESS(+/-0.2)"n ),
Personality( "Standard Least Squares" ),
Emphasis( "Minimal Report" ),
Run(
Profiler(
1,
Confidence Intervals( 1 ),
Term Value(
ELONG( 417.5, Lock( 0 ), Show( 1 ) ),
"HARDNESS(+/-0.2)"n( 69.775, Lock( 0 ), Show( 1 ) )
)
),
:"SILICA (%)"n << {Summary of Fit( 1 ), Analysis of Variance( 1 ),
Parameter Estimates( 1 ), Effect Tests( 0 ), Effect Details( 0 ),
Lack of Fit( 0 ), Scaled Estimates( 0 ), Plot Actual by Predicted( 1 ),
Plot Regression( 0 ), Plot Residual by Predicted( 0 ),
Plot Studentized Residuals( 1 ), Plot Effect Leverage( 0 ),
Plot Residual by Normal Quantiles( 1 ), Box Cox Y Transformation( 0 ),
Press( 1 )}
)
),
Fit Model(
Y( :SILANE Value ),
Effects(
:"ABRASION For example (%)"n, :MODULUS, :ELONG, :"HARDNESS(+/-0.2)"n,
:MODULUS * :ELONG
),
Personality( "Standard Least Squares" ),
Emphasis( "Minimal Report" ),
Run(
Profiler(
1,
Confidence Intervals( 1 ),
Term Value(
"ABRASION For example (%)"n( 133.1, Lock( 0 ), Show( 1 ) ),
MODULUS( 1255, Lock( 0 ), Show( 1 ) ),
ELONG( 417.5, Lock( 0 ), Show( 1 ) ),
"HARDNESS(+/-0.2)"n( 69.775, Lock( 0 ), Show( 1 ) )
)
),
:SILANE Value << {Summary of Fit( 1 ), Analysis of Variance( 1 ),
Parameter Estimates( 1 ), Effect Tests( 0 ), Effect Details( 0 ),
Lack of Fit( 0 ), Scaled Estimates( 0 ), Plot Actual by Predicted( 1 ),
Plot Regression( 0 ), Plot Residual by Predicted( 0 ),
Plot Studentized Residuals( 1 ), Plot Effect Leverage( 0 ),
Plot Residual by Normal Quantiles( 1 ), Box Cox Y Transformation( 0 ),
Press( 1 )}
)
),
Fit Model(
Y( :SULFUR ),
Effects( :ELONG ),
Personality( "Standard Least Squares" ),
Emphasis( "Minimal Report" ),
Run(
Profiler(
1,
Confidence Intervals( 1 ),
Term Value( ELONG( 417.5, Lock( 0 ), Show( 1 ) ) )
),
:SULFUR << {Summary of Fit( 1 ), Analysis of Variance( 1 ),
Parameter Estimates( 1 ), Effect Tests( 0 ), Effect Details( 0 ),
Lack of Fit( 0 ), Scaled Estimates( 0 ), Plot Actual by Predicted( 1 ),
Plot Regression( 0 ), Plot Residual by Predicted( 0 ),
Plot Studentized Residuals( 1 ), Plot Effect Leverage( 0 ),
Plot Residual by Normal Quantiles( 1 ), Box Cox Y Transformation( 0 ),
Press( 1 )}
)
),
<<{Profiler(
1,
Confidence Intervals( 1 ),
Term Value(
ELONG( 417.5, Lock( 0 ), Show( 1 ) ),
"HARDNESS(+/-0.2)"n( 69.775, Lock( 0 ), Show( 1 ) ),
"ABRASION For example (%)"n( 133.1, Lock( 0 ), Show( 1 ) ),
MODULUS( 1255, Lock( 0 ), Show( 1 ) )
)
)}
);
This is my code to make factors list:
Names Default To Here( 1 );
dt = Current Data Table();
curep = Current Report();
dtname = dt << Get Name;
//Check how many prediction profiles, if >1 it's fit group, =1 it's fit model
pred_objs = curep << XPath( "//OutlineBox[ contains( text(), 'Prediction Profile' ) ]" );
num_objs = N Items( pred_objs );
If( num_objs < 1,
Throw( "No prediction profile is found!" )
);
If( num_objs == 1,
textind = "Profiler(",
textind = "{Profiler("
);
//Read the Model Term list
modelobj = curep[Outline Box( 1 )] << get scriptable object;
modeltext = Char( modelobj << get script );
//Show( modeltext );
posA = Contains( modeltext, textind );
termstext = Right( modeltext, Length( modeltext ) - posA + 1 );
/*Show( termstext );*/
posB = Contains( termstext, "Term Value" );
posC = Contains( termstext, "Show(1))", -1 );
termvalue = Left( termstext, posC + 7 ) || ","; //Make sure all terms end with )),
termvalue = Right( termvalue, Length( termvalue ) - posB - 10 );
/*Show( termvalue );
Show( posB );
Show( posC );
Show( posD );*/
//Check how many factors or main effects in the final model
words = Words( termvalue, "," );
termnum = 0;
For( i = 1, i <= N Items( words ), i++,
If( Contains( words[i], "Show" ),
termnum = termnum + 1
)
);
//Get the term with default value
term list = {};
For( k = 1, k <= termnum, k++,
//show(firstpos);
pos1 = Contains( termvalue, "))," ) + 3;
term1 = Left( termvalue, pos1 );
//show(term1);
termvalue = Right( termvalue, Length( termvalue ) - pos1 );
//show(termvalue);
Insert Into( term list, term1 );
);
Show( term list );
//get term name without default value
factors = {};
For( k = 1, k <= N Items( term list ), k++,
termK = term list[k];
firstchar = Left( termK, 1 );
If( firstchar == "\!"",
pos2 = Contains( termK, "\!"", -1 );
term2 = Left( termK, pos2 + 1 );
,
pos2 = Contains( termK, "(" ); //Categorical terms cannot have "()" in the column name
term2 = Left( termK, pos2 - 1 );
);
Insert Into( factors, char(parse(term2)) );
);
Show( factors );