Different Methods of Calculating Body Sway Area Thomas Wollseifen Brighton (UK), 9th-12th October 2011 1 Posturography Postural instability Parkinson‘s disease Sleeping problems Elderly subjects Centre of pressure Subject=7 7 6 5 4 3 2 Y [cm] 1 0 -1 -2 -3 -4 -5 -6 -7 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 Body sway Length of path Velocity Distribution Body sway area X [cm] Body sway path - trajectory Copyright © 2011 i3 | CONFIDENTIAL 2 How to calculate the body sway area? 1) Area of convex hull 2) Area of ellipse – Principal component analysis (PCA) 3) Mean of circle areas Copyright © 2011 i3 | CONFIDENTIAL 3 1) Convex hull Convex hull Subject=7 Subject=7 7 7 6 6 5 5 4 4 3 3 2 Y [cm] 1 0 -1 convex not convex -2 -3 -3 -4 -4 -5 -5 -6 -6 Different algorithms: -7 -7 -7 -7 Gift wrapping algorithm Triangulation etc. Copyright © 2011 i3 | CONFIDENTIAL -6 -6 -5 -5 -4 -4 -3 -3 -2 -2 -1 -1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 X [cm] X [cm] 4 Convex hull - Algorithm Convex hull Subject=7 7 1) Triangulation of a point set (PROC G3GRID) 6 5 4 3 proc g3grid data=_ch00 outtri=_ch01 triangulation of data set out=_temp; grid &y.*&x.=&z.; run; 2 Y [cm] 1 0 -1 -2 -3 -4 -5 -6 -7 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 X [cm] 2) Calculation of the determinant (of the convex hull = Area) x y 1 1 x y 2 2 1 1 Area x y x y x y xn y y x y x y x yn x 1 1 2 2 3 3 4 1 Convex hull 2 2 1 2 2 3 3 4 xn yn x y 1 1 Copyright © 2011 i3 | CONFIDENTIAL 5 Find the area of this (convex) polygon determinant (2,5) 7 6 5 4 (-4,3) 3 2 (5,1) Y [cm] 1 0 -1 -2 2 5 1 4 3 1 Area 6 (4) 25 20 15 2 15 2 5 1 2 2 5 -3 -4 -5 -6 -7 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 X [cm] data _det01; set &indata.; x2=lag(&x.); y2=lag(&y.); if not missing(x2) then d1=x2*&y.; else d1=0; if not missing(y2) then d2=y2*&x.; else d2=0; run; Copyright © 2011 i3 | CONFIDENTIAL proc sql; create table _det02 as select * ,sum(d1) as sumd1 ,sum(d2) as sumd2 ,(calc. sumd2 – calc. sumd1)*0.5, as det from _det01 ; quit; 6 A PCA | e1 | | e2 | 7 7 6 6 5 5 4 4 3 3 2 2 Find a „better“ bounding box! 1 0 -1 -2 -3 e‘2 1 Y [cm] Y [cm] 2) Principal component analysis (PCA) 0 e‘1 -1 -2 -3 -4 PCA -5 -6 -4 -5 -6 -7 -7 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 X [cm] X [cm] Idea: Reduce dimensionality of a point set by identifying the most significant directions (Principal components = Eigenvectors) Copyright © 2011 i3 | CONFIDENTIAL 7 Principal component analysis with PROC PRINCOMP proc princomp data=_pca01 COV OUT = _prins; var &y. &x.; ods output eigenvectors=_eigenvectors eigenvalues=_eigenvalues; run; Covariance Matrix y X Y 4.526000000 -2.408333333 X -2.408333333 5.195833333 Cov(y,y) Cov(y,x) Cov(x,y) Cov(x,x) Eigenvalues of the Covariance Matrix Eigenvalue 1 7.29242620 2 Copyright ©2.42940713 2011 i3 | CONFIDENTIAL Difference 4.86301907 Proportion Cumulative 0.7501 0.7501 0.2499 1.0000 8 From covariance matrix to Eigenvectors / Eigenvalues Calculate 2x2 covariances cov(X,Y) of X,Y: 1 n cov( X , Y ) ( xi x )( yi y ) n 1 i 1 Prepare covariance matrix: Cov-Matrix Cov(y,y) Y X Cov(y,x) Y 4.53 -2.41 Cov(x,y) Cov(x,x) x -2.41 5.20 Calculate Eigenvalues and Eigenvectors of the covariance matrix: 4.53 2.41 det( A E ) 0 2.41 5.20 0 Eigenvalue1 Eigenvalue2 Copyright © 2011 i3 | CONFIDENTIAL 7.29 2.42 Eigenvector e1 Eigenvector e2 x y (0.75, -0.66) (0.66, 0.75) 9 Find a bounding box - Algorithm 2. – 6. Subject=7 7 7 7 6 Tranform & rotate 5 6 centroid 4 2 Y [cm] 1 0 -1 5 4 3 3 2 2 1 1 Y [cm] 3 0 -1 -2 -2 -2 -3 -3 -3 -4 -4 -4 -5 -5 -5 -6 -6 -6 -7 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 X [cm] |e‘1|=4.57 0 -1 -7 |e‘2| =2.78 6 Rotate box 5 4 Y [cm] 7. -7 -7 -6 -5 -4 -3 -2 -1 0 X [cm] 1 2 3 4 5 6 7 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 X [cm] 1. Calculate eigenvalues and eigenvectors e1 and e2 of covariance matrix (PROC PRINCOMP) 2. 3. 4. 5. 6. Calculate centroid of the point set Translate point set such that the centroid is moved to the origin Transform point set into polar coordinates (with angle and radius r) Rotate point set by angle of the 1st eigenvector Calculate the bounding box and the length of the eigenvectors e’1 and e’2 Re-rotate bounding box by ange of the 1st eigenvector Copyright © 2011 i3 | CONFIDENTIAL 7. AreaPCA= | e1 | | e2 | 10 3) Mean circle area - Algorithm Subject=7 7 1. Transformation into polar coordinates (r,) 2. Calculate the integer (INT) of each angle for each data point 3. Calculate max radius r for each angle (360 different angles possible) 4. For each remaining data point p‘ (r, ) calculate the circle area 5. Am= ·r² 6 5 4 3 2 Y [cm] 1 0 -1 -2 -3 -4 -5 -6 -7 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 1.-4. 4 5 6 7 X [cm] Mean circle area Subject=7 7 A1= ·r² ... ... A14= ·r² 6 5 4 3 2 Y [cm] 1 0 -1 -2 -3 -4 -5 area=37.10 -6 -7 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 5. X [cm] Mean circle area Subject=7 7 6 5 4 3 Am= ·r² 2 Y [cm] 1 0 -1 -2 -3 -4 -5 Copyright © 2011 i3 | CONFIDENTIAL 11 -6 -7 -7 -6 -5 -4 -3 -2 -1 0 X [cm] 1 2 3 4 5 6 7 Mean circle area – Simple example Mean circle sum usubjid=1 Mean circle sum usubjid=1 7 7 6 6 5 5 4 4 3 40.8 3 2 2 1 15.7 0 Y [cm] Y [cm] 1 0 -1 0 24.5 -1 -2 -2 -3 -3 -4 -4 -5 -5 41.6 -6 -7 -7 -6 -5 -4 -3 -2 -1 0 1 2 area=24.54 3 -6 -7 4 5 6 7 -7 -6 -5 -4 -3 -2 -1 X [cm] Polar coordinates max_r 0 1 2 3 4 5 6 7 X [cm] x y r theta Circle Area pi n area_i mean_area 0 0 0 0 0 3,141593 4 0 24,54 3,61 2 3 3,61 56 3,141593 4 40,84 24,54 2,24 -2 1 2,24 153 3,141593 4 15,71 24,54 3,64 1 -3,5 3,64 285 3,141593 4 41,63 24,54 Copyright © 2011 i3 | CONFIDENTIAL 12 Comparison of methods Convex hull PCA method PCA ellipse Subject=7 Convex hull Subject=7 Mean circle area Subject=7 7 7 6 6 6 5 5 5 4 4 4 3 3 3 2 2 2 1 1 1 0 Y [cm] 7 Y [cm] Y [cm] Circle method 0 0 -1 -1 -1 -2 -2 -2 -3 -3 -3 -4 -4 -4 -5 -5 -5 -6 -6 -6 -7 -7 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 X [cm] ACH=26.2 [cm²] Copyright © 2011 i3 | CONFIDENTIAL 6 7 -7 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 X [cm] APCA=39.9 [cm²] -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 X [cm] ACM=37.1 [cm²] 13 Comparison of methods - different distributions Convex hull PCA method Subject=8 7 6 6 6 5 5 5 4 4 4 3 3 3 2 2 2 1 1 1 0 Y [cm] 7 0 -1 -1 -2 -2 -2 -3 -3 -3 -4 -4 -4 -5 -5 -5 -6 -6 -6 -7 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 -7 -7 7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 -7 ACH=8.8 5 4 4 4 3 3 3 2 2 2 1 1 1 0 Y [cm] 6 5 Y [cm] 6 5 0 -1 -1 -2 -2 -2 -3 -3 -3 -4 -4 -4 -5 -5 -5 -6 -6 -6 -7 -7 -1 0 1 2 X [cm] ACH=3.1 Copyright © 2011 i3 | CONFIDENTIAL 3 4 5 6 7 0 1 2 3 4 5 6 7 5 6 7 0 -1 -2 -1 Subject=7 6 -3 -2 ACM=3.6 7 -4 -3 Subject=7 7 -5 -4 X [cm] 7 -6 -5 APCA=11.7 Subject=7 -7 -6 X [cm] X [cm] Y [cm] 0 -1 -7 „Flat data“ Subject=8 7 Y [cm] Y [cm] Subject=8 Normally distributed data Circle method -7 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 X [cm] APCA=3.7 6 7 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 X [cm] ACM=11.1 14 Comparison of methods – different test data Test data Calculation Method N Mean Std min max test01 1 Convex hull 10 1.78 1.22 0.1 3.3 0.1 3.9 test02 test03 test04 2 PCA ellipse 10 2.08 1.44 3 Mean circle 10 13.88 5.65 11.1 29.6 1 Convex hull 10 3.58 2.45 0.3 6.7 0.4 7.8 2 PCA ellipse 10 4.16 2.84 3 Mean circle 10 11.85 2.66 10.1 18.7 1 Convex hull 10 5.36 3.68 0.4 10.0 0.5 11.6 2 PCA ellipse 10 6.23 4.25 3 Mean circle 10 11.30 1.54 10.0 14.5 1 Convex hull 10 8.93 6.16 0.6 16.7 0.7 19.3 10.1 12.9 2 PCA ellipse 10 10.33 7.12 3 Mean circle 10 11.11 0.95 Copyright © 2011 i3 | CONFIDENTIAL Pairwise comparison p-value F-test Normal Distr.? 1-2: 0.9789 1-3:<0.0001 2-3:<0.0001 <0.0001 No 1-2: 0.8785 1-3:<0.0001 2-3:<0.0001 <0.0001 Yes 1-2: 0.8329 1-3: 0.0014 2-3: 0.0062 0.0010 No 1-2: 0.8367 1-3: 0.6492 2-3: 0.9444 0.6683 Yes 15 Summary Convex hull Areaconvex hull < AreaPCA Convex hull Subject=7 7 6 5 4 3 1 Y [cm] Good approximation of the body sway area Data independent Encloses all data points 2 0 -1 -2 -3 -4 -5 -6 -7 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 1 2 3 4 5 6 7 X [cm] Magnitude and direction Data independent Comparable result as convex hull Not all data points area enclosed 6 5 4 3 2 1 Y [cm] PCA ellipse PCA ellipse Subject=7 7 0 -1 -2 -3 -4 -5 -6 -7 -7 -- Fast algorithm Crude approximation of the sway area Depends on data distribution Not all data points area enclosed -5 -4 -3 -2 -1 0 4 5 6 7 X [cm] Mean circle area Subject=7 7 6 5 4 3 2 1 Y [cm] Circle method -6 0 -1 -2 -3 -4 -5 -6 -7 -7 Copyright © 2011 i3 | CONFIDENTIAL -6 -5 -4 -3 -2 -1 0 X [cm] 1 2 3 4 5 6 7 16 Questions &Answers Contact details PharmaNet / i3 Thomas.Wollseifen@i3global.com Taunusstrasse 9 65183 Wiesbaden Germany Copyright © 2011 i3 | CONFIDENTIAL 17