cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
mhalwi
Level III

Create a formula for temporary variable

Hi all, 

 

im still new to JMP scripting. I need help to create a formula to make the value as a variable but with its own name. What i mean is as below. So, i want to create a formula that can make column 4 below as a variable for distribution graph. 

 

it is like Plastic = 0.424542

 

the problem right now is the formula name will be in the same which is t4 = :TYPE;:MIN;. So if i want to plot the min value for plastic in the distribution graph, it will take the min value for rock as the formula for rock is also t4. 

 

so, how i can make the formula so that the variable value become 

Plastic = :TYPE;:MIN;  

Paper = :TYPE;:MIN; 

 

and so on, then it can be independant variable already. really appreciated if someone can help on this. i have look in the internet for few hours already. 

 

table.png

15 REPLIES 15
uday_guntupalli
Level VIII

Re: Create a formula for temporary variable

@mhalwi
      I am not sure if I understand what you are trying to do. However, I will try and explain based on what I have understood . 

      Shown below is my interpretation of what you are trying to do. Essentially plot a distribution of your data to be able to see the minimum of your type. I presume the graph shhown below achieves that.  

      If this is not what you are after, would you be kind enough to provide some screenshots of what you are trying to do - done in Excel - so the community can help you towards what you are trying to achieve ? 
image.png

Best
Uday
julian
Community Manager Community Manager

Re: Create a formula for temporary variable

Hi @mhalwi,

I'm not sure what you're asking exactly, but I have two guesses, so hopefully one is right!

 

First guess: are you trying to construct a formula that will return a column with the type text, then an equals sign, then the value in the min column? The following formula in a formula column will accomplish that:

Concat(:Type," = ",Char(:Min))

and return a table like this:exampleTable.png

I've attached the example table in case it helps. 

 

