[R] fitting data
Ben Bolker
bolker at ufl.edu
Wed Jan 14 15:13:03 CET 2009
Serebrenik, A. <a.serebrenik <at> tue.nl> writes:
>
> Dear all,
>
> I have a set of data which seem to be distributed almost exponentially but
> only on [0;1]. I guess that the probability distribution in this case
> would look like
>
> \frac{lambda}{1-e^{-\lambda}) e^{-\lambda x}
>
> I would like to use fitdistr to estimate the value of \lambda.
>
> 1) Would it be correct first to find lambda for the
> exponential distribution and then to substitute it in the
> formula above?
That might be a decent starting value.
>
> 2) I guess that it should somehow be possible to
> convince fitdistr to use the function above, but I have no
> clue how.
>
The help for fitdistr says that "densfun" may be ...
" a function returning a density evaluated at its first argument".
In case that's opaque to you, that means something like
dmyfun <- function(x,lambda) {
(1-exp(-lambda))/lambda*exp(-lambda*x)
}
fitdistr(mydata,dmyfun,start)
[note: totally untested ...]
Ben Bolker
More information about the R-help
mailing list