<?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: factorial to degree script in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/factorial-to-degree-script/m-p/194192#M41511</link>
    <description>&lt;P&gt;I realized that my expectations were not right.&amp;nbsp; This actually does the same thing as what fit model macro does.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I like the following iterative approach more though.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;factorial_to_degree = function({factors, degree}, 
	n_factors = nitems(factors);
	factors = shape(factors, n_factors);
	termlist = {};
	for(i=1, i&amp;lt;=degree, i++, 
		nckmat = nchoosekmatrix(n_factors, i);
		for(r = 1, r&amp;lt;=nrows(nckmat), r++, 
			AddTermExpr = Expr(AddTerm());
			for(c=1, c&amp;lt;=ncols(nckmat), c++, 
				insert into(AddTermExpr, Evallist({factors[nckmat[r, c]], 1}));
			);
			insert into(termlist, nameexpr(AddTermExpr));
		);
	);
	return(termlist);
);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 23 Apr 2019 17:36:21 GMT</pubDate>
    <dc:creator>vince_faller</dc:creator>
    <dc:date>2019-04-23T17:36:21Z</dc:date>
    <item>
      <title>factorial to degree script</title>
      <link>https://community.jmp.com/t5/Discussions/factorial-to-degree-script/m-p/194104#M41493</link>
      <description>&lt;P&gt;I'm having a hard time making factorial to degree inside of a script in order to assign certain DOE factors to some factorial.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can get the first level with nchoosekMatrix() but can't figure out how to dynamically get levels higher than 1.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here(1);

factorial_to_degree = function({factors, degree = 2, termlist = {}}, 
	{DEFAULT LOCAL}, 
	if(degree!=1, 
		termlist = recurse(factors, degree-1, termlist);
	);
	nckmat = nchoosekmatrix(nrows(factors), degree);
	for(r = 1, r&amp;lt;=nrows(nckmat), r++, 
		AddTermExpr = Expr(AddTerm());
		for(c=1, c&amp;lt;=ncols(nckmat), c++, 
			insert into(AddTermExpr, Evallist({factors[nckmat[r, c]], 1}));
		);
		insert into(termlist, nameexpr(AddTermExpr));
	);
	return(termlist);
);

factorial_to_degree([1, 2, 3], 2);

//returns
/*
{AddTerm( {1, 1} ), AddTerm( {2, 1} ), AddTerm( {3, 1} ), AddTerm( {1, 1}, {2, 1} ),
AddTerm( {1, 1}, {3, 1} ), AddTerm( {2, 1}, {3, 1} )}
*/

//want it to return
/*
{
	AddTerm( {1, 1} ), AddTerm( {2, 1} ), AddTerm( {3, 1} ), 
	AddTerm( {1, 2} ), AddTerm( {2, 2} ), AddTerm( {3, 2} ),
	AddTerm( {1, 1}, {2, 1} ), AddTerm( {1, 1}, {3, 1} ), AddTerm( {2, 1}, {3, 1} )
}
*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think I should be doing something recursively but I'm having a hard time actually getting anything to work.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would greatly be appreciated.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2023 20:58:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/factorial-to-degree-script/m-p/194104#M41493</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2023-06-08T20:58:39Z</dc:date>
    </item>
    <item>
      <title>Re: factorial to degree script</title>
      <link>https://community.jmp.com/t5/Discussions/factorial-to-degree-script/m-p/194192#M41511</link>
      <description>&lt;P&gt;I realized that my expectations were not right.&amp;nbsp; This actually does the same thing as what fit model macro does.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I like the following iterative approach more though.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;factorial_to_degree = function({factors, degree}, 
	n_factors = nitems(factors);
	factors = shape(factors, n_factors);
	termlist = {};
	for(i=1, i&amp;lt;=degree, i++, 
		nckmat = nchoosekmatrix(n_factors, i);
		for(r = 1, r&amp;lt;=nrows(nckmat), r++, 
			AddTermExpr = Expr(AddTerm());
			for(c=1, c&amp;lt;=ncols(nckmat), c++, 
				insert into(AddTermExpr, Evallist({factors[nckmat[r, c]], 1}));
			);
			insert into(termlist, nameexpr(AddTermExpr));
		);
	);
	return(termlist);
);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Apr 2019 17:36:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/factorial-to-degree-script/m-p/194192#M41511</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2019-04-23T17:36:21Z</dc:date>
    </item>
  </channel>
</rss>

