I have the following data
dat<-c(16.254884, 14.077510, 12.851675, 19.152597, 11.511230,
16.122911, 16.099962, 9.670949, 12.523661, 15.257432, 13.603848,
14.118873, 12.632340, 15.413753, 5.426383, 11.369880, 12.895920,
13.635134, 15.118388,13.154107, 8.913164, 17.302810, 14.968054,
16.200151, 16.068944, 18.571952, 15.247535, 15.018281)
I am using this code to find the mode:
Mode_fc <- function(x) {
ux <- unique(x)
ux[which.max(tabulate(match(x, ux)))]
}
Using MyParam
, I am able to get the min, max and mode
MyParam <- c(min= min(dat), max= max(dat), mode= Mode_fc(dat))
When I enter these values into the code below fitdist
works as expected
fitdist(dat, "triang", start = list(min=5.4, max=19.2, mode=16.3))
But, when I try to read in MyParam I get all sorts of errors
fitdist(dat, "triang",
start = list(min=MyParam[[1]], max=MyParam[[2]], mode=MyParam[[3]]))
I know the issue is with optim()
, but I have not been able to figure out how to fix this problem. Any suggestions are appreciated!.