Geoscience Reference
In-Depth Information
the data is
normfit
. To demonstrate the use of this function we i rst generate
100 synthetic Gaussian-distributed sets of values with a mean of 6.4 and a
standard deviation of 1.4.
clear
rng(0)
data = 6.4 + 1.4*randn(100,1);
We then dei ne the midpoints
v
of nine histogram intervals with the edges
e
,
display the results, and calculate the frequency distribution
n
.
e = 1.5 : 10.5;
h = histogram(data,e);
v = h.BinWidth * 0.5 + h.BinEdges(1:end-1);
n = h.Values;
h e function
normfit
yields estimates of the mean,
muhat
, and standard
deviation,
sigmahat
, of the normal distribution for the observations in
data
.
[muhat,sigmahat] = normfit(data)
muhat =
6.5723
sigmahat =
1.6274
h ese values for the mean and the standard deviation are similar to the
ones that we dei ned initially. We can now calculate the probability density
function of the normal distribution with the mean
muhat
and standard
deviation
sigmahat
, scale the resulting function
y
to same total number of
observations in
data
, and plot the result.
x = 2 : 1/20 : 10;
y = normpdf(x,muhat,sigmahat);
y = trapz(v,n) * y/trapz(x,y);
bar(v,n), hold on, plot(x,y,'r'), hold off
Alternatively, we can use the function
mle
to i t a normal distribution (and
also other distributions such as binomial or exponential distributions) to
the data. h e function
mle(data,'distribution',dist)
computes parameter
estimates for the distribution specii ed by
dist
. Acceptable strings for
dist
can be obtained by typing
help mle
.
phat = mle(data,'distribution','normal');
h e variable
phat
contains the values of the parameters describing the type of
distribution i tted to the data. As before, we can now calculate and scale the