Second guess: You want to set new variables, named for the cells in the type column, to the values in the min column. Or said differently, you want to evaluate the text in Column 4 of the table above. If that's what you're after (and you've made this table) you could run the following jsl:

For Each Row(Eval(Parse(:Column 4)));

But, making that column just to evaluate it probably isn't the most parsimonious approach. If this is what you're trying to do, the following will set those variables without making that formula column: 

For Each Row(Eval(Parse(Concat(:Type," = ",Char(:Min)))))

 

I hope one of these two answers helps!

 

@julian 

 

 

mhalwi
Level III

Re: Create a formula for temporary variable

Hi All, 

 

Hi @uday_guntupalli and @julian,

 

here i attached the sample table and the jmp script so that you guys can try out and get the idea of what im trying to achieve here. Just change the path to the table of data in your computer. 

 

As you can see in the script, there is a formula (USL and LSL) in the summary for the data table. 

 

So, what i need to do right now is to create another formula that can take the value of USL for plastic and so on and asiggned it to become something like Plastic_USL = 0.4. Then i can use the variable (Plastic_USL) to plot in the plastic distribution graph using sendToReport function. so, same goes to the other list of item in the TYPE column.

 

i cannot use directly the USL variable because if i use that it will only take the last USL value calculated which is ROCK and plot it in all graph (Plastic, Cotton, Paper, Rock). Then the line for USL will be correct for only 1 graph and wrong for the rest of it. 

 

I have been searching for a way to do this but can not get anywhere and really need help from you guys here. You guys help is really appreciated here!

dt = Open ("C:\*\data_table.csv"); 

Distribution(
	Stack( 1 ),
	Continuous Distribution(
		Column( :NUMERIC_RESULT ),
		Horizontal Layout( 1 ),
		Vertical( 0 ),
		Count Axis( 1 ),
		Normal Quantile Plot( 1 )
	),
   By( :TYPE );
);


Summary( 
   Group(:TYPE ),
	Mean( :NUMERIC_RESULT ),
	Std Dev( :NUMERIC_RESULT )
);
New Column( "lower_limit",
		Numeric,
		Continuous,
		Format( "Best", 8 ),
		Formula(
			LSL = :Name( "Mean(NUMERIC_RESULT)" ) - 6 *:Name( "Std Dev(NUMERIC_RESULT)" ) 
		),
);
New Column( "upper_limit",
		Numeric,
		Continuous,
		Format( "Best", 8 ),
		Formula(
			USL = :Name( "Mean(NUMERIC_RESULT)" ) + 6 *:Name( "Std Dev(NUMERIC_RESULT)" ) 
		),
);

wait (1);

dr = Fit Group (
Distribution(
Stack( 1 ),
Continuous Distribution(
	Column( :NUMERIC_RESULT ),
	Horizontal Layout( 1 ),
	Vertical( 0 ),
	Count Axis( 1 ),
	Normal Quantile Plot( 1 )
),
   By( :TYPE )
   );
	SendToReport(Dispatch({"Distributions TYPE=Cotton","NUMERIC_RESULT"},"1",ScaleBox,
			{Min( LSL - 1 ), Max( USL + 1 ), Inc( 0.005 ), Minor Ticks( 1 ),
			Add Ref Line( LSL, Solid, "Medium Dark Red", "", 2 ),
			Add Ref Line( USL, Solid, "Medium Dark Red", "", 2 )}
		)
	);
	SendToReport(
		Dispatch(
			{
			"Distributions TYPE=Paper",
			"NUMERIC_RESULT"},
			"1",
			ScaleBox,
			{Min(-0.6 ), Max( 1.2 ), Inc( 0.001 ), Minor Ticks( 0 ),
			Add Ref Line( USL, Solid, "Medium Dark Red", "", 2 ),
			Add Ref Line( LSL, Solid, "Medium Dark Red", "", 2 )}
		)
	);
	SendToReport(
		Dispatch(
			{
			"Distributions TYPE=Plastic",
			"NUMERIC_RESULT"},
			"1",
			ScaleBox,
			{Min( 0.1 ), Max( 0.4 ), Inc( 0.005 ), Minor Ticks( 0 ),
			Add Ref Line( USL, Solid, "Medium Dark Red", "", 2 ),
			Add Ref Line( LSL, Solid, "Medium Dark Red", "", 2 )}
		)
	);
	SendToReport(
		Dispatch(
			{
			"Distributions TYPE=Rock",
			"NUMERIC_RESULT"},
			"1",
			ScaleBox,
			{Min( 0.01 ), Max( 3.5 ), Inc( 0.01 ), Minor Ticks( 0 ),
			Add Ref Line( USL, Solid, "Medium Dark Red", "", 2 ),
			Add Ref Line( LSL, Solid, "Medium Dark Red", "", 2 )}
		)
	);

)<<report;

 

 

 

julian
Community Manager Community Manager

Re: Create a formula for temporary variable

Hi @mhalwi,

I see exactly what you're trying to do now. If you insert the following jsl after you build your summary table you will have variables for the LSL and USL named for each level of Type (full script attached here, LSL USL - Original method.jsl):

For Each Row(Eval(Parse(Concat("LSL_",:Type," = ",Char(lower_limit)))));
For Each Row(Eval(Parse(Concat("USL_",:Type," = ",Char(upper_limit)))));

Now, when you call Distribution for each of the Types and build your reference lines, append the Type name to LSL and USL. For example, in Dispatch for "Paper": 

		Dispatch(
			{
			"Distributions TYPE=Paper",
			"NUMERIC_RESULT"},
			"1",
			ScaleBox,
			{Min(-0.6 ), Max( 1.2 ), Inc( 0.001 ), Minor Ticks( 0 ),
			Add Ref Line( USL_Paper, Solid, "Medium Dark Red", "", 2 ),
			Add Ref Line( LSL_Paper, Solid, "Medium Dark Red", "", 2 )}
		)

This got me thinking, though. Would you be open to a slightly different way of accomplishing this? Another way you could do this is if you split your original table we can set the LSL and USL as column properties via jsl. Then, when you call Distribution() the limits can be plotted automatically. JSL for that is also attached (LSL USL - Alt method.jsl).LSL and USL.png

 

 

Does that help?

@julian

 

mhalwi
Level III

Re: Create a formula for temporary variable

Hi @julian

 

both of the solutions work great!! thanks to you!

 

1 question as for the alt method  i need to manually plot the graph after the table has been split. Is there any method to plot the distribution graph for all column as the TYPE column value will always change?

 

thanks again for your help!!

txnelson
Super User

Re: Create a formula for temporary variable

Here is a different approach to the output you are attempting to generate......it takes advantage of JMP having the ability to have Spec Limits as column properties, and for the Distribution Platform to recognize them, and to use them within the platform

Names Default To Here( 1 );
dt = Current Data Table();

// Only one set of Spec Limits per column can be set, 
// therefore split the data into separate columns
// and set the separate limits for each column
dtSplit = dt << Split( Split By( :TYPE ), Split( :NUMERIC_RESULT ), Sort by Column Property );

// Get the names of the generated columns
colList = dtSplit << get column names( string );

// Loop across the columns and create the spec limits for each column
For( i = 1, i <= N Items( colList ), i++,
	Eval(
		Substitute(
				Expr(
					__col__ << set property(
						"spec limits ",
						{LSL( __LSL__ ), USL( __USL__ ), show limits( 1 )}
					)
				),
			Expr( __col__ ), Parse( "dtSplit:" || colList[i] ),
			Expr( __LSL__ ),
				Eval(
					Parse(
						"col mean(dtSplit:" || colList[i] || ")-6*col std dev(dtSplit:" || colList[i
						] || ")"
					)
				),
			Expr( __USL__ ),
				Eval(
					Parse(
						"col mean(dtSplit:" || colList[i] || ")+6*col std dev(dtSplit:" || colList[i
						] || ")"
					)
				)
		)
	)
);

// Create a literal string that contains the JSL required to 
// generate the Distributions
theExpr = "Distribution(
	Arrange in Rows( 1 ),";
theExpr = theExpr || Char(
	Substitute(
			Expr(
				Continuous Distribution(
					Column( __col__ ),
					Horizontal Layout( 1 ),
					Vertical( 0 ),
					Normal Quantile Plot( 1 )
				)
			),
		Expr( __col__ ), Parse( "dtSplit:" || colList[1] )
	)
);
For( i = 2, i <= N Items( colList ), i++,
	theExpr = theExpr || "," || Char(
		Substitute(
				Expr(
					Continuous Distribution(
						Column( __col__ ),
						Horizontal Layout( 1 ),
						Vertical( 0 ),
						Normal Quantile Plot( 1 )
					)
				),
			Expr( __col__ ), Parse( "dtSplit:" || colList[i] )
		)
	);
	
);
theExpr = theExpr || ";";

// Run the generated code
Eval( Parse( theExpr ) );
Jim
mhalwi
Level III

Re: Create a formula for temporary variable

Hi Jim,
thanks a lot! your method also works great. Any chance to make the plotting for the distribution graph automatically using JSL rather than manually choose to plot the graph?
txnelson
Super User

Re: Create a formula for temporary variable

@mhalwi

Would you please explain what you mean by "plotting for the distribution graph automatically"?  Do you want JMP to run the plot when you open up a new data table?  Or, do you want JMP to recognize when new data are available on some system?   

Jim
mhalwi
Level III

Re: Create a formula for temporary variable

Hi Jim,

what i mean is after it has calculated all limits then it will directly plot the distribution graph for all TYPE value along with the limit calculated. So, im thinking to get this done by using the script but when i try to export out the script after i plotted all the TYPE distribution graph seems like all type graph is hardcoded to the current table only.

Means if i have new item for TYPE column then it will not plot the distribution graph. It will only plot those 4 item in the type column only.

Hope this answer your question. just let me know if you need more clarification about this. thanks!