昨日、次のスレッドを見つけたので、parse() を調査しました。
https://community.jmp.com/t5/Discussions/evaluating-a-string-using-a-column-formula/mp/38028
思考プロセスは次のとおりです。
- expr() を使用する場合、JMP は他の引数ではなく、関数を引数として想定します。 これについては後で詳しく説明します。
- 引数を文字列として変数に保存し、別の引数または関数に配置できる場合、これは必要なものをコーディングするのに役立ちます
これが例です。
names default to here(1);
clear log();
clear symbols();
dt = open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Graph Builder(
Size( 517, 447 ),
Show Control Panel( 0 ),
Fit to Window,
Set α Level( 0.05 ),
Variables( X( :weight ), Y( :height ), Color( :sex ) ),
Elements( Points( X, Y, Legend( 3 ) ) ),
SendToReport(
Dispatch(
{},
"height",
ScaleBox,
{Add Ref Line( 67.5, "Solid", "Black", "Tall", 1 )}
)
)
);スクリプトは Big Class.jmp を開き、参照線を含む視覚化を生成します。 視覚化のために他のソースからデータを取得したい場合は、上記のスクリプトを次のように変更できます。
Names default to here(1);
clear log();
dt = open( "$SAMPLE_DATA/Big Class.jmp" );
// Example "other" source
ex = New Table( "Example",
Add Rows(2),
New Column( "Growth Label", Character, Nominal, Set Values( { "Tall", "Short" } ) ),
New Column( "Height tag", Numeric, Continuous, Set Values( { 67.5, 60 } ) ),
);
dt << Graph Builder(
Size( 517, 447 ),
Show Control Panel( 0 ),
Fit to Window,
Set α Level( 0.05 ),
Variables( X( :weight ), Y( :height ), Color( :sex ) ),
Elements( Points( X, Y, Legend( 3 ) ) ),
SendToReport(
Dispatch(
{},
"height",
ScaleBox,
{Add Ref Line( ex:Height tag[1], "Solid", "Black", ex:Growth Label[1], 1 )} // 2x references to data table( "Example" ) as "ex"
)
)
);上記のスクリプトの違いは、リファレンス ライン情報の一部が、作成されたサンプル テーブルから取得されていることです。上記のスクリプトのビジュアライゼーションをデータ テーブル スクリプトとして追加したい場合はどうすればよいでしょうか?値のために常に別のテーブルを参照したくないと仮定すると、参照をそれらが表す値に置き換えるにはどうすればよいでしょうか?答えは式の操作であり、一見 parse() です。
式操作の詳細については、次のリソースを参照してください。 https://www.jmp.com/support/help/en/17.0/#page/jmp/advanced-expressions-macros-and-lists.shtml#
ビジュアライゼーションをテーブル スクリプトとして Big Class に追加する場合、スクリプト ウィンドウは次のようなコードになります。
// Visualization - No references to other data sources
dt << New script( "Vis 1",
Graph Builder(
Size( 517, 447 ),
Show Control Panel( 0 ),
Fit to Window,
Set α Level( 0.05 ),
Variables( X( :weight ), Y( :height ), Color( :sex ) ),
Elements( Points( X, Y, Legend( 3 ) ) ),
SendToReport(
Dispatch(
{},
"height",
ScaleBox,
{Add Ref Line( 67.5, "Solid", "Black", "Tall", 1 )}
)
)
);
);
// Visualization - With references to other data sources
// This will not work, as the data table reference "ex" is undefined
// We could replace ex with data table( "example" ), but that table would need to be open in the background
dt << New script( "Vis 2",
Graph Builder(
Size( 517, 447 ),
Show Control Panel( 0 ),
Fit to Window,
Set α Level( 0.05 ),
Variables( X( :weight ), Y( :height ), Color( :sex ) ),
Elements( Points( X, Y, Legend( 3 ) ) ),
SendToReport(
Dispatch(
{},
"height",
ScaleBox,
{Add Ref Line( ex:Height tag[1], "Solid", "Black", ex:Growth Label[1], 1 )}
)
)
);
);これは、parse() に焦点を当てた、これまでの調査と実験の成果です。まだうまくいきませんが、正しい方向への一歩です!
names default to here(1);
clear log();
clear symbols();
// Opening & creating data tables for use
dt = open( "$SAMPLE_DATA/Big Class.jmp" );
ex = New Table( "Example",
Add Rows(2),
New Column( "Growth Label", Character, Nominal, Set Values( { "Tall", "Short" } ) ),
New Column( "Height tag", Numeric, Continuous, Set Values( { 67.5, 60 } ) ),
);
// Variables
graphing = expr( Graph Builder() );
size = "Size( 517, 447 )";
control_panel = "Show Control Panel( 0 )";
fit = "Fit to Window";
a_lvl = "Set α Level( 0.05 )";
vars = "Variables( X( :weight ), Y( :height ), Color( :sex ) )";
eles = "Elements( Points( X, Y, Legend( 3 ) ) )";
str = "SendToReport()";
disp = parse( "Dispatch()" );
curly = "{}";
label = "ex:Growth label[1]";
label2 = "height";
scle = "ScaleBox";
x_axis = "x()";
test_label = "ex:Height tag[1]";
mylabel = "ex:Growth label[1]";
ref_line = parse( "Add Ref Line()" );
insert into( graphing, parse( size ) );
insert into( graphing, parse( control_panel ) );
insert into( graphing, parse( fit ) );
insert into( graphing, parse( a_lvl ) );
insert into( graphing, parse( vars ) );
insert into( graphing, parse( eles ) );
show( graphing ); // Result:graphing = Graph Builder(Size(517, 447), Show Control Panel(0), Fit to Window, Set α Level(0.05), Variables(X(:weight), Y(:height), Color(:sex)), Elements(Points(X, Y, Legend(3))));
// add ref line
insert into( ref_line, eval( parse( test_label ) ) );
insert into( ref_line, "Solid" );
insert into( ref_line, "Black" );
insert into( ref_line, eval( parse( mylabel ) ) );
show( ref_line ); // Result: ref_line = Add Ref Line(67.5, "Solid", "Black", "Tall");
insert into( disp, parse( curley ) );
insert into( disp, eval( parse( mylabel ) ) );
insert into( disp, char( label2 ) );
insert into( disp, parse( scle ) );
insert into( disp, parse( curly ) ); // Note this line! More work needs to be done here
show( disp ); // Result: disp = Dispatch({}, "Tall", "height", ScaleBox, {});上記のスクリプトは非常に忙しいので、残りの部分を把握した後、必要な変数の数を減らして最適化する方法を探します。これはかなりのリストです。
スクリプトの下部近くに、メモに関する詳細情報があります。curly を disp に挿入する前に、ref_line を curly に挿入する必要があります。 これができると考えるのは簡単でしょう:
insert( curley, ref_line );
ただし、ref_line の内容は関数ではなく引数に含まれているため、JMP はエラーになります。これを回避する方法が分かれば、他のすべては簡単になるはずです。私の次の推測は、次のようなことを試すことです。
// Note: char( ref_line ) will cause JMP to error, because it's an argument
new_parse = expr( parse() );
insert into( new_parse, char( ref_line) );
// Then somehow
eval( insert into( curley, eval expr( eval( new_parse ) ) ) );
非文字型の引数を別の引数に挿入する方法を学んだ後は、Graph Builder() 関数の残りの部分を簡単に作成できます。 最後のピースは、すべてを式として dt << New Script( "Visualization", ); に挿入し、eval expr() と別の eval() (?) を使用して JMP を正常に実行させることです。コードを編集し、ビジュアライゼーションを dt に挿入します。
ここで私が見つけた興味深いものがあります。引数 (非文字) を別の引数 (文字) に挿入しようとすると、try() は非文字が文字列になるのを助けました。しかし、これをもう少しテストしたところ、結果は再現できませんでした。また、これらの中括弧は、何かを挿入するのが非常に困難です。
Names default to here(1);
clear log();
// This block demonstrates, at a basic level, what I'm trying to do
printing = Expr( print() );
hello = "hello world";
insert into( printing, hello );
eval( printing );
show( printing ); // Result = printing = Print("hello world");
// Test run 1 - Works
new_parse1 = Parse( "Variable()" );
mytest1 = "X(:height)";
insert into( new_parse1, parse( mytest1 ) );
show( new_parse1, type( mytest1 ) ); // Result: new_parse = Variable(X(:height)); Type(mytest) = "String";
// Test run 2 - Doesn't work
new_parse2 = Parse( "Variable()" );
mytest2 = X(:height); // "Name unresolved"" error! X is not recognized
insert into( new_parse2, parse( mytest2 ) );
show( new_parse2, type( mytest2 ) ); // Intended: new_parse = Variable(X(:height)); Type(mytest) = "String";
// Test run 3 - Works
new_parse3 = Parse( "Variable()" );
try( mytest3 = X(:height) );
insert into( new_parse3, parse( mytest3 ) );
show( new_parse3, type( mytest3 ) ); // Result: new_parse = Variable(X(:height)); Type(mytest) = "String";
// Test run 4 - Doesn't work
curly = "{}";
new_parse4 = Parse( "Variable()" );
x_test = parse( "X()" );
some_list = { "one", "two", "three" };
insert into( x_test, eval( some_list[1] ) );
show( x_test ); // Result: x_test = X("one");
insert into( new_parse4, x_test ); // Containing within try() avoids error, but x_test not added into new_parse3
show( new_parse3 ); // Result: new_parse3 = Variable(); <-- Intended: new_parse3 = Variable(X("one"));
insert into( curly, new_parse4 );
show( curly ); // Intended: new_parse3 = {Variable(X("one"))};
// Other attempts - Doesn't work
variable1 = Variable(X("one"));
variable2 = eval insert( "{^variable1^}" );
variable3 = "{" || char( variable1 ) || "}";あなたは私が信じている余分な複雑さをたくさん持っています。このようなものがあなたが待っているものだと思います:
Names default to here(1);
clear log();
// Reference table
// Used to populate data in table script below for dt( big )
dt = New Table( "Example",
Add Rows(2),
New Column( "Growth Label", Character, Set Values( { "Tall", "Short", "Thin" } ) ),
New Column( "Height tag", Numeric, Set Values( { 67.5, 60, 56 } ) ),
New Column( "color", Character, Set Values( { "medium dark green", "medium dark red", "purple" } ) )
);
// Example table
big = open( "$SAMPLE_DATA/Big Class.jmp" );
big << New Column( "Random", Numeric, <<SET each="" value=""></SET>こんにちは、
いくつかのビジュアライゼーションをテーブル スクリプトとしてスクリプト化するタスクがあります。通常、これは簡単です。 大まかな部分は、スクリプトの実行中に他のソースを参照する必要がある参照行です。参照は、通常は外部から変数を受け入れない 2 つの関数に含まれているため、式操作を使用してこれらの値を挿入する方法を見つけることは、現時点では私のスキル レベルを超えています。 克服しなければならない障害は複数あります。
- 外部変数をうまく受け入れない関数
- var1 = 1;
var2 = 2;
Dt << 新しいスクリプト( "例", print( var1 + var2 ) ); - 変数はテーブル スクリプトから定義されることに注意してください。 数値はデータ テーブルから参照されるため、これは必須です。
- 急送()
- この内部の値については、静的で明確に記述された値である必要があります。
- 関数を含まない式の操作
- 例 = expr( New Script() );
タイトル = "テスト";
insert into( 例, タイトル ); // show(example) = 新しいスクリプト( “test” )
// 後で、例の 22 行目のように、x 軸に列を挿入するときに…
x_empty = expr( X() );
x_cols = { :col1, :col2 };
insert into( x_empty, x_cols[1] ); // エラーが発生します。JMP は X() が何であるかを知りません - これは、どういうわけか X() を評価しない必要があるが、それでも項目の挿入を許可する必要があることを示しています。これは、name expr() や expr() のような関数が行うことになっているものですが、この場合は機能しません。
サンプル スクリプトには、達成したいことの簡略化された例が含まれています。 新しく生成されたテーブルのタイトルと番号は、関数が実行されて Big Class に挿入される前に、テーブル スクリプトに挿入されます。 スクリプトの最後にこの基本的な例があります。
Names default to here(1);
clear log();
// Reference table
// Used to populate data in table script below for dt( big )
dt = New Table( "Example",
Add Rows(2),
New Column( "Growth Label", Character, Nominal, Set Values( { "Tall", "Short" } ) ),
New Column( "Height tag", Numeric, Continuous, Set Values( { 67.5, 60 } ) ),
);
// Example table
big = open( "$SAMPLE_DATA/Big Class.jmp" );
// Plain example - vis added as table script * works *
big << New Script( "Example",
Graph Builder(
Size( 534, 456 ),
Show Control Panel( 0 ),
Fit to Window,
Set α Level( 0.05 ),
Variables( X( :weight ), X( :age ), Y( :height ), Color( :sex ) ),
Elements( Points( X, Y, Legend( 4 ) ) ),
SendToReport(
Dispatch(
{},
"height",
ScaleBox,
{Add Ref Line( 67.5, "Dashed", "Medium Dark Green", "Tall", 1 ),
Add Ref Line( 60, "Dashed", "Medium Dark Red", "Short", 1 )}
)
)
)
);
// Needed info for below
vis_x = { :weight, :age };
vis_y = { :height };
// Modified example - vis added as table script * not working *
big << New Script( "Example",
Graph Builder(
Size( 534, 456 ),
Show Control Panel( 0 ),
Fit to Window,
Set α Level( 0.05 ),
Variables( X( vis_x[1] ), X( vis_x[1] ), Y( vis_y[1] ), Color( :sex ) ),
Elements( Points( X, Y, Legend( 4 ) ) ),
SendToReport(
Dispatch(
{},
"height",
ScaleBox,
{Add Ref Line( big:Height tag[1], "Dashed", "Medium Dark Green", big:Growth Label[1], 1 ),
Add Ref Line( big:Height tag[2], "Dashed", "Medium Dark Red", big:Growth Label[2], 1 )}
)
)
)
);
// Example: expression manipulations
var1 = 10; // represents some reference number, from somewhere
var2 = 1; // represents some reference number, from somewhere
expr_test = eval expr( expr(var1) + expr(var2) );
expr_begin = expr( New Script( "Var replacement" ) );
insert into( expr_begin, name expr( expr_test ) );
show( expr_begin );
eval( eval expr( big << expr( name expr( expr_begin ) ) ) ); // Script contains: 10 + 1
/* Notice how the table script "Var replacement" in big doesn't contain var1 & var2,
it contains the values they represent. This is what I want to do. */
close( dt, "No Save" );コミュニティ フォーラムで「基準線」を検索すると、かなりの数の結果が得られます。 これまでに私が見つけた最も近い例は、以下のリンクです。
https://community.jmp.com/t5/Discussions/Is-there-a-way-to-automatically-draw-ref-lines-at-the-peak-of/mp/87721/highlight/false#M38710
https://community.jmp.com/t5/Discussions/Fill-color-for-multiple-reference-lines/mp/273205