0

If I fit a uni-variate data with normal distribution, how can i get back the fitted values in MATLAB. I am using this simple example

load hospital % data
x = hospital.Weight;
[mu sigma]=normfit(x) %normal fitting
%To visualize the pdf
xval=min(x):0.1:max(x)
yval=normpdf(xval,mu,sigma)
plot(xval,yval)

yval is giving the probabilities of xval values. Now, If I would like to extract the fitted values of 'x' after approximating it with the above normal distribution, how do I do that?. As can be seen in the picture the y-axis values are the pdf and lies between 0 and 1, however I want the corresponding fitted values from the data that follows normal distribution.

Would the fitted values be x_fitted = yval*sigma + mu? !I think I am missing some basic maths here.

Stewie Griffin
  • 14,889
  • 11
  • 39
  • 70
Shehroz
  • 347
  • 2
  • 9
  • 25

1 Answers1

1

normfit simply gives you the mu and sigma of the fitted normal pdf. From those you build that pdf with normpdf. So the desired y values for your input x would be

y = normpdf(x,mu,sigma)

which you could plot with

hold on
plot(x,y,'ro')

enter image description here

Note that, with this procedure, the data lie exactly on the normal pdf, even if those data do not actually follow a normal distribution.

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
  • Thanks. The values of y is in the range of [0,1] because it is probability, how can we translate them so it can have magnitude corresponding original data x? In my above example mu=154 and sigma=26.57 but 0<=y<=1 – Shehroz Nov 06 '13 at 12:28
  • 1
    You already have tha magnitude of the original data. I don't see how you could obtain another magnitude for the fitted data, if that's what you want; I'm not really sure it would even make sense – Luis Mendo Nov 06 '13 at 13:01