I’m running a distribution fitting analysis to my data. I’m trying 5 different distributions and I’d like to store the results for each one in an array or matrix.
So I’m using the fitdist function of the fitdistrplus package and all goes well, but I don’t know how to save each result. This is a newbie question but I’ve googled several times and no useful result came up.
Current code:
for loop
.....
params = fitdist( data, dist,method="mle")
print( params )
summary( params )
plot( params )
So I need something like:
for loop
.....
params = fitdist( data, dist,method="mle")
result1[i]<-print( params ) #Can I save a print (graphics)?
result2[i]<-summary( params )
result3[i]<-plot( params )
Thanks for the help.
(You should offer an example of how you are representing ‘data’ and ‘dist’.)
You need to predefine the result items because R will not automatically accept
resutl1[i]<-inside a loop ifresult1doesn’t already exist. This assumes that ‘data’ and ‘distr’ are lists or vectors of appropriate type forfitdistr. It’s possible that you may need to use “[[” instead of “[” (or a combination) in the arguments tofitdistr.You would access the result objects using
results[[i]]rather thanresults[i]since “[[” extracts the actual value in a list, whileresults[i]would give you a sublist with one element. If might be better (more compact and ultimately more flexible) to save just the ‘params’ objects to which you could later applysummary()andprint()as needed.