cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
SDF1
Super User

JSL help proper referencing of a column

Hi All,

 

  Having trouble with the proper referencing of a column when passing the command <<Simulate to a report window using JSL.

 

  The section of code I'm having a hard time with is the following:

report_of_interest[Number Col Box( 8 )] << Simulate(
	NBSnum,
	Random Seed( RSnum ),
	Out( Eval( YCols ) ),
	In( :Simulated Y )
);

  Running that section of code gives the following error: Column to switch out not found. and then pops up the window where you're supposed to select the columns to switch in and out.

 

  The report_of_interest is the report window where I'm sending the Simulate command. Specifically to the NumberColBox(8), which is the Estimate column in the report. NBSnum and RSnum are the number of bootstrap samples to run and a random seed variable. The problem is the name of the column in the Out( ) of the Simulate( ) command. The In( ) column is no problem because I can name the simulated data column whatever I want, but the column for the Out( ) option is not a column I really want to rename or anything. In this case, I save the simulated data to the data table and rename the column to "Simulated Y" so I can reference it as is needed in the Simulate command as In(:Simulated Y).

 

  Earlier in the code, the user is prompted to select the column that will be the response column for modeling, this is YCols, and often, when dealing with a column in a platform, you can just have it as Eval(YCols), and it accepts it just fine, for example:

fm = avdt << Fit Model(
	Y( Eval( YCols ) ),
	Validation( :Validation ),
	Effects( :Null Factor, Eval( XCols ) ),
	Personality( "Generalized Regression" ),
	Run( Fit( Estimation Method( Forward Selection ), Validation Method( Validation Column ) ) )
);

  Will run a fit model on the Y( ) column correctly. However, the Simulate( ) command wants to have the column referenced as a scoped column, I believe, as it wants it to be, :My Column To Model, for example.

 

  Let's say that the column has the name "My Column To Model", so the variable YCols and Eval(YCols) will both return the following {"My Column To Model"}. When sending the simulate command to the report, it wants the scoped column name, like the following:

report_of_interest[Number Col Box( 8 )] << Simulate(
	NBSnum,
	Random Seed( RSnum ),
	Out( :My Column To Model ),
	In( :Simulated Y )
);

  The problem is, the column I'm modeling can change, therefore it's name changes, and I don't want to rename the column to always be a fixed name like :YData. I want to work with a variable like YCols, but I don't know how to work with the infix colon operator (:) and a variable like YCols to have the correct column reference for the Simulate( ) command.

 

  I've tried As Column(dt, name), Column(dt, name), Column(number), Parse(":"||char(Column(avdt, Eval(YCols)))),  Parse(":"||Eval(YCols)[1]), and none of those work. They all result in the same error mentioned above and open up a new window to select the columns to swap In/Out, which negates the automation I'm trying to do.

 

Any help is much appreciated.

 

Thanks!,
DS

3 ACCEPTED SOLUTIONS

Accepted Solutions
SDF1
Super User

Re: JSL help proper referencing of a column

I found one possible solution, but it's certainly not efficient and it's rather cumbersome. I would imagine there are better solutions, and I'm hoping someone can help me out on it.

 

I found that if you build the string of sending the command in JSL and use Eval(Parse()) to actually do it, then it works. Again, it's cumbersome and is not efficient, but it does work.

str = Eval Insert(
	"report_of_interest[Number Col Box( 8 )] << Simulate(
		NBSnum,
		Random Seed( RSnum ),
		Out("
);
str2 = Eval Insert( "	),
	In( :Simulated Y )
	)" );
Eval( Parse( str || ":" || Char( Eval( YCols )[1] ) || str2 ) );

Strange solution, and I'm hoping someone has a better one they can share.

 

Thanks!,

DS

View solution in original post

mmarchandTSI
Level V

Re: JSL help proper referencing of a column

I have issues with things like this, as well.  It might not be the best solution, but the following code should do what you want it to do.  *edit*  I see you found a similar method already. 

 

Eval(
	Parse(
		"\[report_of_interest[Number Col Box( 8 )] << Simulate(
	NBSnum,
	Random Seed( RSnum ),
	Out( ]\"
		 || YCols[1] || "\[ ),
	In( :Simulated Y )
);]\"
	)
);

 

