I would like to export the following mixture distribution mathematica found for my dataset to .json file

dis = FindDistribution[selection]

  {LogisticDistribution[19.2103, 0.155169],
   CauchyDistribution[23.5492, 2.24062]

I tried to look into the documentation available on Mathematica on Export .json here what I did:

  {"MixtureDistribution" -> {"Weight"-> {0.8744, 0.1255}},
   "LogisticDistribution"-> {"Parameter"-> 19.2103,0.1551}},
    "CauchyDistribution" -> {"Parameter"-> {23.5492, 2.2406}}

It created .json file, but what i need is not to write manually the distribution and parameters, instead i would like to have these parameters and distribution to be automatically found in .json file.

I hope I am clear. Will be looking forward for the answers.

up vote 2 down vote accepted

Perhaps this is what you're looking for:

fun[MixtureDistribution[w_, dists_]] :=
    Cases[dists, d_[p___] :> ToString[d] -> {"Parameter" -> {p}}], 
    "MixtureDistribution" -> {"Weight" -> w}

md = MixtureDistribution[
      {LogisticDistribution[19.2103, 0.155169],
       CauchyDistribution[23.5492, 2.24062]}

fun[md] --> 
        {"MixtureDistribution" -> {"Weight" -> {0.874492, 0.125508}}, 
         "LogisticDistribution" -> {"Parameter" -> {19.2103, 0.155169}}, 
         "CauchyDistribution" -> {"Parameter" -> {23.5492, 2.24062}}}

You can then export this result.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.