Skip to content

Commit

Permalink
update for exponential distribution object
Browse files Browse the repository at this point in the history
  • Loading branch information
pr0m1th3as committed Feb 26, 2024
1 parent d6bee3c commit a9fa1c7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions INDEX
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Descriptive Statistics
trimmean
var
Distribution Classes
ExponentialDistribution
GammaDistribution
GeneralizedExtremeValueDistribution
GeneralizedParetoDistribution
Expand Down
30 changes: 26 additions & 4 deletions inst/dist_wrap/fitdist.m
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,16 @@
endif

case "exponential"
warning ("fitdist: 'Exponential' distribution not supported yet.");
if (isempty (groupvar))
varargout{1} = [];
varargout{1} = ExponentialDistribution.fit (x, alpha, censor, freq);
else
varargout{1} = [];
pd = ExponentialDistribution.fit ...
(x(g==1), alpha, censor(g==1), freq(g==1));
for i = 2:groups
pd(i) = ExponentialDistribution.fit ...
(x(g==i), alpha, censor(g==i), freq(g==i));
endfor
varargout{1} = pd;
varargout{2} = gn;
varargout{3} = gl;
endif
Expand Down Expand Up @@ -230,7 +235,8 @@

case {"generalizedpareto", "gp"}
if (any (x - theta < 0))
error ("fitdist: invalid THETA value for generalized Pareto distribution.");
error (strcat (["fitdist: invalid THETA value for generalized"], ...
[" Pareto distribution."]));
endif
if (isempty (groupvar))
varargout{1} = GeneralizedParetoDistribution.fit ...
Expand Down Expand Up @@ -473,6 +479,22 @@

## Test output
%!test
%! x = exprnd (1, 100, 1);
%! pd = fitdist (x, "exponential");
%! [muhat, muci] = expfit (x);
%! assert ([pd.mu], muhat);
%! assert (paramci (pd), muci);
%!test
%! x1 = exprnd (1, 100, 1);
%! x2 = exprnd (5, 100, 1);
%! pd = fitdist ([x1; x2], "exponential", "By", [ones(100,1); 2*ones(100,1)]);
%! [muhat, muci] = expfit (x1);
%! assert ([pd(1).mu], muhat);
%! assert (paramci (pd(1)), muci);
%! [phat, pci] = expfit (x2);
%! assert ([pd(2).mu], muhat);
%! assert (paramci (pd(2)), muci);
%!test
%! x = gamrnd (1, 1, 100, 1);
%! pd = fitdist (x, "Gamma");
%! [phat, pci] = gamfit (x);
Expand Down
11 changes: 9 additions & 2 deletions inst/dist_wrap/makedist.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
pd = [];

case "exponential"
mu = 0;
mu = 1;
while (numel (varargin) > 0)
switch (tolower (varargin{1}))
case "mu"
Expand All @@ -147,7 +147,7 @@
endswitch
varargin([1:2]) = [];
endwhile
pd = [];
pd = ExponentialDistribution (mu);

case "gamma"
a = 1;
Expand Down Expand Up @@ -532,6 +532,13 @@

## Test output
%!test
%! pd = makedist ("exponential");
%! assert (class (pd), "ExponentialDistribution");
%! assert (pd.mu, 1);
%!test
%! pd = makedist ("exponential", "mu", 5);
%! assert (pd.mu, 5);
%!test
%! pd = makedist ("gamma");
%! assert (class (pd), "GammaDistribution");
%! assert (pd.a, 1);
Expand Down

0 comments on commit a9fa1c7

Please sign in to comment.