Clear Filters
Clear Filters

Polyfitn Function calculate the RMS value

3 views (last 30 days)
When I use 'polyfitn' function to fit 3D data, should I use 'polyvaln' function and calculate the RMS error? OR Can I directly consider the RMSE value from the function 'polyfitn' to be the RMS error. In both the cases, the values are different. But for all the cases I checked, the minima occurs at the same point for both the values. Is it safe to consider RMSE value?

Accepted Answer

John D'Errico
John D'Errico on 22 Oct 2016
Edited: John D'Errico on 22 Oct 2016
You can find the formula for RMSE easily enough. Here for example:
https://en.wikipedia.org/wiki/Root-mean-square_deviation
It is simply the sqrt of the mean of the squares of the errors, which is what polyfitn computes, as you can see:
polymodel.RMSE = sqrt(mean((depvar - yhat).^2));
So, you may have chosen a different formula for RMSE. I suppose there are others one might define, but the one in polyfitn is what seems to be standard.
I have no idea what you are asking about if it is safe to use the RMSE that polyfitn returns.
As a simple test:
M = rand(10,3);
y = rand(10,1)*10 + 10;
P = polyfitn(M,y,1);
pred = polyvaln(P,M);
sqrt(mean((pred - y).^2))
ans =
1.9747
P.RMSE
ans =
1.9747
I'm not sure what form you might have chosen here otherwise.
  1 Comment
jupiter
jupiter on 24 Oct 2016
Thank you John, while I was also doing the same thing but calculating the sum and then dividing it by the number of elements (Old school way :)), only a factor of cube at the denominator was causing the difference in the result. Now everything is working fine.

Sign in to comment.

More Answers (0)

Categories

Find more on Chemistry 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!