Skip to content

SOCR Interactive (RShiny) Probability Distribution Calculators

Notifications You must be signed in to change notification settings

SOCR/ProbDistCalc_RShiny

Repository files navigation

RShiny Probability Distribution Calculator/Modeler

Calculator Image Modeler Image

Overview

The SOCR RShiny probability distribution calculators provide interactive vizualizations of probability densities, mass functions, and cumulative distributions, e.g., bivariate normal distribution.

The most current version is V0.9, deployed at here. The release can be find here.

Team

SOCR Team including Ivo D. Dinov, Jared Chai, and others.

Code Structure

The code is organized as follows:

  • ui.R and server.R are the main files for the RShiny app.
  • global.R contains the global variables and functions.
  • dataset.R contains the initialization and pre-processing of the dataset.
  • fitFunctions.R contains the functions for fitting the distribution in modeler.
  • distributionInfo.R contains the functions for getting the distribution information. The information is stored in distribution_info.yaml.
  • plotlyFunctions/*.R contain the functions for plotting distributions.
  • renderMainPlot.R contains the functions for rendering the main plot.
  • renderProbabilitt.R contains the functions for rendering the probabilities calculated.

Other files are mostly for testing and debugging and less important.

Guidelines for Future Development

  • Using RStudio is the easiest way to develop and the app almost out-of-box. However, if you want to use other IDEs like VSCode, use renv to manage the packages. The renv.lock file is already included in the repo. To install the packages, run renv::restore() in the R console. You may need to install other dependencies manually to install the packages, if there's error message saying so.

  • To support a new distribution:

    • Add the distribution information in distribution_info.yaml. Note that the fitFunc field indicates the function for fitting the distribution in modeler, and the plotlyFunc field indicates the function for plotting the distribution in calculator.
    • This distribution will be read by functions in distributionInfo.R into a list of type distributionInfoClass.
    • Then the corresponding distributionInfo object will be included in the distributionInfoList in global.R.
    • Add corresponding functions in plotlyFunctions/*.R for plotting the distribution in calculator, and add functions in fitFunctions.R for fitting the distribution in modeler.
  • To support more existing distributions in modeler:

    • Implement the corresponding fitting function in fitFunctions.R.
    • That's it! The distribution will be automatically supported by the modeler.

Acknowledgments

This work is supported in part by NIH grants P20 NR015331, UL1TR002240, P30 DK089503, UL1TR002240, and NSF grants 1916425, 1734853, 1636840, 1416953, 0716055 and 1023115. Students, trainees, scholars, and researchers from SOCR, BDDS, MIDAS, MICHR, and the broad R-statistical computing community have contributed ideas, code, and support.

References

TODO

  • Sample finished to-do item.
  • There should be histogram indicating the original dataset along with the distribution curve plot. Part of the code is already in the branch sub, but it only works for the normal distribution. Need to generalize it.
  • To generalize the histogram, we may need to extract the similar code in plotlyFunctions into a separate function. Otherwise we have to repeat the code for histogram 70+ times for each distribution. Currently the code is mostly duplicated but slightly different in these functions, which makes it very hard to extract the common code.
  • Deploy to SOCR server. Update the LINK_NEEDED in this README.
  • Support more existing distributions in modeler. Currently only very few distributions are supported in modeler. To do this, follow the guidelines in the section above.