<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to group by and get slopes in a JSL fit model script in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251440#M49362</link>
    <description>&lt;P&gt;1. The analysis can not be directly done from the stacked data table.&amp;nbsp; In order to perform the bivariates, the Fish Caught needs to be in a separate column, and paired with each of the X Factors.&amp;nbsp; However, I think what you may want is just the output format,&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="fish.PNG" style="width: 729px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/22263i9FF8E00FCE7FB400/image-size/large?v=v2&amp;amp;px=999" role="button" title="fish.PNG" alt="fish.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;and this script produces it from the original data table&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;NamesDefaultToHere(1);

dt = Open("$SAMPLE_DATA/Fishing.jmp");

biv = Bivariate(invisible,
	Y( :Fish Caught ),
	X( :Live Bait,
		:Fishing Poles,
		:Camper,
		:People,
		:Children,
		:Fished),
	Fit Line( {Line Color( "Medium Dark Red" )} ),
	By( :Validation )
);

// Create the data table of RSqares
dtR2 = report(biv[1])["Summary of Fit"][tablebox(1)]&amp;lt;&amp;lt; make combined data table;
dtSlope = report(biv[1])["Parameter Estimates"][tablebox(1)]&amp;lt;&amp;lt; make combined data table(invisible);
dtR2 &amp;lt;&amp;lt; select where(:Column 1 != "RSquare");
dtR2 &amp;lt;&amp;lt; delete rows;
dtR2:Column 2 &amp;lt;&amp;lt; set name("RSquare");
dtR2 &amp;lt;&amp;lt; delete Columns({"Validation 2","Column 1"});

// Create the data table of Slopes
dtSlope &amp;lt;&amp;lt; select where(:Term == "Intercept");
dtSlope &amp;lt;&amp;lt; delete rows;
dtSlope:Estimate &amp;lt;&amp;lt; set name( "Slope");
dtSlope &amp;lt;&amp;lt; delete columns({"Validation 2","Term","~Bias","Std Error","t Ratio","Prob&amp;gt;|t|"});

// Put the data together
dtR2 &amp;lt;&amp;lt; 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") &amp;lt;&amp;lt; close window;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 09 Mar 2020 21:13:56 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2020-03-09T21:13:56Z</dc:date>
    <item>
      <title>How to group by and get slopes in a JSL fit model script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251300#M49337</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'm trying to fit data in group and get slope and R squared number. I'm using Fishing data set as an example here.&lt;BR /&gt;&lt;BR /&gt;I stacked the data so that the summary will be outputted easily as one single column then I need to spread the columns again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I did&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;fishing_stacked = dt &amp;lt;&amp;lt; Stack(
	columns(
		:Fish Caught,
		:Live Bait,
		:Fishing Poles,
		:Camper,
		:People,
		:Children,
		:Fished
	),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" )
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="joshua_0-1583767793311.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/22246iF04C9CCAB7098E64/image-size/medium?v=v2&amp;amp;px=400" role="button" title="joshua_0-1583767793311.png" alt="joshua_0-1583767793311.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to group the data by&amp;nbsp;&lt;CODE class=" language-jsl"&gt;Validation&lt;/CODE&gt; column and fit (Y axis =&lt;U&gt; Fish cought&lt;/U&gt;&amp;nbsp;)and X axis are "&lt;U&gt;Live Bait&lt;/U&gt;, &lt;U&gt;Fishing Poles&lt;/U&gt;, Camper ...." and get the slope value and R squared number as new columns.&lt;BR /&gt;&lt;BR /&gt;Here is the previous post but I don't know how to apply it to my data set.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.jmp.com/t5/Discussions/Save-Parameter-Estimates-of-Linear-Regression-with-by-Variable/td-p/13123" target="_blank" rel="noopener"&gt;https://community.jmp.com/t5/Discussions/Save-Parameter-Estimates-of-Linear-Regression-with-by-Variable/td-p/13123&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Mar 2020 16:32:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251300#M49337</guid>
      <dc:creator>joshua</dc:creator>
      <dc:date>2020-03-09T16:32:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by and get slopes in a JSL fit model script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251317#M49339</link>
      <description>any solution to this ?</description>
      <pubDate>Mon, 09 Mar 2020 16:15:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251317#M49339</guid>
      <dc:creator>joshua</dc:creator>
      <dc:date>2020-03-09T16:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by and get slopes in a JSL fit model script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251334#M49341</link>
      <description>is it so difficult to do this ?</description>
      <pubDate>Mon, 09 Mar 2020 16:38:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251334#M49341</guid>
      <dc:creator>joshua</dc:creator>
      <dc:date>2020-03-09T16:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by and get slopes in a JSL fit model script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251345#M49344</link>
      <description>&lt;P&gt;I am not sure that stacking will help, given the analysis you intend. I would try selecting Analyze &amp;gt; Fit Y by X. Select Fish Caught and click Y. Select the other columns and click X. Select Validation and click By, then click OK. Hold the Control key (Windows) or Command key (Macintosh), click the red triangle next to Bivariate and select Fit Line.&amp;nbsp;Right-click the table in Summary of Fit and select Make Into Combined Table. Right-click the table in Parameter Estimates and select Make Into Combined Table.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Mar 2020 17:04:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251345#M49344</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2020-03-09T17:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by and get slopes in a JSL fit model script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251346#M49345</link>
      <description>Can we do this as JSL script ?</description>
      <pubDate>Mon, 09 Mar 2020 16:47:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251346#M49345</guid>
      <dc:creator>joshua</dc:creator>
      <dc:date>2020-03-09T16:47:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by and get slopes in a JSL fit model script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251367#M49348</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;NamesDefaultToHere(1);

