MSE between a set of data points (x,y) and a defined line
22 views (last 30 days)
Show older comments
Hi all,
I'm a psychologist and i'm totally new to Matlab. I'm trying to reproduce an analysis reported in a scietific paper where the researcher compared a curve drawn by participants with an ideal straight line using a formula representing the square of the root mean square (in the attachment the piece of the paper where the analysis is reported).
What i have now is a series of coordinates (a file .dat) divided in two columns (X,Y), representing what the subject has drawn (actual trajectory) with the mouse and i also have the two points where the ideal trajectory should be.
From the formula I understood that the RMS should be computed based on the defined integral (defined by the last X of the subject and the first X of the movement done by participant) of the square of the subtraction between the two functions (actual and ideal). My main problem is that i don't know what should i put as the argument of the integral (what should i subtract). Their results of the formula are always oscillating between 0.0001 and 0.05.
I've tried a simple piece of code (below) where i tried to subtract the integrals of the two curves (i guess basically subtracting the areas) but i really don't think is what i should be doing here.
Thank you in advance for your help,
Alessandro
% % % % % % % % % %
% Lines comparisons%
% % % % % % % % % %
load my_xy.dat; % read actual trajectory data into the my_xy matrix
Xr = my_xy(:,1); % copy first column of my_xy into Xr(eal)
Yr = my_xy(:,2); % copy second column of my_xy into Yr(eal)
Xd = my_xy (:,3);
Yd = my_xy (:,4);
Xc = [0.0,503.46];% Xc(orrect) ideal line x coordinates
Yc = [-352,151.46];% Yc(orrect) ideal line y coordinates
plot(Xr,Yr,'--',Xc,Yc); % plot actual trajectory and ideal trajectory
% 1) trying to replicate the formula but not succeding
MSE = ((trapz(Xr,Yr)-trapz(Xc,Yc)).^2)/(Xr(end)-Xr(1));
3 Comments
Star Strider
on 23 Jul 2014
‘(in the attachment the piece of the paper where the analysis is reported)’
No attachment.
Is the method you want to implement described in the paper, or do you have a specific analysis method in mind? It is not clear (at least to me) what you want to do.
Answers (4)
Roger Stafford
on 23 Jul 2014
Before you carry out your integration it is necessary to establish the y-values for your ideal straight line at the corresponding x-values of the participant data. If this ideal line is defined as passing through the two points (0.0,-352) and (503.46,151.46), then its equation is:
y = -352 + (151.46-(-352))/((503.46-0.0)*(x-0.0)
You called the x-values of the participant Xr and the participant y-values Yr. The ideal y-values at the corresponding points would therefore be:
Yc = -352 + (151.46-(-352))/((503.46-0.0)*(Xr-0.0)
To obtain the trapezoidal approximation to the integral you described, it would be computed by:
a2 = trapz(Xr,(Yr-Yc).^2)/(Xr(end)-Xr(1));
This is the mean square error. To get the root mean square error, take its square root.
0 Comments
Star Strider
on 23 Jul 2014
The integral you posted is actually the Mean Square Error (MSE), not the RootMean Square Error (RMS, RMSE) which is the square root of the MSE.
While I was waiting for clarification, I coded the following code snippet:
Xc = [0.0,503.46]; % Xc(orrect) ideal line x coordinates
Yc = [-352,151.46]; % Yc(orrect) ideal line y coordinates
Xr = [0.1 498]; % Created Data
Yr = [-360 150]; % Created Data
Bc = [Xc' [1;1]]\Yc'; % Slope and Intercept of the ‘Correct’ Line
Br = [Xr' [1;1]]\Yr'; % Slope and Intercept of the ‘Real’ Line
Yp = [Xc' [1;1]]*Br; % Projected Y-Coordinates of Yr w.r.t. Xc
Yd = Yc'-Yp; % Difference of Y-Values at the Same Xc Values
MSE = @(Q) mean(Q.^2); % Mean Square Error
RMS = @(Q) sqrt(mean(Q.^2)); % Root Mean Square Error
YdMSE = MSE(Yd)
YdRMS = RMS(Yd)
It takes beginning and ending points of both lines and calculates the slopes and intercepts of both in Bc and Br respectively. In order to get Y-values at common X-values ( Xc chosen for those ), it calculates projected coordinates of the Yr line based on Bc, as Yp. It then compares Yp and Yc as Yd and calculates the MSE and RMSE of Yd.
This seems to implement the idea in your attachment (at least as I read it), since it compares the differing Y-values at the same X-values.
0 Comments
Alessandro
on 24 Jul 2014
3 Comments
Star Strider
on 25 Jul 2014
Edited: Star Strider
on 25 Jul 2014
My pleasure!
In their Figure 2, they are clearly measuring the line length as 222 mm. Scaling your data to the same units should produce roughly the same results. Scaling it is probably as simple as measuring the screen and applying the appropriate scaling factor. I suggest you do this in both the horizontal and vertical directions to verify that the pixels are approximately square. If so, you need apply only one scaling factor of mm/pixel to get the same units as those in the paper.
See Also
Categories
Find more on Geometric Transformation and Image Registration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!