我使用此参考是因为它是我发现的唯一包含必要细节的参考:
“ Marchu,Victor AA, 弗朗西斯科·AR·罗哈斯(Francisco AR Rojas)和弗朗西斯科·卢萨达(Francisco Louzada)
“用于分析双变量的Chi图及其渐近置信区间
依赖性:对平均智力和无神论率的应用
跨国家数据”,数据科学杂志10(2012),711-722。
我写了这个脚本并验证了等式,但是这些图对我而言并不正确,因此我没有做任何进一步的介绍。
Names Default to Here( 1 );
// get data columns for Y and X roles
dt = Current Data Table();
If( Is Empty( dt ),
Throw( "No data table open" );
);
dialog = New Window( "Chi-Plot", << Modal,
H List Box(
dt clb = Col List Box( All ),
Line Up Box( N Col( 2 ),
Button Box( "Y",
item = dt clb << Get Selected;
y clb << Append( item );
If( N Items( x clb << Get Items ) > 0,
ok bb << Enable( 1 ),
ok bb << Enable( 0 )
);
),
y clb = Col List Box(
Min Items( 1 ), Max Items( 1 ),
<< Set Analysis Type( Continuous )
),
Button Box( "X",
item = dt clb << Get Selected;
x clb << Append( item );
If( N Items( y clb << Get Items ) > 0,
ok bb << Enable( 1 ),
ok bb << Enable( 0 )
);
),
x clb = Col List Box(),
Button Box( "Remove",
y clb << Remove All;
x clb << Remove All;
ok bb << Enable( 0 );
),
Text Box( "")
)
),
H List Box(
ok bb = Button Box( "OK",
y col = Column( (y clb << Get Items)[1] );
x col = Column( (x clb << Get Items)[1] ),
<< Enable( 0 )
),
Button Box( "Cancel")
)
);
// unload dialog
If( dialog["Button"] == -1,
Throw( "User cancelled" );
);
// utility to user alerts
alert# = Function( { msg },
New Window( "Alert", << Modal,
Text Box(
" " || msg || " ",
<< Justify Text( "center" ),
<< Set Font Size( 12 )
),
Text Box( " " )
);
);
// sample size and scaling
n = N Row( dt );
scale = 1 / (n-1);
// data vectors
y = y col << Get As Matrix;
x = x col << Get As Matrix;
// cumulative indicators
F = G = H = J( n, 1, . );
// chi-plot coordinates
χ = λ = J( n, 1, . );
For Each Row(
If( Not( Excluded( Row State() ) ),
i = Row();
// compute cumulative indicators for current row
F[i] = scale * Summation( j = 1, n, If( j != i, x[j] <= x[i], 0 ) );
G[i] = scale * Summation( j = 1, n, If( j != i, y[j] <= y[i], 0 ) );
H[i] = scale * Summation( j = 1, n, If( j != i, x[j] <= x[i] & y[j] <= y[i], 0 ) );
// computer chi-plot coordinates for current row
χ[i] = (H[i] - (F[i] * G[i])) / Sqrt( F[i] * (1-F[i]) * G[i] * (1-G[i]) );
sign = ((F[i]-0.5) * (G[i]-0.5));
λ[i] = 4 * sign * Maximum( (F[i]-0.5)^2, (G[i]-0.5)^2 );
);
);
// add coordinates to data table
χ col = dt << New Column( "χ", Numeric, Continuous, Values( χ ) );
λ col = dt << New Column( "λ", Numeric, Continuous, Values( λ ) );
// add table script for Chi-Plot
dt << New Script( "Chi-Plot",
Current Data Table() << Graph Builder(
Size( 600, 400 ),
Show Control Panel( 0 ),
Show Legend( 0 ),
Variables( X( :λ ), Y( :χ ) ),
Elements( Points( X, Y, Legend( 3 ) ) ),
SendToReport(
Dispatch(
{},
"λ",
ScaleBox,
{Min( -1 ), Max( 1 ), Inc( 0.2 ), Minor Ticks( 0 )}
),
Dispatch(
{},
"χ",
ScaleBox,
{Min( -1 ), Max( 1 ), Inc( 0.2 ), Minor Ticks( 0 )}
),
Dispatch( {}, "graph title", TextEditBox, {Set Text( "Chi-Plot" )} )
)
);
);
// launch Chi-Plot
gb = dt << Graph Builder(
Size( 600, 400 ),
Show Control Panel( 0 ),
Show Legend( 0 ),
Variables( X( :λ ), Y( :χ ) ),
Elements( Points( X, Y, Legend( 3 ) ) ),
SendToReport(
Dispatch(
{},
"λ",
ScaleBox,
{Min( -1 ), Max( 1 ), Inc( 0.2 ), Minor Ticks( 0 )}
),
Dispatch(
{},
"χ",
ScaleBox,
{Min( -1 ), Max( 1 ), Inc( 0.2 ), Minor Ticks( 0 )}
),
Dispatch( {}, "graph title", TextEditBox, {Set Text( "Chi-Plot" )} )
)
);