Function Reference: hnfit

statistics: paramhat = hnfit (x, mu)
statistics: [paramhat, paramci] = hnfit (x, mu)
statistics: [paramhat, paramci] = hnfit (x, mu, alpha)

Estimate parameters and confidence intervals for the half-normal distribution.

paramhat = hnfit (x) returns the maximum likelihood estimates of the parameters of the half-normal distribution given the data in vector x. paramhat(1) is the location parameter, mu, and paramhat(2) is the scale parameter, sigma. Although mu is returned in the estimated paramhat, hnfit does not estimate the location parameter mu, and it must be assumed to be known.

[paramhat, paramci] = hnfit (x, mu) returns the 95% confidence intervals for the estimated scale parameter sigma. The first colummn of paramci includes the location parameter mu without any confidence bounds.

[…] = hnfit (x, alpha) also returns the 100 * (1 - alpha) percent confidence intervals of the estimated scale parameter. By default, the optional argument alpha is 0.05 corresponding to 95% confidence intervals.

The half-normal CDF is only defined for x >= mu.

Further information about the half-normal distribution can be found at https://en.wikipedia.org/wiki/Half-normal_distribution

See also: hncdf, hninv, hnpdf, hnrnd, hnlike

Source Code: hnfit

Example: 1

 

 ## Sample 2 populations from different half-normal distibutions
 rand ("seed", 1);   # for reproducibility
 r1 = hnrnd (0, 5, 5000, 1);
 rand ("seed", 2);   # for reproducibility
 r2 = hnrnd (0, 2, 5000, 1);
 r = [r1, r2];

 ## Plot them normalized and fix their colors
 hist (r, [0.5:20], 1);
 h = findobj (gca, "Type", "patch");
 set (h(1), "facecolor", "c");
 set (h(2), "facecolor", "g");
 hold on

 ## Estimate their shape parameters
 mu_sigmaA = hnfit (r(:,1), 0);
 mu_sigmaB = hnfit (r(:,2), 0);

 ## Plot their estimated PDFs
 x = [0:0.2:10];
 y = hnpdf (x, mu_sigmaA(1), mu_sigmaA(2));
 plot (x, y, "-pr");
 y = hnpdf (x, mu_sigmaB(1), mu_sigmaB(2));
 plot (x, y, "-sg");
 xlim ([0, 10])
 ylim ([0, 0.5])
 legend ({"Normalized HIST of sample 1 with μ=0 and σ=5", ...
          "Normalized HIST of sample 2 with μ=0 and σ=2", ...
          sprintf("PDF for sample 1 with estimated μ=%0.2f and σ=%0.2f", ...
                  mu_sigmaA(1), mu_sigmaA(2)), ...
          sprintf("PDF for sample 2 with estimated μ=%0.2f and σ=%0.2f", ...
                  mu_sigmaB(1), mu_sigmaB(2))})
 title ("Two population samples from different half-normal distibutions")
 hold off

                    
plotted figure