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
Thierry_S
Super User

JMP > JSL > Get Formula > Extract Parameters

Hi JMP Community,

 

I have generated multiple prediction formulas stored in columns and I need to extract the parameters to evaluate which variables are common across formulas.

When I call for dt:Column X << Get formula, the output is not a string or list that can be used with standard pattern extraction functions (e.g., Words (), Munger ()...).

Questions:

  1. Am I using the right function to collect the formula parameters by using << Get Formula?
  2. If not, what would be a more appropriate function?
  3. If yes, is there a trick to convert the << Get formula output to a string, list, or matrix?

Thank you for your help.

Best,

TS

Thierry R. Sornasse
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: JMP > JSL > Get Formula > Extract Parameters

Being pretty "Old School", I handle it by retrieving the formula as a character string

Names Default To Here( 1 );
dt = Current Data Table();
x = Char( dt:predicted height << get formula );
Jim

View solution in original post

4 REPLIES 4
txnelson
Super User

Re: JMP > JSL > Get Formula > Extract Parameters

Being pretty "Old School", I handle it by retrieving the formula as a character string

Names Default To Here( 1 );
dt = Current Data Table();
x = Char( dt:predicted height << get formula );
Jim
Thierry_S
Super User

Re: JMP > JSL > Get Formula > Extract Parameters

Hi txnelson,

That was simple. 

Thanks.

Best,

TS

Thierry R. Sornasse
peng_liu
Staff

Re: JMP > JSL > Get Formula > Extract Parameters

If the interest is in the variable names inside the formula, it might be easier to work directly with the formula expression. Here is an example which extracts unique symbol names out of a formula.

dt = open("$sample_data/Reliability/Locomotive.jmp");
ex = column(dt, 3)<<getformula;

get_vars = function({ex},{parse_expr, elems},
	elems = {};
	parse_expr = function({ex},{i,exi},
		for (i=1,i<=narg(ex),i++,
			exi = arg(ex,i);
			if (narg(exi)==0,
				if (isname(nameexpr(exi)),
					insert into(elems, lowercase(char(nameexpr(exi))));
				)
				,
				parse_expr(arg(ex,i));
			)
		)
	);

	parse_expr(nameexpr(ex));
	aa = Associative Array( elems );
	aa << get keys
);

show(get_vars(nameexpr(ex)));

Re: JMP > JSL > Get Formula > Extract Parameters

I'm going to document another approach to this here.  (Thanks to @Byron_JMP for the Arg() tutorial on this)

 

You can go through an Arg() command to get the parameters as a list that you can work with pretty easily.  I've also put a function below that returns the parameters for a  column formula as an Associative Array.  

 

// For a given column, col, in a data table, dt, you can get the formula column property with a message:

formula = dt:Col << Get Formula;

// the first argument of which is the parameters list which can be extracted using Arg()

params = Arg(formula, 1);

// from there you can index down to get the parameter / value pair

parameterName1 = Arg(params[1],1);
parameterValue1 = Arg(params[1],2);

And the Function that returns the formula parameters as an associative array

// This function expects a column reference

formulaParameters = Function( {colref},
	{default local}, 
	
	plist = Arg( colref << Get Formula, 1 );
	
	keys = {};
	values = {};
	For Each( {value, index}, plist,
		Insert Into( keys, Arg( value, 1 ) );
		Insert Into( values, Arg( value, 2 ) );
	);

	parameters = Associative Array( keys, values );	
	
);

// Usage example: 
dt = Current Data Table();
columnWithParameters = dt:Col1 << Get Column Reference();

parameterAArray = formulaParameters( columnWithParameters );