将 Integrate 与 Interpolate 或 SplineEval 结合使用以获得曲线下的面积。
@塞利格曼写道使用 JMP 求曲线下面积;这里有一些关于一些内置函数的更多信息。
Interpolate 函数使用 X 坐标的排序列表和相应的 Y 坐标列表,并回答“如果 X 为 42,Y 会是多少?”的问题。在排序列表中最近的两个 X 坐标之间使用线性插值。 线性插值产生直线段,数据点位于曲线的拐角处。
SplineEval 函数使用样条插值执行相同的操作(在 Spline Coef 函数的帮助下)。 样条线是一种灵活的、有弹性的金属线,它靠近数据点,具体取决于它的硬度。 通常数据点不会落在样条曲线上。
这两个函数都会生成曲线中从第一个 X 到最后一个 X 的所有数据点。
积分函数回答了另一个问题:“在此范围内,该曲线下方有多少面积?” Interpolate 有四个参数;前两个描述生成曲线的 af(x) 函数,后两个描述 x 值的范围。 Integrate( f(x), x, low, high ) 的结果是 x 从低到高时曲线下的面积。 前两个变量似乎重复 x,因为 f(x) 可能是像 a+2*b 这样的表达式,第二个变量告诉我们 a 或 b 是否是 low 和 high 之间的变量。
这篇文章的 JSL 是关于使用 Interpolate 或 SplineEval 作为 Interpolate 的 f(x) 值。它构建了一个交互式图表,以帮助理解如何使用线性或样条插值来查找由某些噪声数据点定义的曲线下的面积。 它还显示了将噪声(黑色数据点)添加到数据之前的确切答案(红色)。 蓝色曲线是黑色数据点的样条拟合。 中间的条形图并排显示了三个面积计算;当样条张力发生变化时,只有中间的蓝色条会移动。 有了正确的随机数据,任何条形都可以比其他条形更高或更短。
JSL makes a graph like this; the lambda slider changes the blue spline's tension.JSL制作了这样一个图表; lambda 滑块改变蓝色样条线的张力。
每个...都需要 JMP 16
New Window( "Integrate Area Under Curve",
// make a function, in the window: namespace, that returns a sine wave
window:f = Function( {t},
50 + Sin( t / 10 ) * 40
);
// create the x dimension of the graph
window:xmin = 20; // integrate over this range
window:xmax = 80;
window:xcoarse = window:xmin :: window:xmax :: 4; // the coarse data is used to make random data from sin function
window:xfine = window:xmin :: window:xmax :: 0.125; // the fine data is used for outlining smooth polygons
// create the y dimension of the graph from x and function f(x) and some randomness
window:random = 10; // random variation, slider below
// this function called here, and from slider below
window:generatedata = Function( {}, // regenerate the points with new random error
window:ycoarse = window:f( window:xcoarse ) + J( 1, N Col( window:xcoarse ), Random Normal( 0, window:random ) );
// ycoarse is the y data for the points; limit it to stay on the y axis...
window:ycoarse[Loc( window:ycoarse > 99 )] = 99;
window:ycoarse[Loc( window:ycoarse < 1 )] = 1;
);
window:generatedata(); // prepare the initial data in the graph
// lambda is the tension on the spline interpolation, slider below
window:loglambda = 2;// spline tension, a nice middle value
// random patterns for filled areas. the exponents are artistically adjusted for blending the colors
// with gray drawn first, and dark, and yellow drawn last, medium, and blue between, but light.
// there are 7 overlaps with different shades.
window:patternsize = 299; // big square patch for a pattern
window:pat01 = J( window:patternsize, window:patternsize, (Random Integer( 0, 255 ) / 255) ^ 0.5 );//gray
window:pat02 = J( window:patternsize, window:patternsize, (Random Integer( 0, 255 ) / 255) ^ 3 );//blue
window:pat03 = J( window:patternsize, window:patternsize, (Random Integer( 0, 255 ) / 255) ^ 2 );//yellow
window:bar01 = 38;
window:bar02 = 44;// bar x-locations, in graph coordinates; they look good here, for this sine wave
window:bar03 = 50;
window:show = [1 1 1];
window:barwide = 5;
window:barbottom = 50;// bottom of chopped off bar
window:bartop = window:barbottom + 5;
// map values of the AUC onto the graph
window:aucMin = 1500;
window:aucMax = 4000;
window:aucToGraph = Function( {y}, // convert auc to graph Y to make bar heights; 0 is for a label
Interpolate( y, 0, window:barbottom - window:bartop, window:aucMin, 7, window:aucMax, 97 - window:bartop )
);
// draw a broken bar; x in graph units, y in auc units
window:drawAucBar = Function( {x, y},
y = window:aucToGraph( y );
Polygon(// ragged edge bottom poly below the break
x || x || x + .1 * window:barwide || x + .3 * window:barwide || x + .5 * window:barwide || x + .8 * window:barwide || x + window:barwide
|| x + window:barwide,
window:barbottom || window:barbottom + 5 || window:barbottom + 6 || window:barbottom + 4 || window:barbottom + 7 || window:barbottom + 3
|| window:barbottom + 5 || window:barbottom
);
If( y >= 0, // the bar is below the break, don't draw
Polygon(
x || x || x + .1 * window:barwide || x + .3 * window:barwide || x + .5 * window:barwide || x + .8 * window:barwide || x + window
:barwide || x + window:barwide,
window:bartop + y || window:bartop + 5 || window:bartop + 6 || window:bartop + 4 || window:bartop + 7 || window:bartop + 3 || window
:bartop + 5 || window:bartop + y
)
);
);
// make the GUI
window:g = Graph Box(
// this script runs when the graph needs to reshow, either the first time, or because a slider script uses <<RESHOW framesize=""></RESHOW>