[R] Determining model parameters
rkevinburton at charter.net
rkevinburton at charter.net
Thu Aug 7 20:20:56 CEST 2008
I am trying to fit a set of data to a Weibull distribution. Because the implementation requires that I put the data in the range of 0 < x < 1 I have a "normailze" function:
normalize <- function(x) {
y <- (x-min(x)) / (max(x) - min(x))
y = y + 0.5 * (y == 0) -0.5 * (y == 1)
return (y)
}
So the output to this normalize function is:
normalize(c(93,34,16,120,53,75))
[1] 0.7403846 0.1730769 0.5000000 0.5000000 0.3557692 0.5673077
If I calculate the model parameters by hand (basically through a line fit) I get:
$shape
[1] 2.022953
$scale
[1] 0.5528019
$r
[1] 0.9661575
When I run fitdistr I get:
fitdistr(normalize(c(93,34,16,120,53,75)), "weibull")
shape scale
3.02746335 0.52969005
(1.01520182) (0.07482737)
Warning messages:
1: In dweibull(x, shape, scale, log) : NaNs produced
2: In dweibull(x, shape, scale, log) : NaNs produced
My first concern is the warnings. Why are the NaNs produced? Next is that values produced. I have used my "manual" method for some time now and I think it produces an accurate fit. The numbers produced by fitdistr are of the same order but they are still different than I would expect. So the combination of the warnings and the questionable response doesn't inspire my confidence. Am I doing something wrong?
Thank you.
Kevin
---- Ben Bolker <bolker at ufl.edu> wrote:
>
> ~ The beta distribution only applies to data that are bounded
> between 0 and 1 (in some cases strictly bounded, i.e. 0<x<1 not
> just 0<=x<=1).
>
> ~ As a start, try something like
>
> d2 = (Diff-min(Diff)+0.001)/(max(Diff)-min(Diff)+0.002)
> fitdistr(d2,densfun="beta",start=list(shape1=3,shape2=2))
>
> ~ [cc'ing back to R-help for posterity ...]
>
> ~ Ben Bolker
>
> rkevinburton at charter.net wrote:
> | OK. I see in the documentation that "start" is required for certain
> distributions. Now I get:
> |
> | fitdistr(Diff, densfun="beta", list(shape1=3,shape2=2))
> | Error in optim(x = c(0, 516, 968, 703, 960, 32, 956, 1417, -92, 471,
> 531, :
> | initial value in 'vmmin' is not finite
> |
> | Any idea what vmmin is? And what the cause of the error is?
> |
> | Thanks again.
> |
> | Kevin
> | ---- Ben Bolker <bolker at ufl.edu> wrote:
> |> <rkevinburton <at> charter.net> writes:
> |>
> |>> If I have some data that based on the historgram and other plots it
> "looks"
> |> like a beta distribution. Is there
> |>> a function or functions within R to help me determine the model
> parameters for
> |> such a distirbution?
> |>
> |>
> |> library(MASS)
> |> ?fitdistr
> |>
More information about the R-help
mailing list