View solution in original post

jthi
Super User

Re: JSL help proper referencing of a column

If I have to build a list of column references and Eval won't work, I usually build the expressions and then use Eval(Substitute())

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

cols = {"height", "weight"};

obj = Fit Model(
	Y(:weight),
	Effects(:age, :sex, :height),
	Personality("Generalized Regression"),
	Generalized Distribution("Normal"),
	Run(
		Fit(
			Estimation Method(Lasso(Adaptive)),
			Validation Method(AICc)
		)
	)
);
obj << (fit[1] << Save Simulation Formula);
rpt = Report(obj);

out_expr = Expr(Out());
For Each({colname}, cols,
	Insert Into(out_expr, Name Expr(AsColumn(dt, colname)));
);
show(out_expr);

Eval(Substitute(
	Expr(dtlst = rpt["Parameter Estimates for Original Predictors"][Number Col Box("Prob > ChiSquare")] <<Simulate(
	10, _out_ , In(:weight Simulation Formula))),
	Expr(_out_), Name Expr(out_expr)
));
-Jarmo

View solution in original post

4 REPLIES 4
SDF1
Super User

Re: JSL help proper referencing of a column

I found one possible solution, but it's certainly not efficient and it's rather cumbersome. I would imagine there are better solutions, and I'm hoping someone can help me out on it.

 

I found that if you build the string of sending the command in JSL and use Eval(Parse()) to actually do it, then it works. Again, it's cumbersome and is not efficient, but it does work.

str = Eval Insert(
	"report_of_interest[Number Col Box( 8 )] << Simulate(
		NBSnum,
		Random Seed( RSnum ),
		Out("
);
str2 = Eval Insert( "	),
	In( :Simulated Y )
	)" );
Eval( Parse( str || ":" || Char( Eval( YCols )[1] ) || str2 ) );

Strange solution, and I'm hoping someone has a better one they can share.

 

Thanks!,

DS

jthi
Super User

Re: JSL help proper referencing of a column

If I have to build a list of column references and Eval won't work, I usually build the expressions and then use Eval(Substitute())

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

cols = {"height", "weight"};

obj = Fit Model(
	Y(:weight),
	Effects(:age, :sex, :height),
	Personality("Generalized Regression"),
	Generalized Distribution("Normal"),
	Run(
		Fit(
			Estimation Method(Lasso(Adaptive)),
			Validation Method(AICc)
		)
	)
);
obj << (fit[1] << Save Simulation Formula);
rpt = Report(obj);

out_expr = Expr(Out());
For Each({colname}, cols,
	Insert Into(out_expr, Name Expr(AsColumn(dt, colname)));
);
show(out_expr);

Eval(Substitute(
	Expr(dtlst = rpt["Parameter Estimates for Original Predictors"][Number Col Box("Prob > ChiSquare")] <<Simulate(
	10, _out_ , In(:weight Simulation Formula))),
	Expr(_out_), Name Expr(out_expr)
));
-Jarmo
SDF1
Super User

Re: JSL help proper referencing of a column

Hi @mmarchandTSI and @jthi ,

 

  Thanks for the feedback and ideas on how to solve this issue. I shouldn't be too surprised that there are multiple different ways of solving the same problem with JMP/JSL. One of the great things about the software. Still, I find it interesting that a "simpler" solution isn't possible. I appreciate the help!

 

Thanks,

DS

mmarchandTSI
Level V

Re: JSL help proper referencing of a column

I have issues with things like this, as well.  It might not be the best solution, but the following code should do what you want it to do.  *edit*  I see you found a similar method already. 

 

Eval(
	Parse(
		"\[report_of_interest[Number Col Box( 8 )] << Simulate(
	NBSnum,
	Random Seed( RSnum ),
	Out( ]\"
		 || YCols[1] || "\[ ),
	In( :Simulated Y )
);]\"
	)
);