阶乘至度脚本我很难在脚本中将阶乘转换为度数,以便将某些 DOE 因子分配给某些阶乘。
我可以使用 nchoosekMatrix() 获得第一级,但不知道如何动态获得高于 1 的级别。
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<=nrows(nckmat), r++,
AddTermExpr = Expr(AddTerm());
for(c=1, c<=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} )
}
*/
我认为我应该以递归方式做一些事情,但实际上我很难让任何事情发挥作用。
任何帮助都将不胜感激。
实验设计质量与工艺工程阶乘到程度的脚本我很难在脚本内部进行因子分析,以便将某些DOE因子分配给某个因子。
我可以使用nchoosekMatrix()获得第一级,但无法弄清楚如何动态获得高于1的级别。
factorial_to_degree = function({factors, degree = 2},
{DEFAULT LOCAL},
nckmat = nchoosekmatrix(nrows(factors), degree);
termlist = {};
for(r = 1, r<=nrows(nckmat), r++,
AddTermExpr = Expr(AddTerm());
for(c=1, c<=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}, {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, 1}, {2, 1} ), AddTerm( {1, 2}, {2, 1} ), AddTerm( {1, 1}, {2, 2} ),
AddTerm( {1, 1}, {3, 1} ), AddTerm( {1, 2}, {3, 1} ), AddTerm( {1, 1}, {3, 2} ),
AddTerm( {2, 1}, {3, 1} ), AddTerm( {2, 2}, {3, 1} ), AddTerm( {2, 1}, {3, 2} )
}
*/
我想我应该递归地做一些事情但是我很难实际上有任何工作。
任何帮助将不胜感激。
Re:factorial to degree脚本我意识到我的期望是不对的。 这实际上与模型宏的功能相同。
我更喜欢以下迭代方法。
factorial_to_degree = function({factors, degree},
n_factors = nitems(factors);
factors = shape(factors, n_factors);
termlist = {};
for(i=1, i<=degree, i++,
nckmat = nchoosekmatrix(n_factors, i);
for(r = 1, r<=nrows(nckmat), r++,
AddTermExpr = Expr(AddTerm());
for(c=1, c<=ncols(nckmat), c++,
insert into(AddTermExpr, Evallist({factors[nckmat[r, c]], 1}));
);
insert into(termlist, nameexpr(AddTermExpr));
);
);
return(termlist);
);