cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Discussions

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

Calculation Result Discrepancy, Col Mean, etc.

Why do calculation results differ when using variables compared to using direct strings? I suspect that when variables are used, the grouping function for the variable part might not be working. How can this be resolved?

with the following formula

Col Mean(
	:data,
	:A,
	:B,
	:C_D == "ccccccc"
)

This is the formula.

Col Mean(
	:data,
	:A,
	:B,
	Column(Eval Insert("C_^get_input_1^" == get_input_2))
)
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Calculation Result Discrepancy, Col Mean, etc.

Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute 

Most likely something like this, but I cannot test it as I don't have data or the earlier part of the script

Names Default To Here(1);


dt = Data Table("data_table");

Eval(Substitute(
	Expr(Data Table("data_table") << New Column(colname,
		Numeric,
		"Continuous",
		Formula(Col Mean(:data, :A, :B, _input1_ == _input2_)),
	)),
	Expr(colname), Substitute(Xbar_^get_input_process^_^get_input_line^),
	Expr(_input1_) = NameExpr(AsColumn(dt, Eval Insert("new_^get_input_1^"))),
	Expr(_input2_) = get_input_2
));
-Jarmo

View solution in original post

8 REPLIES 8
TamedZebra
Level III

Re: Calculation Result Discrepancy, Col Mean, etc.

Sorry, everyone. I forgot to mention that get_input_1 and get_input_2 can be assumed to be already obtained as strings, respectively.

jthi
Super User

Re: Calculation Result Discrepancy, Col Mean, etc.

First one is comparing column vs string and second one we cannot be sure what is being compared (string to string which would always be 1 or 0?). At least it isn't evaluated and you will need to evaluate the values into the formula

Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute 

-Jarmo
TamedZebra
Level III

Re: Calculation Result Discrepancy, Col Mean, etc.

I want to achieve the same result as the expression in the first line. When the variables were given as get_input_1="D" and get_input_2="cccccc" respectively, I naturally expected the same result, but the reality was different...

jthi
Super User

Re: Calculation Result Discrepancy, Col Mean, etc.

Eval(Substitute(
	Expr(Col Mean(
		:data,
		:A,
		:B,
		_input1_ == _input2_
	),
	Expr(_input1_) = NameExpr(AsColumn(dt, get_input_1)),
	Expr(_input2_) = get_input_2
	)
));

but you need to add new column and formula to that example

-Jarmo
TamedZebra
Level III

Re: Calculation Result Discrepancy, Col Mean, etc.

Thank you for your replies. Also, I apologize for my late responses.

I wrote the JSL as shown below, but an error is being output. What could be the cause?

The error message says "insufficient arguments" at the location "Substitute/###/(Expr(".

	Data Table( "data_table" ) << New Column( Eval Insert("Xbar_^get_input_process^_^get_input_line^"),
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Formula(
			Eval(Substitute(
				Expr(Col Mean(
					:data,
					:A,
					:B,
					_input1_ == _input2_
					),
					Expr(_input1_) = NameExpr(AsColumn(dt, Eval Insert("new_^get_input_1^"))),
					Expr(_input2_) = get_input_2
					)
					));
	)) << Run Formulas;
jthi
Super User

Re: Calculation Result Discrepancy, Col Mean, etc.

Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute 

Most likely something like this, but I cannot test it as I don't have data or the earlier part of the script

Names Default To Here(1);


dt = Data Table("data_table");

Eval(Substitute(
	Expr(Data Table("data_table") << New Column(colname,
		Numeric,
		"Continuous",
		Formula(Col Mean(:data, :A, :B, _input1_ == _input2_)),
	)),
	Expr(colname), Substitute(Xbar_^get_input_process^_^get_input_line^),
	Expr(_input1_) = NameExpr(AsColumn(dt, Eval Insert("new_^get_input_1^"))),
	Expr(_input2_) = get_input_2
));
-Jarmo
TamedZebra
Level III

Re: Calculation Result Discrepancy, Col Mean, etc.

 Thank you for your consideration, even though it was difficult to experiment without being able to provide actual data. 

 

I modified it as follows to fit my data table.

Names Default To Here(1);


dt = Data Table("data_table");

Eval(Substitute(
	Expr(Data Table("data_table") << New Column(colname,
		Numeric,
		"Continuous",
		Formula(Col Mean(:data, :A, :B, _input1_ == _input2_)),
	)),
	Expr(colname), Eval Insert(Xbar_^get_input_process^_^get_input_line^),
	Expr(_input1_) , NameExpr(AsColumn(dt, Eval Insert("new_^get_input_1^"))),
	Expr(_input2_) , get_input_2
));
 
 
mmarchandFSLR
Level VI

Re: Calculation Result Discrepancy, Col Mean, etc.

Column(Eval Insert("C_^get_input_1^" == get_input_2)) evaluates to Column( "C_D" == "ccccccc" ), so your formula would be

edit

Including non-string inside Eval Insert() actually causes it to evaluate to the empty string.

Col Mean(
	:data,
	:A,
	:B,
	Column( "" )
);

 

That may be why it isn't working as expected.  Jarmo's solution should be what you want.

Recommended Articles