回复:將字符串從列表轉換為新列中公式正文的腳本。在此示例中,所有“公式”的列名都以“(”開頭,因此您可以將其替換為“(:”,然後使用 Parse
Names Default To Here(1);
dtinit = Open("$SAMPLE_DATA/Bands Data.jmp");
dtfeat = New Table("features",
Add Rows(14),
New Column("Term",
Character,
"Nominal",
Set Property("ID Column", 1),
Set Values(
{"press speed", "(roller durometer-34.5151)*(anode space ratio-102.914)", "(proof cut-44.9671)*(blade pressure-30.8904)",
"(anode space ratio-102.914)*(chrome content-99.6164)", "(humidity-78.6849)*(press speed-1851.21)", "roller durometer",
"(roller durometer-34.5151)*(current density-39.0164)", "(humidity-78.6849)*(wax-2.4037)",
"(wax-2.4037)*(chrome content-99.6164)", "(viscosity-50.7836)*(press speed-1851.21)", "(wax-2.4037)*(hardener-0.96014)",
"(roughness-0.71969)*(current density-39.0164)", "(humidity-78.6849)*(ink pct-55.6473)",
"(blade pressure-30.8904)*(press speed-1851.21)"}
)
),
Set Label Columns(:Term)
);
dtfeat << New Column("interaction", Character, "Nominal", Formula(If(Starts With(:term, "("), :term, ""))) <<
Move Selected Columns({:interaction}, after(:term));
value = dtfeat:interaction << get values();
uniqueinteraction = Associative Array(value) << get keys;
For Each({uniq}, uniqueinteraction,
f_str = Substitute(uniq, "(", "(:");
If(IsMissing(f_str),
continue();
);
Eval(EvalExpr(
dtinit << New Column(uniq, Numeric, "Continuous",
Formula(Expr(Parse(f_str)))
)));
);
使用 Eval Insert、Eval Expr、Parse 和 Substitute 將一個表達式插入另一個表達式
回复:將字符串從列表轉換為新列中公式正文的腳本。傑出的。 成功了。 多謝。
用於將列表中的字符串轉換為新列中的公式主體的腳本。使用擬合平台後,遵循識別一些交互列的過程並尋找一些交互(階乘...)。 我想使用交互產生的項(例如 cA*0.1+cB*0.3)作為起點,自動根據這些項創建列公式。 我努力尋找一種方法來使用字符串的內容,例如“cA * 0.1 + cB * 0.3”,其中cA和cB代表表中存在的2列的名稱來構建新公式。
腳本的最後部分創建公式,但僅表示字符串的內容,而不是評估其內容。
任何建議將不勝感激。
塞巴斯蒂安
names default to here(1);
clear log();
dtinit=Open( "$SAMPLE_DATA/Bands Data.jmp" );
// Make TableBox into a Data Table
// → Data Table( "Untitled 3" )
//terms tables resulting from a generalized regression taking into consideration term interaction.
dtfeat = New Table( "features",
Add Rows( 14 ),
New Column( "Term",
Character,
"Nominal",
Set Property( "ID Column", 1 ),
Set Values(
{"press speed", "(roller durometer-34.5151)*(anode space ratio-102.914)", "(proof cut-44.9671)*(blade pressure-30.8904)",
"(anode space ratio-102.914)*(chrome content-99.6164)", "(humidity-78.6849)*(press speed-1851.21)", "roller durometer",
"(roller durometer-34.5151)*(current density-39.0164)", "(humidity-78.6849)*(wax-2.4037)", "(wax-2.4037)*(chrome content-99.6164)",
"(viscosity-50.7836)*(press speed-1851.21)", "(wax-2.4037)*(hardener-0.96014)", "(roughness-0.71969)*(current density-39.0164)",
"(humidity-78.6849)*(ink pct-55.6473)", "(blade pressure-30.8904)*(press speed-1851.21)"}
)
),
Set Label Columns( :Term )
);
//Identifies interacting terms
// New column: interaction
dtfeat << New Column( "interaction", Character, "Nominal", Formula( If( Starts With( :term, "(" ), :term, "" ) ) ) <<
Move Selected Columns( {:interaction}, after( :term ) );
value = dtfeat:interaction << get values();
uniqueinteraction = Associative Array( value ) << get keys;
nvinteract = N Items( uniqueinteraction );
//Will create a column named after the interacting terms
//Should apply a formula based on the interacting terms
//However, not sure how to extract the string from the list 'uniqueinteraction' so that is it not seen as a string but rather as 'formula instruction' where some portion of the term is recognized as a column namealready present in the original table
For( i = 1, i <= nvinteract, i++,
dtinit << New Column( uniqueinteraction[i], Numeric, "Continuous", Format( "Best", 12 ), Formula( Eval( uniqueinteraction[i] ) )
消費者和市場研究