cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
joshua
Level III

loop through column names and do bivariate fitting with certain ones and output slope and R squared value

Relevant post is here,
https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-...
I have many columns and do not want to include some of them to the analysis. So I need to loop through the column names and pick the ones I need and do bivariate fitting.

 

So by following the solution on above post

 

I did

 

NamesDefaultToHere(1);

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


colList = dt << get column names( string );

For( i = 1, i <= N Items( colList ), i++,
	If( ! Contains( colList[i], "Validation") & ! Contains( colList[i], "People") ,
	
	biv = Bivariate(invisible,
	Y( :Fish Caught ),
	X( :i),
	Fit Line( {Line Color( "Medium Dark Red" )} ),
	By( :Validation )
))
	
	dtR2 = report(biv[1])["Summary of Fit"][tablebox(1)]<< make combined data table;

dtR2 = report(biv[1])["Summary of Fit"][tablebox(1)]<< make combined data table;
dtSlope = report(biv[1])["Parameter Estimates"][tablebox(1)]<< make combined data table (invisible);
dtR2 << select where(:Column 1 != "RSquare");
dtR2 << delete rows;
dtR2:Column 2 << set name("RSquare");
dtR2 << delete Columns({"Validation 2","Column 1"});	

dtSlope << select where(:Term == "Intercept");
dtSlope << delete rows;
dtSlope:Estimate << set name( "Slope");
dtSlope << delete columns({"Validation 2","Term","~Bias","Std Error","t Ratio","Prob>|t|"});

// Put the data together
dtR2 << Update(
	With( dtSlope ),
	Match Columns( :Validation = :Validation, :X = :X, :Y = :Y )
);

// Clean up the items not needed
close(dtSlope, nosave);
window("Fishing - Bivariate of Fish Caught") << close window;
);

but it seems that I'm not sure how to implement this correctly.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: loop through column names and do bivariate fitting with certain ones and output slope and R squared value

Names Default To Here( 1 );

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

col = dt << Get Column Names( Numeric, String );

For( c = N Items( col ), c > 0 , c--,
	If( col[c] == "Fish Caught", Remove From( col, c ) );
	If( col[c] == "Validation", Remove From( col, c ) );
	If( col[c] == "People", Remove From( col, c ) );
);

biv = dt << Bivariate(
	Y( :Fish Caught ),
	X( Eval( col ) ),
	By( :Validation ),
	Fit Line
);

biv rep = biv << Report;

summary dt = biv rep[1]["Summary of Fit"][TableBox(1)] << Make Combined Data Table;
parameter dt = biv rep[1]["Parameter Estimates"][TableBox(1)] << Make Combined Data Table;

Wait( 0 );

biv << Close Window;

Column( summary dt, 6 ) << Set Name( "RSquare" );
summary dt
	<< Select Where( Contains( :Column 1[], "RSquare" ) & Not( Contains( :Column 1[], "Adj" ) ) )
	<< Invert Row Selection
	<< Delete Rows
	<< Delete Columns( { "Y", "Validation 2", "Column 1" } );

Column( parameter dt, 7 ) << Set Name( "Slope" );
parameter dt
	<< Select Where( Contains( :Term[], "Intercept" ) )
	<< Delete Rows
	<< Delete Columns( { "Y", "Validation 2", "Term", "~Bias", "Std Error", "t Ratio", "Prob>|t|" } );

summary dt << Join(
	With(parameter dt ),
	Select( :Validation, :X, :RSquare ),
	SelectWith( :Slope ),
	By Row Number
);

Close( summary dt, No Save );
Close( parameter dt, No Save );

View solution in original post

4 REPLIES 4
joshua
Level III

Re: loop through column names and do bivariate fitting with certain ones and output slope and R squared value

Can somebody from Jmp staff help me with this problem ?

Re: loop through column names and do bivariate fitting with certain ones and output slope and R squared value

Names Default To Here( 1 );

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

col = dt << Get Column Names( Numeric, String );

For( c = N Items( col ), c > 0 , c--,
	If( col[c] == "Fish Caught", Remove From( col, c ) );
	If( col[c] == "Validation", Remove From( col, c ) );
	If( col[c] == "People", Remove From( col, c ) );
);

biv = dt << Bivariate(
	Y( :Fish Caught ),
	X( Eval( col ) ),
	By( :Validation ),
	Fit Line
);

biv rep = biv << Report;

summary dt = biv rep[1]["Summary of Fit"][TableBox(1)] << Make Combined Data Table;
parameter dt = biv rep[1]["Parameter Estimates"][TableBox(1)] << Make Combined Data Table;

Wait( 0 );

biv << Close Window;

Column( summary dt, 6 ) << Set Name( "RSquare" );
summary dt
	<< Select Where( Contains( :Column 1[], "RSquare" ) & Not( Contains( :Column 1[], "Adj" ) ) )
	<< Invert Row Selection
	<< Delete Rows
	<< Delete Columns( { "Y", "Validation 2", "Column 1" } );

Column( parameter dt, 7 ) << Set Name( "Slope" );
parameter dt
	<< Select Where( Contains( :Term[], "Intercept" ) )
	<< Delete Rows
	<< Delete Columns( { "Y", "Validation 2", "Term", "~Bias", "Std Error", "t Ratio", "Prob>|t|" } );

summary dt << Join(
	With(parameter dt ),
	Select( :Validation, :X, :RSquare ),
	SelectWith( :Slope ),
	By Row Number
);

Close( summary dt, No Save );
Close( parameter dt, No Save );

Re: loop through column names and do bivariate fitting with certain ones and output slope and R squared value

Did this solution help you?

joshua
Level III

Re: loop through column names and do bivariate fitting with certain ones and output slope and R squared value

yes mark, Sorry for delay:)