I'm using the function fitdist of fitdistrplus package. For some distributions I get an error. I don't mind it I just want the program not to stop, and assign a value to a variable and proceed.
Based on the help i've got my code looks like:
i=1
for (data in results)
for (dist in distributions)
resultst[[i]] <- tryCatch(
fitdist( data, dist,method="mle",
start=list(mean=mapply("[[", results[i], 1),
sd=mapply("[[", results[i], 2)),
fix.arg=list(a=minv,b=maxv)),
error = function(e) results[[i]])
i=i+1
But get this error:
Error in resultst[[i]] <- tryCatch(fitdist(data, dist, method = "mle", :
more elements supplied than there are to replace
SOLUTION:
i=1
for (data in results)
for (dist in distributions)
params <- tryCatch(
fitdist( data, dist,method="mle",
start=list(mapply("[[", results[i], 1),
mapply("[[", results[i], 2)),
fix.arg=list(a=minv,b=maxv)),
error = function(e) {
fitdist( data, substring(dist,2),method="mle",
start=list(mapply("[[", results[i], 1),
mapply("[[", results[i], 2)))
})
resultst[i]<-params
resultst2[[i]]<-params
i=i+1
EDIT changed i=0 to i=1 (my mistake!) include params