8
conf95.sdw 2/4/02 1/8 The Confidence 95 Ellipse Introduction. Important parameters in posturogram analysis are derived from the 95 % confidence ellipse (let's shorten it as Conf95 here). Basically it is the smallest ellipse that will cover 95 % of the points of the COP diagram. Whereas the simple procedure of drawing a perimeter around the COP- trace does not distinguish regions that are more or less frequented, the Conf95 puts more weight on regions more frequently visited. The following figure shows an example with the Conf95 (blue) catching most of the COP-trace (red). Two important parameters are associated with this ellipse; its area and the inclination of its main axis relative to the medial-lateral axis (x-axis) or anterior- posterior axis (y-axis). The latter shows the directional tendency of the sways. Computation. The Conf95 ellipse can be computed using the assumption that the coordinates of the COP-points will be approximately Gaussian distributed around their mean. Generally we have a nonzero correlation between the x-coordinates and y-coordinates. The conf95 ellipse will be chosen so that for coordinates defined with respect to its axes are uncorrelated. The first step is to subtract the mean values from the x- and y-coordinates of the COP-points. (1) x i x i ˆ x y i y i ˆ y F Borg Bioproject, Chydenius Institute, Finland.

The Confidence 95 Ellipse - University of Delaware of... · The Confidence 95 Ellipse Introduction. Important parameters in posturogram analysis are derived from the 95 % confidence

  • Upload
    vocong

  • View
    220

  • Download
    0

Embed Size (px)

Citation preview

Page 1: The Confidence 95 Ellipse - University of Delaware of... · The Confidence 95 Ellipse Introduction. Important parameters in posturogram analysis are derived from the 95 % confidence

conf95.sdw 2/4/02 1/8

The Confidence 95 EllipseIntroduction. Important parameters in posturogram analysis are derived from the 95 % confidenceellipse (let's shorten it as Conf95 here). Basically it is the smallest ellipse that will cover 95 % of thepoints of the COP diagram. Whereas the simple procedure of drawing a perimeter around the COP-trace does not distinguish regions that are more or less frequented, the Conf95 puts more weight onregions more frequently visited. The following figure shows an example with the Conf95 (blue)

catching most of the COP-trace (red). Two important parameters are associated with this ellipse; itsarea and the inclination of its main axis relative to the medial-lateral axis (x-axis) or anterior-posterior axis (y-axis). The latter shows the directional tendency of the sways.

Computation. The Conf95 ellipse can be computed using the assumption that the coordinates of theCOP-points will be approximately Gaussian distributed around their mean.

Generally we have a nonzero correlation between the x-coordinates and y-coordinates. The conf95ellipse will be chosen so that for coordinates defined with respect to its axes are uncorrelated.

The first step is to subtract the mean values from the x- and y-coordinates of the COP-points.

(1) xi →xi�x y i → yi� y

F Borg Bioproject, Chydenius Institute, Finland.

Page 2: The Confidence 95 Ellipse - University of Delaware of... · The Confidence 95 Ellipse Introduction. Important parameters in posturogram analysis are derived from the 95 % confidence

conf95.sdw 2/4/02 2/8

Then, let us compute the 2 × 2 correlation matrix C for the COP-points:

(2) C=(Cxx Cxy

C yx C yy) Cxx=∑i

xi2 Cxy=C yx=∑

ixi yi C yy=∑

iy i

2

The ellipse axis-vectors are obtained as the unit eigenvectors e0 and e1 of the matrix C. Suppose thecorresponding eigenvalues are λ0 ≥ λ1 > 0. Suppose the COP-data consists of N points. Accordingto our construction we may now assume that the coordinates of the COP-points projected on theellipse axes have Gaussian distributions with means 0 and standard deviations

(3) σ 0=λ0

N�1σ 1=

λ1

N�1

If the coordinates visavis the axes e0 and e1 are denoted ξ and η then we may assume that thevariables

(4)ξ

σ 0and

η

σ 1

are independent having the normal distribution, N(0,1). Especially the variable

(5) ζ=( ξ

σ 0)2

+( η

σ 1)2

will then have a chi-square distribution of second degree. Since (looking up the tables)

(6) Prob(ζ<5.991)=0.95

it follows that 95 % of the points will be inside an ellipse described by

(7) ( ξ

σ 0)2

+( η

σ 1)2

=5.991

This is our Conf95 ellipse. It can be drawn by setting the main half-axis as

(8) 5.991σ 0 e0

and the minor half-axis as

(9) 5.991σ 1 e1

The inclination angle is given as the angle between e0 and the x-axis. Finally, the area of the ellipse

F Borg Bioproject, Chydenius Institute, Finland.

Page 3: The Confidence 95 Ellipse - University of Delaware of... · The Confidence 95 Ellipse Introduction. Important parameters in posturogram analysis are derived from the 95 % confidence

conf95.sdw 2/4/02 3/8

is given by

A=5.991πσ 0σ 1

Appendix A. Experimental Labwindows CVI code:

#define HISTN 40 // number of intervals for the histogram#define ELLN 50 // number of points defining the ellipse

int AnalyseBal(char *pathn) {

int err = 0, rows=0, cols = 1, i, j, k;FILE *fp;char c;char line[600];double **dat = 0;float data;int ploth[6], mess1ID, aindex;double max[6], min[6], scale[6], offset[6], std[2], mean[2];int maxi[6], mini[6], ctrlID[12], cSTD[2];char Contr[80];int histx[HISTN], histy[HISTN], CanvH, CanvW;double axisx[HISTN], axisy[HISTN], x0, y0, x1, y1, sc, dx, dy, maxd, mx, my;double perim = 0, trlength = 0;double **vel = 0, dt, s;Point Newp, Oldp;double corr[2][2], evec[2][2], eval[2], rr[2]; // corr = correlation matrixdouble ellx, elly, cosu, sinu, u, inclination, r95, area;double gaussx[HISTN], gaussy[HISTN];

SuspendTimerCallbacks();

panelAnal = LoadPanel(panelHandle, "fplat.uir", OPEN);InstallPopup(panelAnal);

if((fp = fopen(pathn, "r")) != NULL) {

while(!feof(fp)) // scans the next row { fscanf (fp, "%c", &c); if(c == '\n') break; if(c == '\t') cols++; // counts the nr of tabs in the numerical part of the file }

rewind(fp);

while(!feof(fp)) { // counts the number of rows

if(fgets (line, 600 , fp) != NULL) rows = rows + 1;

}

rewind(fp);

dat = (double**)malloc(cols*sizeof(double*)); for(j=0; j < cols; j++) dat[j] = (double*)malloc(rows*sizeof(double)); vel = (double**)malloc(2*sizeof(double*)); for(i=0; i <2 ; i++) vel[i] = (double*)malloc(rows*sizeof(double));

F Borg Bioproject, Chydenius Institute, Finland.

Page 4: The Confidence 95 Ellipse - University of Delaware of... · The Confidence 95 Ellipse Introduction. Important parameters in posturogram analysis are derived from the 95 % confidence

conf95.sdw 2/4/02 4/8

k = 0;

while(!feof(fp)) {

if(fscanf (fp, "%f", &data) == 1){

// 1st column copx, 2nd column copy, rest emg if any dat[k%cols][k/cols] = (double)data; k++; } }

fclose(fp);

mess1ID = NewCtrl (panelAnal, CTRL_TEXT_MSG, "File:", 10, 37);SetCtrlVal(panelAnal, mess1ID, pathn);

StdDev (dat[0], rows, &mean[0], &std[0]);StdDev (dat[1], rows, &mean[1], &std[1]);

cSTD[0] = NewCtrl (panelAnal, CTRL_NUMERIC, "Std", 371 , 760); //stdev COPxSetCtrlAttribute (panelAnal, cSTD[0], ATTR_CTRL_MODE, VAL_INDICATOR);

cSTD[1] = NewCtrl (panelAnal, CTRL_NUMERIC, "Std", 308 , 760); //stdev COPxSetCtrlAttribute (panelAnal, cSTD[1], ATTR_CTRL_MODE, VAL_INDICATOR);

SetCtrlVal(panelAnal, cSTD[0], std[0]);SetCtrlVal(panelAnal, cSTD[1], std[1]);

MaxMin1D (dat[0], rows, &max[0], &maxi[0], &min[0], &mini[0]); MaxMin1D (dat[1], rows, &max[1], &maxi[1], &min[1], &mini[1]);

// histogram calculation

LinEv1D (dat[0], rows, 1, -mean[0], dat[0]); // subtracts mean value from the dataLinEv1D (dat[1], rows, 1, -mean[1], dat[1]);

dt = (double)SamplSize/ (double)SamplFreq;

Histogram (dat[0], rows, min[0]-mean[0], max[0] - mean[0], histx, axisx, HISTN);Histogram (dat[1], rows, min[1]-mean[1], max[1] - mean[1], histy, axisy, HISTN);

for(i=0; i < 2; i++) // velocity calculation – not used yet Difference (dat[i], rows, dt, dat[i][0], dat[i][rows-1], vel[i]);

// compute gaussian prob density

x0 = (axisx[1] - axisx[0])*rows/sqrt(2*PII)/std[0];x1 = (axisy[1] - axisy[0])*rows/sqrt(2*PII)/std[1];y0 = 0.5/std[0]/std[0];y1 = 0.5/std[1]/std[1];

for(i=0; i < HISTN; i++) {

gaussx[i] = x0*exp(-y0*axisx[i]*axisx[i]); gaussy[i] = x1*exp(-y1*axisy[i]*axisy[i]);

}

PlotXY (panelAnal, OPEN_HISTX, axisx, histx, HISTN, VAL_DOUBLE,VAL_INTEGER, VAL_VERTICAL_BAR, VAL_EMPTY_SQUARE, VAL_SOLID, 1,VAL_RED);

PlotXY (panelAnal, OPEN_HISTX, axisx, gaussx, HISTN, VAL_DOUBLE,

F Borg Bioproject, Chydenius Institute, Finland.

Page 5: The Confidence 95 Ellipse - University of Delaware of... · The Confidence 95 Ellipse Introduction. Important parameters in posturogram analysis are derived from the 95 % confidence

conf95.sdw 2/4/02 5/8

VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1,VAL_BLUE);

PlotXY (panelAnal, OPEN_HISTY, axisy, histy, HISTN, VAL_DOUBLE,VAL_INTEGER, VAL_VERTICAL_BAR, VAL_EMPTY_SQUARE, VAL_SOLID, 1,VAL_RED);

PlotXY (panelAnal, OPEN_HISTY, axisy, gaussy, HISTN, VAL_DOUBLE, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLUE);

// computation of the confidence ellipse

for(i = 0; i < 2; i++)for(j = i; i <= j, j < 2; j++)

DotProduct (dat[i], dat[j], rows, &corr[i][j]);

corr[1][0] = corr[0][1]; // symmetric matrixSymEigenValueVector (corr, 2, 1, eval, evec); // calculate eigenvalues eval and eigenvectors evec

if(rows > 1)for(i = 0; i < 2; i++) {

rr[i] = sqrt(eval[i]/ (double) (rows-1)); // std deviation along the new axisDotProduct (evec[i], evec[i], 2, &s); // normalizings = sqrt(s);for(j=0; j < 2; j++) evec[i][j] /= s;

}

aindex = (rr[0] > rr[1]) ? 0: 1; // index of main axis

// plot trace// calculate length of cop-trace

SetCtrlAttribute(panelAnal, OPEN_CANVAS, ATTR_PEN_COLOR, VAL_RED);

GetCtrlAttribute(panelAnal, OPEN_CANVAS, ATTR_WIDTH, &CanvW);GetCtrlAttribute(panelAnal, OPEN_CANVAS, ATTR_HEIGHT, &CanvH);

dx = 2*fabs(max[0] - mean[0]);dy = 2*fabs(max[1] - mean[1]);

maxd = (dx > dy) ? dx : dy;

mx = 0; // not usedmy = 0;

sc = (double)((CanvH < CanvW)? CanvH : CanvW);

x0 = (((dat[0][0] - mx)/maxd) + 0.5)*sc;y0 = (-((dat[1][0] - my)/maxd) + 0.5)*sc;

Oldp.x = RoundRealToNearestInteger(x0); Oldp.y = RoundRealToNearestInteger(y0);

for(i=1; i < rows; i++) {

x1 = (((dat[0][i] - mx)/maxd) + 0.5)*sc;y1 = (-((dat[1][i] - my)/maxd) + 0.5)*sc;

trlength += (maxd/sc)*sqrt ((x0 -x1)*(x0 -x1) + (y0-y1)*(y0-y1));

x0 = x1;y0 = y1;

F Borg Bioproject, Chydenius Institute, Finland.

Page 6: The Confidence 95 Ellipse - University of Delaware of... · The Confidence 95 Ellipse Introduction. Important parameters in posturogram analysis are derived from the 95 % confidence

conf95.sdw 2/4/02 6/8

Newp.x = RoundRealToNearestInteger(x1); Newp.y = RoundRealToNearestInteger(y1);

CanvasSetPenPosition(panelAnal, OPEN_CANVAS, Oldp);CanvasDrawLineTo(panelAnal, OPEN_CANVAS, Newp);

Oldp.x = Newp.x;Oldp.y = Newp.y;

}

SetCtrlVal(panelAnal, OPEN_LENGTH, trlength);

// plot the confidence ellipse

r95 = sqrt(5.991); // 95% confidence *radius* -- chi-square 2 DF

area = PII*5.991*rr[0]*rr[1]; // area of the ellipse

SetCtrlVal(panelAnal, OPEN_AREA, area);

ellx = rr[0]*evec[0][0]; // initial pointelly = rr[0]*evec[0][1];

ellx *= r95*sc/maxd;elly *= r95*sc/maxd;

Oldp.x = RoundRealToNearestInteger(ellx + sc/2); Oldp.y = RoundRealToNearestInteger(elly + sc/2);

ellx = rr[aindex]*evec[aindex][0]; // the main axis end point elly = rr[aindex]*evec[aindex][1];

ellx *= r95*sc/maxd;elly *= r95*sc/maxd;

x0 = RoundRealToNearestInteger(ellx + sc/2); y0 = RoundRealToNearestInteger(elly + sc/2);

SetCtrlAttribute(panelAnal, OPEN_CANVAS, ATTR_PEN_COLOR, VAL_BLUE);

CanvasDrawLine (panelAnal, OPEN_CANVAS, MakePoint(sc -x0, sc - y0),MakePoint(x0,y0));

for(i=1; i < ELLN; i++) { // ellipse

u = 2*PII*(double)i/(double)ELLN;

cosu = cos(u);sinu = sin(u);

ellx = rr[0]*cosu*evec[0][0] + rr[1]*sinu*evec[1][0];elly = rr[0]*cosu*evec[0][1] + rr[1]*sinu*evec[1][1];

ellx *= r95*sc/maxd;elly *= r95*sc/maxd;

Newp.x = RoundRealToNearestInteger(ellx + sc/2); Newp.y = RoundRealToNearestInteger(elly + sc/2);

// printf("%f\t%i\t%i\n", u, Newp.x, Newp.y);

CanvasSetPenPosition(panelAnal, OPEN_CANVAS, Oldp);CanvasDrawLineTo(panelAnal, OPEN_CANVAS, Newp);

Oldp.x = Newp.x;

F Borg Bioproject, Chydenius Institute, Finland.

Page 7: The Confidence 95 Ellipse - University of Delaware of... · The Confidence 95 Ellipse Introduction. Important parameters in posturogram analysis are derived from the 95 % confidence

conf95.sdw 2/4/02 7/8

Oldp.y = Newp.y;

}

// calclutate inclination

inclination = asin(evec[aindex][1])*180.0/PII;

// if(inclination > 90) inclination = 180 - inclination;

SetCtrlVal(panelAnal, OPEN_ANGLE, inclination);

SetCtrlAttribute(panelAnal, OPEN_CANVAS, ATTR_PEN_COLOR, VAL_BLACK);

CanvasDrawLine (panelAnal, OPEN_CANVAS, MakePoint(0, 94), // x-axisMakePoint(188,94));

CanvasDrawLine (panelAnal, OPEN_CANVAS, MakePoint(94, 0),MakePoint(94,188));

for(j = 0; j < cols; j++) { // graphs

MaxMin1D (dat[j], rows, &max[j], &maxi[j], &min[j], &mini[j]);Scale1D (dat[j], rows, dat[j], &offset[j], &scale[j]);LinEv1D (dat[j], rows, 50, 50 + j*100, dat[j]);

ploth[j] = PlotY (panelAnal, OPEN_GRAPH, dat[j], rows, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);

ctrlID[j] = NewCtrl (panelAnal, CTRL_NUMERIC, "Max", 356 - j*63 , 680); //maxctrlID[6+j] = NewCtrl (panelAnal, CTRL_NUMERIC, "Min",386 - j*63 , 680); //max

SetCtrlAttribute (panelAnal, ctrlID[j], ATTR_LABEL_LEFT, 650);SetCtrlAttribute (panelAnal, ctrlID[j], ATTR_LABEL_TOP, 356 - j*63);SetCtrlAttribute (panelAnal, ctrlID[j], ATTR_CTRL_MODE, VAL_INDICATOR);

SetCtrlAttribute (panelAnal, ctrlID[j+6], ATTR_LABEL_LEFT, 650);SetCtrlAttribute (panelAnal, ctrlID[j+6], ATTR_LABEL_TOP, 386 - j*63);SetCtrlAttribute (panelAnal, ctrlID[j+6], ATTR_CTRL_MODE, VAL_INDICATOR);

SetCtrlVal(panelAnal, ctrlID[j], max[j]);

SetCtrlVal(panelAnal, ctrlID[6+j], min[j]);}

for(j = 0; j < cols; j++) free(dat[j]);free(vel[0]); free(vel[1]);

}

return err;} // end of AnalysBal()

Appendix B. Eigenvectors of a symmetric 2 ×××× 2 matrix. In the above algorithm we need theeigenvectors and eigenvalues of a symmetric 2 by 2 matrix (computed by the functionSymEigenValueVector() above). First the eigenvalues of the symmetric matrix C (cxy = cyx) are

F Borg Bioproject, Chydenius Institute, Finland.

Page 8: The Confidence 95 Ellipse - University of Delaware of... · The Confidence 95 Ellipse Introduction. Important parameters in posturogram analysis are derived from the 95 % confidence

conf95.sdw 2/4/02 8/8

determined by the solutions to

(10) |cxx�λ cxy

cyx c yy�λ|=0

which are

(11) λ±=

cxx+cyy

2± cxy

2+(cxx�cyy

2 )2

The eigenvectors v are solutions of

(12) (cxx�λ cxy

cyx cyy�λ)(vx

vy)=0

Thus

(13)vy

vx=

cxx�λ

�cxy

and the orthonormal eigenvectors are therefore given by ( cxy ≠ 0)

(14)e±±±±=

1

1+(cxx�λ±

cxy)

2(1

�cxx�λ

±

cxy)

The angle of inclination (visavis the x-axis) φ is finally determined from

(15)cos(φ)=

1

1+(cxx�λ+

cxy)

2

In order to draw the Conf95 ellipse we can use the parametric representation (0 ≤ u < 2 π)

(16) r (u)=cos(u) 5.991σ 0 e0+sin (u) 5.991σ 1 e1

F Borg Bioproject, Chydenius Institute, Finland.