The problem is that fitdistr does not limit the shape and scale to positive.
library(MASS) set.seed(0) x <- rbeta(1000, shape1=1, shape2=1) f1 <- fitdistr(x, dbeta, list(shape1=1,shape2=1))
As a rule, itβs not a problem if the optimization algorithm tries to get some invalid parameter values ββon the way to a possible solution that is not on the border, but I agree that it is better to avoid warnings where possible.
You can define the lower bounds yourself:
...: Additional parameters, both for "densfun" and for "optim". In particular, it can be used to indicate boundaries through βlowerβ or βupperβ or both.
f2 <- fitdistr(x, dbeta, list(shape1=1,shape2=1), lower=c(0,0))
(no warnings). The answers are not exactly identical, but they are very close (this should be expected from the results of numerical optimization).
all.equal(coef(f1),coef(f2),tol=1e-6)
source share