dt = Open("$SAMPLE_DATA/Fishing.jmp");
xList = {:Fishing Poles, :People, :Children};
biv = dt &amp;lt;&amp;lt; Bivariate(Y(:Fish Caught), X(Eval(xList)), By(:Validation), FitLine(1));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Mar 2020 17:13:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251367#M49348</guid>
      <dc:creator>ian_jmp</dc:creator>
      <dc:date>2020-03-09T17:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by and get slopes in a JSL fit model script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251436#M49359</link>
      <description>thanks but how can I get slope and R squared number extracted from Bivariate plots ? In addition, can we do this in stacked version of the Fish data as showed in table ?</description>
      <pubDate>Mon, 09 Mar 2020 19:56:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251436#M49359</guid>
      <dc:creator>joshua</dc:creator>
      <dc:date>2020-03-09T19:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by and get slopes in a JSL fit model script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251440#M49362</link>
      <description>&lt;P&gt;1. The analysis can not be directly done from the stacked data table.&amp;nbsp; In order to perform the bivariates, the Fish Caught needs to be in a separate column, and paired with each of the X Factors.&amp;nbsp; However, I think what you may want is just the output format,&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="fish.PNG" style="width: 729px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/22263i9FF8E00FCE7FB400/image-size/large?v=v2&amp;amp;px=999" role="button" title="fish.PNG" alt="fish.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;and this script produces it from the original data table&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;NamesDefaultToHere(1);

dt = Open("$SAMPLE_DATA/Fishing.jmp");

biv = Bivariate(invisible,
	Y( :Fish Caught ),
	X( :Live Bait,
		:Fishing Poles,
		:Camper,
		:People,
		:Children,
		:Fished),
	Fit Line( {Line Color( "Medium Dark Red" )} ),
	By( :Validation )
);

// Create the data table of RSqares
dtR2 = report(biv[1])["Summary of Fit"][tablebox(1)]&amp;lt;&amp;lt; make combined data table;
dtSlope = report(biv[1])["Parameter Estimates"][tablebox(1)]&amp;lt;&amp;lt; make combined data table(invisible);
dtR2 &amp;lt;&amp;lt; select where(:Column 1 != "RSquare");
dtR2 &amp;lt;&amp;lt; delete rows;
dtR2:Column 2 &amp;lt;&amp;lt; set name("RSquare");
dtR2 &amp;lt;&amp;lt; delete Columns({"Validation 2","Column 1"});

// Create the data table of Slopes
dtSlope &amp;lt;&amp;lt; select where(:Term == "Intercept");
dtSlope &amp;lt;&amp;lt; delete rows;
dtSlope:Estimate &amp;lt;&amp;lt; set name( "Slope");
dtSlope &amp;lt;&amp;lt; delete columns({"Validation 2","Term","~Bias","Std Error","t Ratio","Prob&amp;gt;|t|"});

// Put the data together
dtR2 &amp;lt;&amp;lt; 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") &amp;lt;&amp;lt; close window;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Mar 2020 21:13:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251440#M49362</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-03-09T21:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by and get slopes in a JSL fit model script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251454#M49367</link>
      <description>JMP has no out of the box calculation module for slope?</description>
      <pubDate>Tue, 10 Mar 2020 06:25:10 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251454#M49367</guid>
      <dc:creator>lala</dc:creator>
      <dc:date>2020-03-10T06:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by and get slopes in a JSL fit model script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251482#M49376</link>
      <description>&lt;P&gt;Sure, it does! You can use either the Bivariate platform or the Fit Least Squares platform to estimate the slope in the simple linear regression model. There is also a Linear Regression() function if you need such estimates in a formula or a script.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 12:39:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251482#M49376</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2020-03-10T12:39:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by and get slopes in a JSL fit model script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251631#M49403</link>
      <description />
      <pubDate>Tue, 10 Mar 2020 17:43:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251631#M49403</guid>
      <dc:creator>joshua</dc:creator>
      <dc:date>2020-03-10T17:43:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by and get slopes in a JSL fit model script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251632#M49404</link>
      <description>&lt;P&gt;&lt;SPAN&gt;If I want to loop over the columns ( I have many columns in real data) and not to include the those contains certain string how to loop through them ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;NamesDefaultToHere(1);

