cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Graph Builder Toolbar streamlines interactive graphing. Creates shortcuts on Report and GraphBuilder Helpers toolbars. Download and install the extension.
  • JMP will suspend normal business operations for our Rest and Recharge Day on Friday, October 2, 2026.
    Regular business hours will resume on Monday, October 5, 2026.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
GroupSquareWolf
Level III

Analysis with user selected columns - Scripting

Trying to write a script to perform curve fitting based on user selected columns. 

In the example below, the goal is to fit linear with X and Y based on :Group and/or  :Type. User can select either or both columns and then run the script. 

GroupSquareWolf_0-1653561622492.png

This is what I've got

 

dt1 = current datatable();

sc = dt1 << get selected Columns;
scn= column (sc) << get name;

show (sc);
show (scn); obj = dt1 <<Fit Curve( Y( :Y ), X( :X ), Fit linear, By( scn )
// By (sn) );

In Log

show (sc); spits out:      sc = {:Group, :Type};

show (scn); spits out;      scn = "Group";

 

In Fit curves, neither "By (scn)" nor "By(sc)" can achieve the function of "By (:Group, :Type) or By(:Group).

 

What is the correct code to make this work?

 

Thanks!

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Analysis with user selected columns - Scripting

One option would be to add Eval() around scn:

Names Default To Here(1);

dt1 = Current Data Table();

sc = dt1 << get selected Columns;
scn = Column(sc) << get name;

Show(sc);
Show(scn);

obj = dt1 << Fit Curve(
	Y(:Y),
	X(:X),
	Fit linear,
	By(Eval(scn))//  By (sn)
);
-Jarmo

View solution in original post

pmroz
Super User

Re: Analysis with user selected columns - Scripting

This works too:

Names Default To Here(1);

dt1 = New Table( "Test", Add Rows( 6 ),
	New Column( "X", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [1, 2, 3, 1, 2, 4] ) ),
	New Column( "Y", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [3, 2, 5, 6, 4, 3] ) ),
	New Column( "XY Group", Character, "Nominal", Set Selected, 
		Set Values( {"A", "A", "A", "B", "B", "B"} ) )
);

sc = dt1 << get selected Columns;
scn = Column(sc[1]) << get name;	// sc is a list - get the first highlighted column

Show(sc);
Show(scn);

obj = dt1 << Fit Curve(
	Y(:Y),
	X(:X),
	Fit linear,
	by (column(dt1, scn))
);

View solution in original post

2 REPLIES 2
jthi
Super User

Re: Analysis with user selected columns - Scripting

One option would be to add Eval() around scn:

Names Default To Here(1);

dt1 = Current Data Table();

sc = dt1 << get selected Columns;
scn = Column(sc) << get name;

Show(sc);
Show(scn);

obj = dt1 << Fit Curve(
	Y(:Y),
	X(:X),
	Fit linear,
	By(Eval(scn))//  By (sn)
);
-Jarmo
pmroz
Super User

Re: Analysis with user selected columns - Scripting

This works too:

Names Default To Here(1);

dt1 = New Table( "Test", Add Rows( 6 ),
	New Column( "X", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [1, 2, 3, 1, 2, 4] ) ),
	New Column( "Y", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [3, 2, 5, 6, 4, 3] ) ),
	New Column( "XY Group", Character, "Nominal", Set Selected, 
		Set Values( {"A", "A", "A", "B", "B", "B"} ) )
);

sc = dt1 << get selected Columns;
scn = Column(sc[1]) << get name;	// sc is a list - get the first highlighted column

Show(sc);
Show(scn);

obj = dt1 << Fit Curve(
	Y(:Y),
	X(:X),
	Fit linear,
	by (column(dt1, scn))
);

Recommended Articles