Choose Language Hide Translation Bar
BHarris
Community Trekker

How do I create a custom transform function that takes multiple columns as inputs?

The scripting guide is pretty useful in describing how to make new custom transform functions, but it's not very clear on how to handle multiple columns.

 

How do I create a custom transform function that takes multiple columns as inputs?  E.g., if I select an X, a Y, and a Z columns and want to take the RSS (root-sum-squared) of those three columns?

 

Also, if the order matters, how is that order set?  Is it the order that the columns are selected in?

0 Kudos
9 REPLIES 9

Re: How do I create a custom transform function that takes multiple columns as inputs?

I think that a Custom Function is a better choice for your case. The Custom Transform is restricted to a single input. The Custom Function is not restricted in this way.

 

funcDef = Function( {x, y, z}, Sqrt( Sum( x^2, y^2, z^2 ) ) );

description = "This function returns the root sum squared of three numbers.";

// examples can be multiple statements inside expr()
ex2 = Expr(
	dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
	Here:RSS( :age[1], :age[2], :age[3] );
);

parmHint1 = "x value";
parmHint2 = "y value";
parmHint3 = "z value";

/* create function using variables
the commands can also be accepted as arguments in New Custom Function */
newAdd = New Custom Function( "Here", "RSS", funcDef );

newAdd << Description( description );
newAdd << Prototype( "Here:RSS(x,y,z)" );
newAdd << Example( "Here:RSS(1,2,3)" );

// expr() Examples need to be passed inside NameExpr()
newAdd << Example( Name Expr( ex2 ) );
newAdd << Parameter( "Number", parmHint1 );
newAdd << Parameter( "Number", parmHint2 );
newAdd << Parameter( "Number", parmHint3 );

newAdd << Formula Category( "NumberStuff" );

// add myNamespace:Add Ten function to system
Add Custom Functions( newAdd );

 

The expression inside your function might include logic to address any need for proper order.

Learn it once, use it forever!
BHarris
Community Trekker

Re: How do I create a custom transform function that takes multiple columns as inputs?

Thanks for the response, Mark! A couple quick follow-on questions:

1. I know JMP *supports* multi-column transform functions -- is it just that it doesn't support multi-column *custom* transforms yet?

2. Your function takes 3 arguments -- is it possible to define a function that takes an arbitrary number of arguments?
0 Kudos

Re: How do I create a custom transform function that takes multiple columns as inputs?

I avoid anything in double quotation marks. They usually have no lasting value. JMP provides custom functions and custom transforms. Why not use them as they were intended?

 

You could always use a list parameter instead of a scalar parameter if your function must work with a variable number of arguments.

Learn it once, use it forever!
BHarris
Community Trekker

Re: How do I create a custom transform function that takes multiple columns as inputs?

I'll look up list parameters, thx.

No clue what you're talking about on the double quotation marks, or the basis of the comment about JMP providing custom functions and transforms.
0 Kudos

Re: How do I create a custom transform function that takes multiple columns as inputs?

Here is a new function that takes a list and returns the same computation.

 

Names Default to Here( 1 );

// example
my numbers = List( 1, 2, 3, 4, 5 );

// define it
funcDef = Function( { number }, { i, sum },
	If( Is List( number ),
		Sqrt( Summation( i = 1, N Items( number ), number[i]^2 ) ),
		.
	);
);

// test it
Show( funcDef( my numbers ) );
Learn it once, use it forever!
BHarris
Community Trekker

Re: How do I create a custom transform function that takes multiple columns as inputs?

I copy/pasted that function out into a new JSL script and ran it, but the Log shows this error: "Cannot redefine a predefined JMP namespace"
0 Kudos

Re: How do I create a custom transform function that takes multiple columns as inputs?

OK, then replace the Here namespace with one of your own.

Learn it once, use it forever!
0 Kudos
BHarris
Community Trekker

Re: How do I create a custom transform function that takes multiple columns as inputs?

Sorry I'm so slow, I have no idea how to do that.
0 Kudos

Re: How do I create a custom transform function that takes multiple columns as inputs?

funcDef = Function( { number }, { i, sum },
	If( Is List( number ),
		Sqrt( Summation( i = 1, N Items( number ), number[i]^2 ) ),
		.
	);
);

description = "This function returns the root sum squared of a list numbers.";
parmHint = "a list of numbers";

/* create function using variables
the commands can also be accepted as arguments in New Custom Function */
newAdd = New Custom Function( "mySpace", "RSS", funcDef );

newAdd << Description( description );
newAdd << Prototype( "mySpace:RSS( {} )" );
newAdd << Example( "mySpace:RSS( {1,2,3} )" );

// expr() Examples need to be passed inside NameExpr()
newAdd << Parameter( "List", parmHint );

newAdd << Formula Category( "MyNumberStuff" );

// add mySpace:RSS function to system
Add Custom Functions( newAdd );
Learn it once, use it forever!