dt = Open("$SAMPLE_DATA/Fishing.jmp");


colList = dt &amp;lt;&amp;lt; get column names( string );

For( i = 1, i &amp;lt;= N Items( colList ), i++,
If( ! Contains( colList[i], "Validation") &amp;amp; ! Contains( colList[i], "People") ,

biv = Bivariate(invisible,
Y( :Fish Caught ),
X( :i),
Fit Line( {Line Color( "Medium Dark Red" )} ),
By( :Validation )
);

// Create the data table of RSqares
dtR2 = report(biv[1])["Summary of Fit"][tablebox(1)]&amp;lt;&amp;lt; make combined data table;
dtSlope = report(biv[1])["Parameter Estimates"][tablebox(1)]&amp;lt;&amp;lt; make combined data table (invisible);
dtR2 &amp;lt;&amp;lt; select where(:Column 1 != "RSquare");
dtR2 &amp;lt;&amp;lt; delete rows;
dtR2:Column 2 &amp;lt;&amp;lt; set name("RSquare");
dtR2 &amp;lt;&amp;lt; delete Columns({"Validation 2","Column 1"});&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Mar 2020 17:40:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251632#M49404</guid>
      <dc:creator>joshua</dc:creator>
      <dc:date>2020-03-10T17:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by and get slopes in a JSL fit model script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251657#M49411</link>
      <description>&lt;P&gt;I would approach this differently.&amp;nbsp; By placing all of the output into a single window, the&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;lt;&amp;lt; Make Combined Data Table&amp;nbsp;&lt;/P&gt;
&lt;P&gt;will work as desired.&amp;nbsp; Working across separate windows will be an issue.&lt;/P&gt;
&lt;P&gt;I choose to modify the list of x columns one wants to use, and then apply it to only one Bivariate execution&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA/Fishing.jmp" );


colList = dt &amp;lt;&amp;lt; get column names( string );

For( i = N Items( colList ), I &amp;gt;= 1, i--,
	If( Contains( colList[i], "Validation" ) | Contains( colList[i], "People" ),
		Remove From( colList, i, 1 )
	)
);

biv = Bivariate(invisible,
Y( :Fish Caught ),
X( eval(colList) ),
Fit Line( {Line Color( "Medium Dark Red" )} ),
By( :Validation )
);

// Create the data table of RSqares
dtR2 = report(biv[1])["Summary of Fit"][tablebox(1)]&amp;lt;&amp;lt; make combined data table;
dtSlope = report(biv[1])["Parameter Estimates"][tablebox(1)]&amp;lt;&amp;lt; make combined data table (invisible);
dtR2 &amp;lt;&amp;lt; select where(:Column 1 != "RSquare");
dtR2 &amp;lt;&amp;lt; delete rows;
dtR2:Column 2 &amp;lt;&amp;lt; set name("RSquare");
dtR2 &amp;lt;&amp;lt; delete Columns({"Validation 2","Column 1"});&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There is also a Platform that you may want to explore, that directly produces the report you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA/Fishing.jmp" );


colList = dt &amp;lt;&amp;lt; get column names( string );

For( i = N Items( colList ), I &amp;gt;= 1, i--,
	If( Contains( colList[i], "Validation" ) | Contains( colList[i], "People" ) |
		Contains( colList[i], "Fish Caught" ),
		Remove From( colList, i, 1 )
	)
);

Response Screening(
	Y( :Fish Caught ),
	X( eval(colList) ),
	Where( Format( :Validation ) == "Training" )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 20:48:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251657#M49411</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-03-10T20:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by and get slopes in a JSL fit model script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251661#M49413</link>
      <description>thanks Jim, you are a great help !</description>
      <pubDate>Tue, 10 Mar 2020 20:52:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-group-by-and-get-slopes-in-a-JSL-fit-model-script/m-p/251661#M49413</guid>
      <dc:creator>joshua</dc:creator>
      <dc:date>2020-03-10T20:52:22Z</dc:date>
    </item>
  </channel>
</rss>

