├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── README_ja.md ├── ShinyDistributionsApp.Rproj ├── components ├── functions.R └── modules.R ├── distributions ├── all.R ├── continuous │ ├── Beta.R │ ├── Cauchy.R │ ├── Chi-squared.R │ ├── Erlang.R │ ├── Exponential.R │ ├── F.R │ ├── Gamma.R │ ├── Log-normal.R │ ├── Logistic.R │ ├── Noncentral_F.R │ ├── Noncentral_beta.R │ ├── Noncentral_chi-squared.R │ ├── Noncentral_t.R │ ├── Normal.R │ ├── Uniform.R │ ├── Weibull.R │ └── t.R └── discrete │ ├── Binomial.R │ ├── Discrete_uniform.R │ ├── Geometric.R │ ├── Hypergeometric.R │ ├── Negative_binomial.R │ └── Poisson.R ├── doc ├── demo.png └── ja │ └── demo.png ├── docker-compose.yml ├── global.R ├── i18n ├── config.yaml ├── main.R └── translation_ja.csv ├── markdown ├── about.md └── about_ja.md ├── nvd3chart.R ├── rsconnect └── shinyapps.io │ └── ksmzn │ └── statdist.dcf ├── server.R ├── ui.R ├── utils ├── all.R └── bookmark.R └── www ├── css └── main.css ├── img └── external.png └── js ├── d3 └── d3.v3.min.js ├── google-analytics.js ├── linechart-binding.js ├── nvd3 ├── .gitignore ├── .jshintrc ├── GruntFile.js ├── LICENSE.md ├── Makefile ├── README.md ├── bower.json ├── build.bat ├── deprecated │ ├── bar.html │ ├── bar.js │ ├── charts │ │ ├── cumulativeLineChart.js │ │ ├── discreteBarChart.js │ │ ├── lineChart.js │ │ ├── lineChartDaily.js │ │ └── stackedAreaChart.js │ ├── cumulativeLine.html │ ├── cumulativeLine.js │ ├── discreteBarChartWithEnabledTooltip.html │ ├── discreteBarChartWithEnabledTooltip.js │ ├── discreteBarWithAxes.html │ ├── discreteBarWithAxes.js │ ├── lineChart-old.html │ ├── lineChartDaily.html │ ├── linePlusBar.html │ ├── linePlusBar.js │ ├── lineWithFocus.html │ ├── lineWithFocus.js │ ├── lineWithFourAxes.html │ ├── lineWithFourAxes.js │ ├── lineWithLegend.html │ ├── lineWithLegend.js │ ├── monthendAxis.html │ ├── multiBarHorizontalWithLegend.html │ ├── multiBarHorizontalWithLegend.js │ ├── multiBarWithLegend.html │ ├── multiBarWithLegend.js │ ├── pie.js │ ├── scatterChart.html │ ├── scatterChart.js │ ├── scatterFisheyeChart.js │ ├── scatterWithLegend.html │ ├── scatterWithLegend.js │ ├── stackedArea.js │ ├── stackedAreaChart.html │ ├── stackedAreaChart_old.html │ ├── stackedAreaWithLegend.html │ └── stackedAreaWithLegend.js ├── examples │ ├── bullet.html │ ├── bulletChart.html │ ├── crossfilter.html │ ├── crossfilterWithDimentions.html │ ├── crossfilterWithTables.html │ ├── cumulativeLineChart.html │ ├── discreteBarChart.html │ ├── historicalBar.html │ ├── historicalBarChart.html │ ├── horizon.html │ ├── images │ │ ├── grey-minus.png │ │ ├── grey-plus.png │ │ └── nvd3_sampleLineChart1.png │ ├── indentedtree.html │ ├── index.html │ ├── legend.html │ ├── line.html │ ├── lineChart.html │ ├── lineChartSVGResize.html │ ├── linePlusBarChart.html │ ├── linePlusBarWithFocusChart.html │ ├── lineWithFisheyeChart.html │ ├── lineWithFocusChart.html │ ├── multiBar.html │ ├── multiBarChart.html │ ├── multiBarHorizontalChart.html │ ├── multiChart.html │ ├── nations.json │ ├── parallelCoordinates.html │ ├── pie.html │ ├── pieChart.html │ ├── scatter.html │ ├── scatterChart.html │ ├── scatterPlusLineChart.html │ ├── sparkline.html │ ├── sparklinePlus.html │ ├── stackedArea.html │ ├── stackedAreaChart.html │ └── stream_layers.js ├── lib │ ├── cie.js │ ├── colorbrewer.js │ ├── crossfilter.js │ ├── crossfilter.min.js │ ├── d3.v2.js │ ├── d3.v2.min.js │ ├── d3.v3.js │ ├── fisheye.js │ ├── hive.js │ ├── horizon.js │ └── sankey.js ├── nv.d3.css ├── nv.d3.js ├── nv.d3.min.css ├── nv.d3.min.js ├── package.json ├── src │ ├── core.js │ ├── interactiveLayer.js │ ├── intro.js │ ├── models │ │ ├── axis.js │ │ ├── backup │ │ │ ├── bullet.js │ │ │ └── bulletChart.js │ │ ├── boilerplate.js │ │ ├── bullet.js │ │ ├── bulletChart.js │ │ ├── cumulativeLineChart.js │ │ ├── discreteBar.js │ │ ├── discreteBarChart.js │ │ ├── distribution.js │ │ ├── historicalBar.js │ │ ├── historicalBarChart.js │ │ ├── indentedTree.js │ │ ├── legend.js │ │ ├── line.js │ │ ├── lineChart.js │ │ ├── linePlusBarChart.js │ │ ├── linePlusBarWithFocusChart.js │ │ ├── lineWithFisheye.js │ │ ├── lineWithFisheyeChart.js │ │ ├── lineWithFocusChart.js │ │ ├── multiBar.js │ │ ├── multiBarChart.js │ │ ├── multiBarHorizontal.js │ │ ├── multiBarHorizontalChart.js │ │ ├── multiBarTimeSeries.js │ │ ├── multiBarTimeSeriesChart.js │ │ ├── multiChart.js │ │ ├── ohlcBar.js │ │ ├── parallelCoordinates.js │ │ ├── pie.js │ │ ├── pieChart.js │ │ ├── scatter.js │ │ ├── scatterChart.js │ │ ├── scatterPlusLineChart.js │ │ ├── sparkline.js │ │ ├── sparklinePlus.js │ │ ├── stackedArea.js │ │ └── stackedAreaChart.js │ ├── nv.d3.css │ ├── outro.js │ ├── tooltip.js │ └── utils.js └── test │ ├── ScatterChartTest.html │ ├── interactiveBisectTest.html │ ├── lineChartTest.html │ ├── multiBarChartTest.html │ ├── pieChartTest.html │ ├── polylinearTest.html │ ├── realTimeChartTest.html │ ├── stackedAreaChartTest.html │ ├── testScript.js │ └── teststyle.css └── scatterchart-binding.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .Rhistory 3 | *-Ex.R 4 | .Rdata 5 | .Rproj.user 6 | 7 | shinyapps 8 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ksmzn/shinydistributionsapp:latest 2 | 3 | COPY /ShinyDistributionsApp/ /srv/shiny-server/ 4 | 5 | CMD exec shiny-server >> /var/log/shiny-server.log 2>&1 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 ksmzn 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Probability Distributions Viewer 2 | ===================== 3 | 4 | ![demo](https://github.com/ksmzn/ProbabilityDistributionsViewer/blob/master/doc/demo.png) 5 | 6 | [https://statdist.ksmzn.com](https://statdist.ksmzn.com) 7 | 8 | This web app enables visual inspection of various probability distributions commonly used in statistics. 9 | You can modify their parameters, and check how they influence the distributions. 10 | From the **left menu**, choose a probability distribution of interest. 11 | 12 | The web app was authored by @ksmzn using the Shiny R web app framework and the NVD3.js graphing framework. @kaz_yos translated it into English. 13 | 14 | - The original code is avaialbe at: https://github.com/ksmzn/ProbabilityDistributionsViewer 15 | 16 | ### References 17 | 18 | #### Shiny 19 | 20 | + [Shiny Official Tutorial](http://shiny.rstudio.com/tutorial/) 21 | + [Shiny - Bookmarking state](https://shiny.rstudio.com/articles/bookmarking-state.html) 22 | + [Shiny - Advanced bookmarking](https://shiny.rstudio.com/articles/advanced-bookmarking.html) 23 | + [Shiny - Modularizing Shiny app code](https://shiny.rstudio.com/articles/modules.html) 24 | 25 | #### shinydashboard 26 | 27 | + [shinydashboard](https://rstudio.github.io/shinydashboard/) 28 | + [Shiny Dashboard Behavior](https://rstudio.github.io/shinydashboard/behavior.html) 29 | 30 | #### shiny.i18n 31 | 32 | + [GitHub - Appsilon/shiny.i18n](https://github.com/Appsilon/shiny.i18n) 33 | 34 | #### Shiny & HTTPS 35 | 36 | + [SteveLTN/https-portal](https://github.com/SteveLTN/https-portal) 37 | 38 | #### JavaScript 39 | 40 | + [Simple Line Chart - NVD3.js](http://nvd3.org/examples/line.html) 41 | 42 | #### Tutorial & Example 43 | 44 | + [ボケて(bokete)のネタを全自動で流し見できるサイト作った - ほくそ笑む](http://d.hatena.ne.jp/hoxo_m/20140731/p1) (in Japanese) 45 | + [RStudio Shiny チュートリアル レッスン1 ようこそ Shiny へ - Qiita](http://qiita.com/hoxo_m/items/c8365117f3444fb51df4) (in Japanese) 46 | 47 | ### Author's blog article (in Japanese) 48 | 49 | + [Shinyで確率分布を動かして遊べるページ作った](http://ksmzn.hatenablog.com/entry/statdist-shiny) 50 | + [Shinyで作った確率分布を動かせるページを, NVD3.jsでヌルヌルでインタラクティブなグラフにしました。そしてShinyでD3.jsを使う方法3つ。](http://ksmzn.hatenablog.com/entry/shiny-nvd3-js-nuru) 51 | + [確率分布を学ぶアプリを、shinydashboard を使って新しくしてみた & 英訳していただきました。](http://ksmzn.hatenablog.com/entry/shiny-dashboard-english) 52 | + [Dockerを使ってDigitalOceanにShinyアプリを公開する](http://ksmzn.hatenablog.com/entry/degitalocean-shiny-docker) 53 | + [shiny.i18nパッケージでshinyを多言語対応](http://ksmzn.hatenablog.com/entry/shiny-i18n) 54 | + [「ShinyModule」で中規模Shinyアプリをキレイにする](http://ksmzn.hatenablog.com/entry/shiny-module) 55 | 56 | 57 | -------------------------------------------------------------------------------- /README_ja.md: -------------------------------------------------------------------------------- 1 | 確率分布Viewer 2 | ===================== 3 | 4 | ![demo](https://github.com/ksmzn/ProbabilityDistributionsViewer/blob/master/doc/ja/demo.png) 5 | 6 | [https://statdist.ksmzn.com](https://statdist.ksmzn.com) 7 | 8 | ## どんなアプリ? 9 | 10 | 様々な確率分布のカタチを見ることができるWebアプリです。 11 | R言語でアプリを作れる [Shiny](http://shiny.rstudio.com) で作りました。 12 | 13 | パラメータを変えて、確率分布のカタチがどのように変わるのか観察しましょう。 14 | 平均値・分散の値も知ることができます。 15 | 16 | **左メニュー** からお好きな確率分布を選んでください。 17 | 18 | ### 参考文献 19 | 20 | #### Shiny 21 | 22 | + [Shiny Official Tutorial](http://shiny.rstudio.com/tutorial/) 23 | + [Shiny - Bookmarking state](https://shiny.rstudio.com/articles/bookmarking-state.html) 24 | + [Shiny - Advanced bookmarking](https://shiny.rstudio.com/articles/advanced-bookmarking.html) 25 | + [Shiny - Modularizing Shiny app code](https://shiny.rstudio.com/articles/modules.html) 26 | 27 | #### shinydashboard 28 | 29 | + [shinydashboard](https://rstudio.github.io/shinydashboard/) 30 | + [Shiny Dashboard Behavior](https://rstudio.github.io/shinydashboard/behavior.html) 31 | 32 | #### shiny.i18n 33 | 34 | + [GitHub - Appsilon/shiny.i18n](https://github.com/Appsilon/shiny.i18n) 35 | 36 | #### Shiny & HTTPS 37 | 38 | + [SteveLTN/https-portal](https://github.com/SteveLTN/https-portal) 39 | 40 | #### JavaScript 41 | 42 | + [Simple Line Chart - NVD3.js](http://nvd3.org/examples/line.html) 43 | 44 | #### Tutorial & Example 45 | 46 | + [ボケて(bokete)のネタを全自動で流し見できるサイト作った - ほくそ笑む](http://d.hatena.ne.jp/hoxo_m/20140731/p1) 47 | + [RStudio Shiny チュートリアル レッスン1 ようこそ Shiny へ - Qiita](http://qiita.com/hoxo_m/items/c8365117f3444fb51df4) 48 | 49 | ### 拙ブログ 50 | 51 | + [Shinyで確率分布を動かして遊べるページ作った](http://ksmzn.hatenablog.com/entry/statdist-shiny) 52 | + [Shinyで作った確率分布を動かせるページを, NVD3.jsでヌルヌルでインタラクティブなグラフにしました。そしてShinyでD3.jsを使う方法3つ。](http://ksmzn.hatenablog.com/entry/shiny-nvd3-js-nuru) 53 | + [確率分布を学ぶアプリを、shinydashboard を使って新しくしてみた & 英訳していただきました。](http://ksmzn.hatenablog.com/entry/shiny-dashboard-english) 54 | + [Dockerを使ってDigitalOceanにShinyアプリを公開する](http://ksmzn.hatenablog.com/entry/degitalocean-shiny-docker) 55 | + [shiny.i18nパッケージでshinyを多言語対応](http://ksmzn.hatenablog.com/entry/shiny-i18n) 56 | + [「ShinyModule」で中規模Shinyアプリをキレイにする](http://ksmzn.hatenablog.com/entry/shiny-module) 57 | 58 | 59 | -------------------------------------------------------------------------------- /ShinyDistributionsApp.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | -------------------------------------------------------------------------------- /components/modules.R: -------------------------------------------------------------------------------- 1 | library(shiny) 2 | library(shinydashboard) 3 | 4 | # Functions 5 | source("components/functions.R") 6 | 7 | # Module ---- 8 | distTabUI <- function(distEnv, wide = F) { 9 | if (wide) { 10 | boxRow <- valueBoxRowWide 11 | } else { 12 | boxRow <- valueBoxRow 13 | } 14 | dist <- distEnv[["dist"]] 15 | c_or_d <- distEnv[["c_or_d"]] 16 | ns <- NS(dist) 17 | 18 | item <- tabItem( 19 | tabName = dist, 20 | fluidRow( 21 | uiOutput(ns("distBox")), 22 | uiOutput(ns("formulaBox")) 23 | ), 24 | fluidRow( 25 | uiOutput(ns("paramBox")), 26 | uiOutput(ns("plotBox")) 27 | ), 28 | boxRow(ns) 29 | ) 30 | return(item) 31 | } 32 | 33 | distTab <- function(input, output, session, distribution, initParams, i18n) { 34 | # Set Up ---- 35 | d <- distribution 36 | c_or_d <- d$c_or_d 37 | 38 | # Parameters 39 | param_names <- names(d$params) 40 | params <- reactive({ 41 | li <- lapply(param_names, function(x) { 42 | # `input` is not allowed bracket indexing. 43 | eval(parse(text = paste0("input$", x))) 44 | }) 45 | names(li) <- param_names 46 | return(li) 47 | }) 48 | 49 | # Function 50 | func_base <- reactive(d$func(input$p_or_c)) 51 | func <- reactive(do.call(func_base(), params())) 52 | 53 | # X axis 54 | if (c_or_d == "c") { 55 | seq_func <- function(min, max) seq(min, max, length = 1000) 56 | plot_type <- "line" 57 | } else { 58 | seq_func <- function(min, max) seq(min, max) 59 | plot_type <- "scatter" 60 | } 61 | 62 | # Outputs ---- 63 | # Distribution Box 64 | output$distBox <- renderUI({ 65 | distBox(d$name, d$wiki, i18n) 66 | }) 67 | 68 | # Formula Box 69 | output$formulaBox <- renderUI({ 70 | formulaBox(d$formula, c_or_d, i18n) 71 | }) 72 | 73 | # Parameter Box 74 | output$paramBox <- renderUI({ 75 | ns <- session$ns 76 | 77 | range_list <- d$range 78 | params_list <- d$params 79 | dist_name <- d$dist 80 | 81 | # Handle initial values when language changes 82 | params_kept <- initParams() 83 | new_params <- params_kept[[dist_name]] # parameters before language changes 84 | 85 | if (is.null(new_params)) { 86 | p_or_c <- NULL 87 | } else { 88 | # Set as default values 89 | p_or_c <- new_params$p_or_c 90 | range_list$value <- new_params$range 91 | for (x in param_names) { 92 | params_list[[x]]$value <- new_params[[x]] 93 | } 94 | } 95 | createParamBox(ns, c_or_d, range_list, params_list, p_or_c, i18n) 96 | }) 97 | 98 | # Mean 99 | output$meanBox <- renderValueBox({ 100 | value <- do.call(d$mean, params()) 101 | f_str <- d$mean_str 102 | meanBox(f_str, value, i18n) 103 | }) 104 | 105 | # Variance 106 | output$varianceBox <- renderValueBox({ 107 | value <- do.call(d$variance, params()) 108 | f_str <- d$variance_str 109 | varianceBox(f_str, value, i18n) 110 | }) 111 | 112 | # Plot 113 | output$plot <- renderNvd3Chart({ 114 | x <- seq_func(input$range[1], input$range[2]) 115 | x <- do.call(d$x_filter, append(list(x = x), params())) 116 | y <- eval(func()(x)) 117 | df <- data.frame(x, y) 118 | return(df) 119 | }) 120 | 121 | # Plot Box 122 | output$plotBox <- renderUI({ 123 | ns <- session$ns 124 | box( 125 | width = 7, 126 | title = i18n()$t("Plot"), status = "primary", solidHeader = TRUE, 127 | nvd3ChartOutput(ns("plot"), plot_type) 128 | ) 129 | }) 130 | } 131 | 132 | callDistributionModule <- function(distribution, initParams, i18n = NULL) { 133 | callModule(distTab, distribution$dist, distribution, initParams, i18n) 134 | } 135 | -------------------------------------------------------------------------------- /distributions/all.R: -------------------------------------------------------------------------------- 1 | library(shiny) 2 | library(R6) 3 | library(purrr) 4 | 5 | Distribution <- R6Class( 6 | "Distribution", 7 | public = list( 8 | dist = NULL, 9 | name = NULL, 10 | wiki = NULL, 11 | c_or_d = NULL, 12 | func = NULL, 13 | formula = NULL, 14 | x_filter = NULL, 15 | mean = NULL, 16 | mean_str = NULL, 17 | variance = NULL, 18 | variance_str = NULL, 19 | range = NULL, 20 | params = NULL, 21 | initialize = function( 22 | dist = NA, 23 | name = NA, 24 | wiki = NA, 25 | c_or_d = NA, 26 | func_p = NA, 27 | func_c = NA, 28 | formula = NA, 29 | x_filter = NA, 30 | mean = NA, 31 | mean_str = NA, 32 | variance = NA, 33 | variance_str = NA, 34 | range = NA, 35 | ...) { 36 | self$dist <- dist 37 | self$name <- name 38 | self$wiki <- wiki 39 | self$c_or_d <- c_or_d 40 | self$formula <- formula 41 | self$mean <- mean 42 | self$mean_str <- mean_str 43 | self$variance <- variance 44 | self$variance_str <- variance_str 45 | self$range <- range 46 | private$set_x_filter(x_filter) 47 | private$set_func(func_p, func_c) 48 | private$set_params(dist, ...) 49 | } 50 | ), 51 | private = list( 52 | set_x_filter = function(x_filter) { 53 | if (is.null(x_filter)) { 54 | x_filter <- function(x, ...) x 55 | } 56 | self$x_filter <- x_filter 57 | }, 58 | set_func = function(func_p, func_c) { 59 | self$func <- function(p_or_c) { 60 | if (p_or_c == "p") { 61 | return(func_p) 62 | } else { 63 | return(func_c) 64 | } 65 | } 66 | }, 67 | set_params = function(dist, ...) { 68 | params <- list(...) 69 | names(params) <- sapply(params, `[[`, "name") 70 | self$params <- params 71 | } 72 | ) 73 | ) 74 | 75 | source_this <- function(path) { 76 | source(file.path("./distributions", path)) 77 | } 78 | 79 | # Continuous Distribituons 80 | source_this("continuous/Normal.R") 81 | source_this("continuous/Erlang.R") 82 | source_this("continuous/F.R") 83 | source_this("continuous/Noncentral_F.R") 84 | source_this("continuous/Chi-squared.R") 85 | source_this("continuous/Noncentral_chi-squared.R") 86 | source_this("continuous/Gamma.R") 87 | source_this("continuous/Cauchy.R") 88 | source_this("continuous/Exponential.R") 89 | source_this("continuous/Log-normal.R") 90 | source_this("continuous/t.R") 91 | source_this("continuous/Noncentral_t.R") 92 | source_this("continuous/Beta.R") 93 | source_this("continuous/Noncentral_beta.R") 94 | source_this("continuous/Uniform.R") 95 | source_this("continuous/Logistic.R") 96 | source_this("continuous/Weibull.R") 97 | 98 | # Discrete Distribituons 99 | source_this("discrete/Geometric.R") 100 | source_this("discrete/Hypergeometric.R") 101 | source_this("discrete/Binomial.R") 102 | source_this("discrete/Negative_binomial.R") 103 | source_this("discrete/Poisson.R") 104 | source_this("discrete/Discrete_uniform.R") 105 | 106 | # Distribituons List ---- 107 | # Continuous 108 | continuous_distributions <- list( 109 | norm, 110 | erlang, 111 | f, 112 | ncf, 113 | chisq, 114 | ncChisq, 115 | gamma, 116 | cauchy, 117 | exp_dist, 118 | lnormal, 119 | t_dist, 120 | nct, 121 | beta, 122 | ncbeta, 123 | unif, 124 | logis, 125 | weibull 126 | ) 127 | # Discrete 128 | discrete_distributions <- list( 129 | geom, 130 | hyper, 131 | binom, 132 | nbinom, 133 | pois, 134 | dunif 135 | ) 136 | 137 | add_names <- function(x) { 138 | names(x) <- purrr::map_chr(x, ~ .x$dist) 139 | return(x) 140 | } 141 | continuous_distributions <- add_names(continuous_distributions) 142 | discrete_distributions <- add_names(discrete_distributions) 143 | 144 | # All Distribituons 145 | distributions <- c(continuous_distributions, discrete_distributions) 146 | dist_names <- purrr::map_chr(distributions, ~ .x$dist) 147 | -------------------------------------------------------------------------------- /distributions/continuous/Beta.R: -------------------------------------------------------------------------------- 1 | # ベータ分布 ---- 2 | ## functions ---- 3 | beta.func_p <- function(shape1, shape2) function(x) dbeta(x, shape1 = shape1, shape2 = shape2, ncp = 0L) 4 | beta.func_c <- function(shape1, shape2) function(x) pbeta(x, shape1 = shape1, shape2 = shape2, ncp = 0L) 5 | beta.formula <- " 6 | f(x)=\\frac{x^{\\alpha-1}(1-x)^{\\beta-1}}{B(\\alpha,\\beta)} 7 | " 8 | 9 | beta.x_filter <- function(x, shape1, shape2) { 10 | if (shape1 < 1) { 11 | x <- x[x != 0] 12 | } 13 | if (shape2 < 1) { 14 | x <- x[x != 1] 15 | } 16 | return(x) 17 | } 18 | 19 | ## Moments ---- 20 | beta.mean <- function(shape1, shape2) shape1 / (shape1 + shape2) 21 | beta.mean_str <- "\\frac{\\alpha}{\\alpha+\\beta}" 22 | beta.variance <- function(shape1, shape2) { 23 | (shape1 * shape2) / 24 | (((shape1 + shape2) ** 2) * 25 | (shape1 + shape1 + 1)) 26 | } 27 | beta.variance_str <- "\\frac{\\alpha\\beta}{(\\alpha+\\beta)^2 (\\alpha+\\beta+1)}" 28 | 29 | ## Parameters ---- 30 | beta.range <- list( 31 | min = 0, 32 | max = 1, 33 | value = c(0, 1), 34 | step = 0.01 35 | ) 36 | beta.shape1 <- list( 37 | name = "shape1", 38 | label_name = "Shape", 39 | label_symbol = "\\alpha", 40 | min = 0, 41 | max = 20, 42 | value = 2, 43 | step = 0.1 44 | ) 45 | beta.shape2 <- list( 46 | name = "shape2", 47 | label_name = "Shape", 48 | label_symbol = "\\beta", 49 | min = 0, 50 | max = 20, 51 | value = 2, 52 | step = 0.1 53 | ) 54 | 55 | ## Instance ---- 56 | beta <- Distribution$new( 57 | dist = "beta", 58 | name = "Beta distribution", 59 | wiki = "https://en.wikipedia.org/wiki/Beta_distribution", 60 | c_or_d = "c", 61 | func_p = beta.func_p, 62 | func_c = beta.func_c, 63 | formula = beta.formula, 64 | x_filter = beta.x_filter, 65 | mean = beta.mean, 66 | mean_str = beta.mean_str, 67 | variance = beta.variance, 68 | variance_str = beta.variance_str, 69 | range = beta.range, 70 | beta.shape1, 71 | beta.shape2 72 | ) 73 | -------------------------------------------------------------------------------- /distributions/continuous/Cauchy.R: -------------------------------------------------------------------------------- 1 | # コーシー分布 2 | ## Functions ---- 3 | cauchy.func_p <- function(location, scale) function(x) dcauchy(x, location = location, scale = scale) 4 | cauchy.func_c <- function(location, scale) function(x) pcauchy(x, location = location, scale = scale) 5 | cauchy.formula <- " 6 | \\begin{align} 7 | f(x; x_0,\\gamma) &= 8 | { 1 \\over \\pi } \\left[ { \\gamma \\over (x - x_0)^2 + \\gamma^2 } \\right] 9 | \\end{align} 10 | " 11 | 12 | cauchy.x_filter <- NULL 13 | 14 | ## Moments ---- 15 | cauchy.mean <- function(...) NULL 16 | cauchy.mean_str <- NULL 17 | cauchy.variance <- function(...) NULL 18 | cauchy.variance_str <- NULL 19 | 20 | ## Parameters ---- 21 | cauchy.range <- list( 22 | min = -100, 23 | max = 100, 24 | value = c(-10, 10), 25 | step = 0.5 26 | ) 27 | cauchy.location <- list( 28 | name = "location", 29 | label_name = "Location", 30 | label_symbol = "x_0", 31 | min = -20, 32 | max = 20, 33 | value = 0, 34 | step = 0.1 35 | ) 36 | cauchy.scale <- list( 37 | name = "scale", 38 | label_name = "Scale", 39 | label_symbol = "\\gamma", 40 | min = 0, 41 | max = 20, 42 | value = 1, 43 | step = 0.1 44 | ) 45 | 46 | ## Instance ---- 47 | cauchy <- Distribution$new( 48 | dist = "cauchy", 49 | name = "Cauchy distribution", 50 | wiki = "https://en.wikipedia.org/wiki/Cauchy_distribution", 51 | c_or_d = "c", 52 | formula = cauchy.formula, 53 | func_p = cauchy.func_p, 54 | func_c = cauchy.func_c, 55 | x_filter = cauchy.x_filter, 56 | mean = cauchy.mean, 57 | mean_str = cauchy.mean_str, 58 | variance = cauchy.variance, 59 | variance_str = cauchy.variance_str, 60 | range = cauchy.range, 61 | cauchy.location, 62 | cauchy.scale 63 | ) 64 | -------------------------------------------------------------------------------- /distributions/continuous/Chi-squared.R: -------------------------------------------------------------------------------- 1 | # カイ二乗分布 2 | ## Functions ---- 3 | chisq.func_p <- function(df) function(x) dchisq(x, df = df, ncp = 0L) 4 | chisq.func_c <- function(df) function(x) pchisq(x, df = df, ncp = 0L) 5 | chisq.formula <- " 6 | f(x;k)=\\frac{(1/2)^{k/2}}{\\Gamma(k/2)} x^{k/2 - 1} e^{-x/2} 7 | \\ \\ \\ \\ \\mathrm{for\\ } x > 0 8 | " 9 | 10 | chisq.x_filter <- function(x, df) { 11 | if (df == 1) { 12 | x <- x[x != 0] 13 | } 14 | return(x) 15 | } 16 | 17 | ## Moments ---- 18 | chisq.mean <- function(df) df 19 | chisq.mean_str <- "k" 20 | chisq.variance <- function(df) 2 * df 21 | chisq.variance_str <- "2k" 22 | 23 | ## Parameters ---- 24 | chisq.range <- list( 25 | min = 0, 26 | max = 100, 27 | value = c(0, 20), 28 | step = 0.5 29 | ) 30 | chisq.df <- list( 31 | name = "df", 32 | label_name = "Degrees of freedom", 33 | label_symbol = "k", 34 | min = 1, 35 | max = 20, 36 | value = 1 37 | ) 38 | 39 | ## Instance ---- 40 | chisq <- Distribution$new( 41 | dist = "chisq", 42 | name = "Chi-squared distribution", 43 | wiki = "https://en.wikipedia.org/wiki/Noncentral_chi-squared_distribution", 44 | c_or_d = "c", 45 | func_p = chisq.func_p, 46 | func_c = chisq.func_c, 47 | formula = chisq.formula, 48 | x_filter = chisq.x_filter, 49 | mean = chisq.mean, 50 | mean_str = chisq.mean_str, 51 | variance = chisq.variance, 52 | variance_str = chisq.variance_str, 53 | range = chisq.range, 54 | chisq.df 55 | ) 56 | -------------------------------------------------------------------------------- /distributions/continuous/Erlang.R: -------------------------------------------------------------------------------- 1 | # アーラン分布 ---- 2 | ## Functions ---- 3 | erlang.func_p <- function(shape, scale) function(x) dgamma(x, shape = shape, scale = scale) 4 | erlang.func_c <- function(shape, scale) function(x) pgamma(x, shape = shape, scale = scale) 5 | erlang.formula <- "f(x; k, \\theta)=\\frac{x^{k-1}e^{-x/\\theta}}{\\theta^{k}(k-1)!} \\quad\\mbox{for }x,\\theta > 0" 6 | 7 | erlang.x_filter <- NULL 8 | 9 | ## Moments ---- 10 | erlang.mean <- function(shape, scale) shape * scale 11 | erlang.mean_str <- "k\\theta" 12 | erlang.variance <- function(shape, scale) shape * (scale ** 2) 13 | erlang.variance_str <- "k\\theta^2" 14 | 15 | ## Parameters ---- 16 | erlang.range <- list( 17 | min = 0, 18 | max = 100, 19 | value = c(0, 20), 20 | step = 0.5 21 | ) 22 | erlang.shape <- list( 23 | name = "shape", 24 | label_name = "Shape", 25 | label_symbol = "k", 26 | min = 1, 27 | max = 20, 28 | value = 1 29 | ) 30 | erlang.scale <- list( 31 | name = "scale", 32 | label_name = "Scale", 33 | label_symbol = "\\theta", 34 | min = 0.5, 35 | max = 20, 36 | value = 1, 37 | step = 0.1 38 | ) 39 | 40 | ## Instance ---- 41 | erlang <- Distribution$new( 42 | dist = "erlang", 43 | name = "Erlang distribution", 44 | wiki = "https://en.wikipedia.org/wiki/Erlang_distribution", 45 | c_or_d = "c", 46 | func_p = erlang.func_p, 47 | func_c = erlang.func_c, 48 | formula = erlang.formula, 49 | x_filter = erlang.x_filter, 50 | mean = erlang.mean, 51 | mean_str = erlang.mean_str, 52 | variance = erlang.variance, 53 | variance_str = erlang.variance_str, 54 | range = erlang.range, 55 | erlang.shape, 56 | erlang.scale 57 | ) 58 | -------------------------------------------------------------------------------- /distributions/continuous/Exponential.R: -------------------------------------------------------------------------------- 1 | # 指数分布 ---- 2 | ## Functions ---- 3 | exp_dist.func_p <- function(rate) function(x) dexp(x, rate = rate) 4 | exp_dist.func_c <- function(rate) function(x) pexp(x, rate = rate) 5 | exp_dist.formula <- " 6 | f(x; \\lambda) = \\left\\{ 7 | \\begin{array}{ll} 8 | \\lambda e^{-\\lambda x} & (x \\geq 0) \\\\ 0 & (x < 0) 9 | \\end{array} 10 | \\right. 11 | " 12 | 13 | exp_dist.x_filter <- NULL 14 | 15 | ## Moments ---- 16 | exp_dist.mean <- function(rate) 1 / rate 17 | exp_dist.mean_str <- "\\frac{1}{\\lambda}" 18 | exp_dist.variance <- function(rate) 1 / (rate ** 2) 19 | exp_dist.variance_str <- "\\frac{1}{\\lambda^2}" 20 | 21 | ## Parameters ---- 22 | exp_dist.range <- list( 23 | min = -10, 24 | max = 50, 25 | value = c(0, 5), 26 | step = 1 27 | ) 28 | exp_dist.rate <- list( 29 | name = "rate", 30 | label_name = "", 31 | label_symbol = "\\lambda", 32 | min = 0, 33 | max = 20, 34 | value = 1, 35 | step = 0.1 36 | ) 37 | 38 | ## Instance ---- 39 | exp_dist <- Distribution$new( 40 | dist = "exp_dist", 41 | name = "Exponential distribution", 42 | wiki = "https://en.wikipedia.org/wiki/Exponential_distribution", 43 | c_or_d = "c", 44 | formula = exp_dist.formula, 45 | func_p = exp_dist.func_p, 46 | func_c = exp_dist.func_c, 47 | x_filter = exp_dist.x_filter, 48 | mean = exp_dist.mean, 49 | mean_str = exp_dist.mean_str, 50 | variance = exp_dist.variance, 51 | variance_str = exp_dist.variance_str, 52 | range = exp_dist.range, 53 | exp_dist.rate 54 | ) 55 | -------------------------------------------------------------------------------- /distributions/continuous/F.R: -------------------------------------------------------------------------------- 1 | # F分布 ---- 2 | ## Functions ---- 3 | f.func_p <- function(df1, df2) function(x) df(x, df1 = df1, df2 = df2, ncp = 0L) 4 | f.func_c <- function(df1, df2) function(x) pf(x, df1 = df1, df2 = df2, ncp = 0L) 5 | f.formula <- " 6 | f(x) = \\frac{1}{\\mathrm{B}(d_1/2, d_2/2)} \\; 7 | \\left(\\frac{d_1\\,x}{d_1\\,x + d_2}\\right)^{d_1/2} \\; 8 | \\left(1-\\frac{d_1\\,x}{d_1\\,x + d_2}\\right)^{d_2/2} \\; x^{-1} 9 | " 10 | 11 | f.x_filter <- NULL 12 | 13 | ## Moments ---- 14 | f.mean <- function(df1, df2) df2 / (df2 - 2) 15 | f.mean_str <- "\\frac{d_2}{d_2-2}" 16 | f.variance <- function(df1, df2) { 17 | (2 * df2 ** 2) * (df1 + df2 - 2) / 18 | (df1 * ((df2 - 2) ** 2) * (df2 - 4)) 19 | } 20 | f.variance_str <- "\\frac{2\\,d_2^2\\,(d_1+d_2-2)}{d_1 (d_2-2)^2 (d_2-4)}" 21 | 22 | ## Parameters ---- 23 | f.range <- list( 24 | min = 0, 25 | max = 100, 26 | value = c(0, 20), 27 | step = 0.5 28 | ) 29 | f.df1 <- list( 30 | name = "df1", 31 | label_name = "Degrees of freedom", 32 | label_symbol = "d_1", 33 | min = 1, 34 | max = 20, 35 | value = 1 36 | ) 37 | f.df2 <- list( 38 | name = "df2", 39 | label_name = "Degrees of freedom", 40 | label_symbol = "d_2", 41 | min = 1, 42 | max = 20, 43 | value = 1 44 | ) 45 | 46 | ## Instance ---- 47 | f <- Distribution$new( 48 | dist = "f", 49 | name = "F-distribution", 50 | wiki = "https://en.wikipedia.org/wiki/F-distribution", 51 | c_or_d = "c", 52 | formula = f.formula, 53 | func_p = f.func_p, 54 | func_c = f.func_c, 55 | x_filter = f.x_filter, 56 | mean = f.mean, 57 | mean_str = f.mean_str, 58 | variance = f.variance, 59 | variance_str = f.variance_str, 60 | range = f.range, 61 | f.df1, 62 | f.df2 63 | ) 64 | -------------------------------------------------------------------------------- /distributions/continuous/Gamma.R: -------------------------------------------------------------------------------- 1 | # ガンマ分布 ---- 2 | ## Functions ---- 3 | gamma.func_p <- function(shape, scale) function(x) dgamma(x, shape = shape, scale = scale) 4 | gamma.func_c <- function(shape, scale) function(x) pgamma(x, shape = shape, scale = scale) 5 | gamma.formula <- "f(x) = x^{k-1} \\frac{e^{-x/\\theta}}{\\Gamma(k)\\,\\theta^k} 6 | \\ \\ \\ \\ \\mathrm{for\\ } x > 0 7 | " 8 | 9 | gamma.x_filter <- function(x, shape, scale) { 10 | if (shape < 1) { 11 | x <- x[x != 0] 12 | } 13 | return(x) 14 | } 15 | 16 | ## Moments ---- 17 | gamma.mean <- function(shape, scale) shape * scale 18 | gamma.mean_str <- "k\\theta" 19 | gamma.variance <- function(shape, scale) shape * (scale ** 2) 20 | gamma.variance_str <- "k\\theta^2" 21 | 22 | ## Parameters ---- 23 | gamma.range <- list( 24 | min = 0, 25 | max = 100, 26 | value = c(0, 20), 27 | step = 0.5 28 | ) 29 | gamma.shape <- list( 30 | name = "shape", 31 | label_name = "Shape", 32 | label_symbol = "k", 33 | min = 0, 34 | max = 20, 35 | value = 1, 36 | step = 0.1 37 | ) 38 | gamma.scale <- list( 39 | name = "scale", 40 | label_name = "Scale", 41 | label_symbol = "\\theta", 42 | min = 0, 43 | max = 20, 44 | value = 1, 45 | step = 0.1 46 | ) 47 | 48 | ## Instance ---- 49 | gamma <- Distribution$new( 50 | dist = "gamma", 51 | name = "Gamma distribution", 52 | wiki = "https://en.wikipedia.org/wiki/Gamma_distribution", 53 | c_or_d = "c", 54 | func_p = gamma.func_p, 55 | func_c = gamma.func_c, 56 | formula = gamma.formula, 57 | x_filter = gamma.x_filter, 58 | mean = gamma.mean, 59 | mean_str = gamma.mean_str, 60 | variance = gamma.variance, 61 | variance_str = gamma.variance_str, 62 | range = gamma.range, 63 | gamma.shape, 64 | gamma.scale 65 | ) 66 | -------------------------------------------------------------------------------- /distributions/continuous/Log-normal.R: -------------------------------------------------------------------------------- 1 | # 対数正規分布 ---- 2 | ## Functions ---- 3 | lnormal.func_p <- function(meanlog, sdlog) function(x) dlnorm(x, meanlog = meanlog, sdlog = sdlog) 4 | lnormal.func_c <- function(meanlog, sdlog) function(x) plnorm(x, meanlog = meanlog, sdlog = sdlog) 5 | lnormal.formula <- " 6 | f(x) = \\frac{1}{\\sqrt{2\\pi} \\sigma x} e^{-\\frac{ (\\ln{x}-\\mu)^2}{2\\sigma^2} }, 7 | \\quad 0 0 13 | " 14 | 15 | ncf.x_filter <- function(x, df1, df2, ncp) { 16 | if (df1 == 1) { 17 | x <- x[x != 0] 18 | } 19 | return(x) 20 | } 21 | 22 | ## Moments ---- 23 | ncf.mean <- function(df1, df2, ncp) { 24 | if (is.null(df2) || df2 <= 2) { 25 | value <- NULL 26 | } else { 27 | value <- (df2 * (df1 + ncp)) / (df1 * (df2 - 2)) 28 | } 29 | return(value) 30 | } 31 | ncf.mean_str <- "\\frac{\\nu_2(\\nu_1 + \\lambda)}{\\nu_1(\\nu_2-2)}" 32 | 33 | ncf.variance <- function(df1, df2, ncp) { 34 | if (is.null(df2) || df2 <= 4) { 35 | value <- NULL 36 | } else { 37 | value <- 38 | (2 * df2 ** 2 * (((df1 + ncp) ** 2) + (df1 + 2 * ncp) * (df2 - 2))) / 39 | (df1 ** 2 * (df2 - 2) ** 2 * (df2 - 4)) 40 | } 41 | return(value) 42 | } 43 | ncf.variance_str <- "2\\frac{(\\nu_1+\\lambda)^2+(\\nu_1+2\\lambda)(\\nu_2-2)}{(\\nu_2-2)^2(\\nu_2-4)} \\left(\\frac{\\nu_2}{\\nu_1}\\right)^2" 44 | 45 | ## Parameters ---- 46 | ncf.range <- list( 47 | min = 0, 48 | max = 100, 49 | value = c(0, 20), 50 | step = 0.5 51 | ) 52 | ncf.df1 <- list( 53 | name = "df1", 54 | label_name = "Degrees of freedom", 55 | label_symbol = "\\nu_1", 56 | min = 1, 57 | max = 20, 58 | value = 1 59 | ) 60 | ncf.df2 <- list( 61 | name = "df2", 62 | label_name = "Degrees of freedom", 63 | label_symbol = "\\nu_2", 64 | min = 1, 65 | max = 20, 66 | value = 1 67 | ) 68 | ncf.ncp <- list( 69 | name = "ncp", 70 | label_name = "Noncentrality parameter", 71 | label_symbol = "\\lambda", 72 | min = 0, 73 | max = 20, 74 | value = 0, 75 | step = 0.1 76 | ) 77 | 78 | ## Instance ---- 79 | ncf <- Distribution$new( 80 | dist = "ncf", 81 | name = "Noncentral F-distribution", 82 | wiki = "https://en.wikipedia.org/wiki/Noncentral_F-distribution", 83 | c_or_d = "c", 84 | func_p = ncf.func_p, 85 | func_c = ncf.func_c, 86 | formula = ncf.formula, 87 | x_filter = ncf.x_filter, 88 | mean = ncf.mean, 89 | mean_str = ncf.mean_str, 90 | variance = ncf.variance, 91 | variance_str = ncf.variance_str, 92 | range = ncf.range, 93 | ncf.df1, 94 | ncf.df2, 95 | ncf.ncp 96 | ) 97 | -------------------------------------------------------------------------------- /distributions/continuous/Noncentral_beta.R: -------------------------------------------------------------------------------- 1 | library(hypergeo) 2 | # 非心ベータ分布 ---- 3 | ## functions ---- 4 | ncbeta.func_p <- function(shape1, shape2, ncp) function(x) dbeta(x, shape1 = shape1, shape2 = shape2, ncp = ncp) 5 | ncbeta.func_c <- function(shape1, shape2, ncp) function(x) pbeta(x, shape1 = shape1, shape2 = shape2, ncp = ncp) 6 | ncbeta.formula <- " 7 | f(x) = \\sum_{j=0}^\\infty \\frac{1}{j!} 8 | \\left(\\frac{\\lambda}{2}\\right)^je^{-\\lambda/2} 9 | \\frac{x^{\\alpha+j-1}(1-x)^{\\beta-1}}{B(\\alpha+j,\\beta)} 10 | " 11 | 12 | ncbeta.x_filter <- function(x, shape1, shape2, ncp) { 13 | if (shape1 < 1) { 14 | x <- x[x != 0] 15 | } 16 | if (shape2 < 1) { 17 | x <- x[x != 1] 18 | } 19 | return(x) 20 | } 21 | 22 | ## Moments ---- 23 | ncbeta.mean <- function(shape1, shape2, ncp) { 24 | value <- exp(-ncp / 2) * 25 | shape1 * 26 | hypergeo::genhypergeo( 27 | U = c(shape1 + 1, shape1 + shape2), 28 | L = c(shape1, 1 + shape1 + shape2), 29 | z = ncp / 2 30 | ) / 31 | (shape1 + shape2) 32 | return(value) 33 | } 34 | ncbeta.mean_str <- " 35 | e^{-\\frac{\\lambda}{2}} 36 | \\frac{\\alpha}{\\alpha+\\beta} 37 | {}_2F_2\\left(\\alpha+\\beta,\\alpha+1;\\alpha,\\alpha+\\beta+1;\\frac{\\lambda}{2} 38 | \\right) 39 | " 40 | 41 | ncbeta.variance <- function(shape1, shape2, ncp) { 42 | value.mean <- ncbeta.mean(shape1, shape2, ncp) 43 | value <- exp(-ncp / 2) * 44 | shape1 * 45 | (shape1 + 1) * 46 | hypergeo::genhypergeo( 47 | U = c(shape1 + 1, shape1 + shape2), 48 | L = c(shape1, 1 + shape1 + shape2), 49 | z = ncp / 2 50 | ) / 51 | ((shape1 + shape2) * (shape1 + shape2 + 1)) - 52 | value.mean ** 2 53 | return(value) 54 | } 55 | ncbeta.variance_str <- " 56 | e^{-\\frac{\\lambda}{2}} 57 | \\frac{\\alpha (\\alpha+1)}{(\\alpha+\\beta)(\\alpha+\\beta+1)} 58 | {}_2F_2\\left(\\alpha+\\beta,\\alpha+2;\\alpha,\\alpha+\\beta+2 59 | ;\\frac{\\lambda}{2}\\right) - \\mu^2 60 | " 61 | 62 | ## Parameters ---- 63 | ncbeta.range <- list( 64 | min = 0, 65 | max = 1, 66 | value = c(0, 1), 67 | step = 0.01 68 | ) 69 | ncbeta.shape1 <- list( 70 | name = "shape1", 71 | label = "形状 \\(\\alpha\\)", 72 | label_name = "Shape", 73 | label_symbol = "\\alpha", 74 | min = 0, 75 | max = 20, 76 | value = 2, 77 | step = 0.1 78 | ) 79 | ncbeta.shape2 <- list( 80 | name = "shape2", 81 | label = "形状 \\(\\beta\\)", 82 | label_name = "Shape", 83 | label_symbol = "\\beta", 84 | min = 0, 85 | max = 20, 86 | value = 2, 87 | step = 0.1 88 | ) 89 | ncbeta.ncp <- list( 90 | name = "ncp", 91 | label_name = "Noncentrality parameter", 92 | label_symbol = "\\lambda", 93 | min = 0, 94 | max = 20, 95 | value = 0, 96 | step = 0.1 97 | ) 98 | 99 | ## Instance ---- 100 | ncbeta <- Distribution$new( 101 | dist = "ncbeta", 102 | name = "Noncentral beta distribution", 103 | wiki = "https://en.wikipedia.org/wiki/Noncentral_beta_distribution", 104 | c_or_d = "c", 105 | func_p = ncbeta.func_p, 106 | func_c = ncbeta.func_c, 107 | formula = ncbeta.formula, 108 | x_filter = ncbeta.x_filter, 109 | mean = ncbeta.mean, 110 | mean_str = ncbeta.mean_str, 111 | variance = ncbeta.variance, 112 | variance_str = ncbeta.variance_str, 113 | range = ncbeta.range, 114 | ncbeta.shape1, 115 | ncbeta.shape2, 116 | ncbeta.ncp 117 | ) 118 | -------------------------------------------------------------------------------- /distributions/continuous/Noncentral_chi-squared.R: -------------------------------------------------------------------------------- 1 | # 非心カイ二乗分布 2 | ncChisq.func <- function(df, ncp, p_or_c) { 3 | if (p_or_c == "p") { 4 | func <- function(x) dchisq(x, df = df, ncp = ncp) 5 | } else { 6 | func <- function(x) pchisq(x, df = df, ncp = ncp) 7 | } 8 | return(func) 9 | } 10 | ## Functions ---- 11 | ncChisq.func_p <- function(df, ncp) function(x) dchisq(x, df = df, ncp = ncp) 12 | ncChisq.func_c <- function(df, ncp) function(x) pchisq(x, df = df, ncp = ncp) 13 | ncChisq.formula <- "f_X(x; k,\\lambda) = 14 | \\sum_{i=0}^\\infty \\frac{e^{-\\lambda/2} (\\lambda/2)^i}{i!} f_{Y_{k+2i}}(x), 15 | \\ \\ \\ \\ \\mathrm{for\\ } x > 0,\\ \\ Y_q \\sim\\chi^2_q \\ 16 | " 17 | 18 | ncChisq.x_filter <- function(x, df, ncp) { 19 | if (df == 1) { 20 | x <- x[x != 0] 21 | } 22 | return(x) 23 | } 24 | 25 | ## Moments ---- 26 | ncChisq.mean <- function(df, ncp) df + ncp 27 | ncChisq.mean_str <- "k+\\lambda" 28 | ncChisq.variance <- function(df, ncp) 2 * (df + 2 * ncp) 29 | ncChisq.variance_str <- "2(k+2\\lambda)" 30 | 31 | ## Parameters ---- 32 | ncChisq.range <- list( 33 | min = 0, 34 | max = 100, 35 | value = c(0, 20), 36 | step = 0.5 37 | ) 38 | ncChisq.df <- list( 39 | name = "df", 40 | label_name = "Degrees of freedom", 41 | label_symbol = "k", 42 | min = 1, 43 | max = 20, 44 | value = 1 45 | ) 46 | ncChisq.ncp <- list( 47 | name = "ncp", 48 | label_name = "Noncentrality parameter", 49 | label_symbol = "\\lambda", 50 | min = 0, 51 | max = 20, 52 | value = 0, 53 | step = 0.1 54 | ) 55 | 56 | ## Instance ---- 57 | ncChisq <- Distribution$new( 58 | dist = "ncChisq", 59 | name = "Noncentral chi-squared distribution", 60 | wiki = "https://en.wikipedia.org/wiki/Noncentral_chi-squared_distribution", 61 | c_or_d = "c", 62 | func_p = ncChisq.func_p, 63 | func_c = ncChisq.func_c, 64 | formula = ncChisq.formula, 65 | x_filter = ncChisq.x_filter, 66 | mean = ncChisq.mean, 67 | mean_str = ncChisq.mean_str, 68 | variance = ncChisq.variance, 69 | variance_str = ncChisq.variance_str, 70 | range = ncChisq.range, 71 | ncChisq.df, 72 | ncChisq.ncp 73 | ) 74 | -------------------------------------------------------------------------------- /distributions/continuous/Noncentral_t.R: -------------------------------------------------------------------------------- 1 | # 非心t分布 2 | ## Functions ---- 3 | nct.func_p <- function(df, ncp) function(x) dt(x, df = df, ncp = ncp) 4 | nct.func_c <- function(df, ncp) function(x) pt(x, df = df, ncp = ncp) 5 | nct.formula <- " 6 | f(x) =\\frac{\\nu^{\\frac{\\nu}{2}} 7 | \\exp\\left (-\\frac{\\nu\\mu^2}{2(x^2+\\nu)} \\right )} 8 | {\\sqrt{\\pi}\\Gamma(\\frac{\\nu}{2})2^{\\frac{\\nu-1}{2}}(x^2+\\nu)^{\\frac{\\nu+1}{2}}} 9 | \\int_0^\\infty y^\\nu\\exp\\left (-\\frac{1}{2}\\left(y-\\frac{\\mu x}{\\sqrt{x^2+\\nu}} 10 | \\right)^2\\right ) dy 11 | " 12 | 13 | nct.x_filter <- NULL 14 | 15 | ## Moments ---- 16 | nct.mean <- function(df, ncp) { 17 | if (is.null(df) || df <= 1) { 18 | value <- NULL 19 | } else { 20 | value <- ncp * sqrt(df / 2) * gamma((df - 1) / 2) / gamma(df / 2) 21 | } 22 | return(value) 23 | } 24 | nct.mean_str <- "\\mu\\sqrt{\\frac{\\nu}{2}}\\frac{\\Gamma((\\nu-1)/2)}{\\Gamma(\\nu/2)}" 25 | nct.variance <- function(df, ncp) { 26 | if (is.null(df) || df <= 2) { 27 | value <- NULL 28 | } else { 29 | value <- (df * (1 + ncp ** 2)) / (df - 2) - 30 | ((ncp ** 2) * df / 2) * ((gamma((df - 1) / 2) / gamma(df / 2)) ** 2) 31 | } 32 | return(value) 33 | } 34 | nct.variance_str <- "\\frac{\\nu(1+\\mu^2)}{\\nu-2}-\\frac{\\mu^2\\nu}{2}\\left(\\frac{\\Gamma((\\nu-1)/2)}{\\Gamma(\\nu/2)}\\right)^2" 35 | 36 | ## Parameters ---- 37 | nct.range <- list( 38 | min = -100, 39 | max = 100, 40 | value = c(-10, 10), 41 | step = 0.5 42 | ) 43 | nct.df <- list( 44 | name = "df", 45 | label_name = "Degrees of freedom", 46 | label_symbol = "\\nu", 47 | min = 1, 48 | max = 20, 49 | value = 1 50 | ) 51 | nct.ncp <- list( 52 | name = "ncp", 53 | label_name = "Noncentrality parameter", 54 | label_symbol = "\\mu", 55 | min = 0, 56 | max = 20, 57 | value = 0, 58 | step = 0.1 59 | ) 60 | 61 | ## Instance ---- 62 | nct <- Distribution$new( 63 | dist = "nct", 64 | name = "Noncentral t-distribution", 65 | wiki = "https://en.wikipedia.org/wiki/Noncentral_t-distribution", 66 | c_or_d = "c", 67 | formula = nct.formula, 68 | func_p = nct.func_p, 69 | func_c = nct.func_c, 70 | x_filter = nct.x_filter, 71 | mean = nct.mean, 72 | mean_str = nct.mean_str, 73 | variance = nct.variance, 74 | variance_str = nct.variance_str, 75 | range = nct.range, 76 | nct.df, 77 | nct.ncp 78 | ) 79 | -------------------------------------------------------------------------------- /distributions/continuous/Normal.R: -------------------------------------------------------------------------------- 1 | # 正規分布 ---- 2 | ## Functions ---- 3 | norm.func_p <- function(mean, sd) function(x) dnorm(x, mean = mean, sd = sd) 4 | norm.func_c <- function(mean, sd) function(x) pnorm(x, mean = mean, sd = sd) 5 | norm.formula <- "f(x)=\\frac{1}{\\sqrt{2\\pi\\sigma^{2}}}\\exp\\!\\left(-\\frac{(x-\\mu)^2}{2\\sigma^2} \\right)" 6 | 7 | norm.x_filter <- NULL 8 | 9 | ## Moments ---- 10 | norm.mean <- function(mean, sd) mean 11 | norm.mean_str <- "\\mu" 12 | norm.variance <- function(mean, sd) sd ** 2 13 | norm.variance_str <- "\\sigma^2" 14 | 15 | ## Parameters ---- 16 | norm.range <- list( 17 | min = -100, 18 | max = 100, 19 | value = c(-10, 10) 20 | ) 21 | norm.meanParam <- list( 22 | name = "mean", 23 | label_name = "Mean", 24 | label_symbol = "\\mu", 25 | min = -50, 26 | max = 50, 27 | value = 0 28 | ) 29 | norm.sd <- list( 30 | name = "sd", 31 | label_name = "Standard deviation", 32 | label_symbol = "\\sigma", 33 | min = 0, 34 | max = 10, 35 | value = 1, 36 | step = 0.5 37 | ) 38 | 39 | 40 | ## Instance ---- 41 | norm <- Distribution$new( 42 | dist = "norm", 43 | name = "Normal distribution", 44 | wiki = "https://en.wikipedia.org/wiki/Normal_distribution", 45 | c_or_d = "c", 46 | func_p = norm.func_p, 47 | func_c = norm.func_c, 48 | formula = norm.formula, 49 | x_filter = norm.x_filter, 50 | mean = norm.mean, 51 | mean_str = norm.mean_str, 52 | variance = norm.variance, 53 | variance_str = norm.variance_str, 54 | range = norm.range, 55 | norm.meanParam, 56 | norm.sd 57 | ) 58 | -------------------------------------------------------------------------------- /distributions/continuous/Uniform.R: -------------------------------------------------------------------------------- 1 | # 一様分布 ---- 2 | ## functions ---- 3 | unif.func_p <- function(min, max) function(x) dunif(x, min = min, max = max) 4 | unif.func_c <- function(min, max) function(x) punif(x, min = min, max = max) 5 | unif.formula <- " 6 | f(x)=\\begin{cases} 7 | \\frac{1}{b - a} & \\mathrm{for}\\ a \\le x \\le b, \\\\[8pt] 8 | 0 & \\mathrm{for}\\ xb 9 | \\end{cases} 10 | " 11 | 12 | unif.x_filter <- NULL 13 | 14 | ## Moments ---- 15 | unif.mean <- function(min, max) (min + max) / 2 16 | unif.mean_str <- "\\frac{1}{2}(a+b)" 17 | unif.variance <- function(min, max) ((max - min) ** 2) / 12 18 | unif.variance_str <- "\\frac{1}{12}(b-a)^2" 19 | 20 | ## Parameters ---- 21 | unif.range <- list( 22 | min = -50, 23 | max = 50, 24 | value = c(0, 1), 25 | step = 0.5 26 | ) 27 | unif.min <- list( 28 | name = "min", 29 | label_name = "Min", 30 | label_symbol = "a", 31 | min = -50, 32 | max = 50, 33 | value = 0, 34 | step = 0.5 35 | ) 36 | unif.max <- list( 37 | name = "max", 38 | label_name = "Max", 39 | label_symbol = "b", 40 | min = -50, 41 | max = 50, 42 | value = 1, 43 | step = 0.5 44 | ) 45 | 46 | ## Instance ---- 47 | unif <- Distribution$new( 48 | dist = "unif", 49 | name = "Uniform distribution (continuous)", 50 | wiki = "https://en.wikipedia.org/wiki/Uniform_distribution_(continuous)", 51 | c_or_d = "c", 52 | formula = unif.formula, 53 | func_p = unif.func_p, 54 | func_c = unif.func_c, 55 | x_filter = unif.x_filter, 56 | mean = unif.mean, 57 | mean_str = unif.mean_str, 58 | variance = unif.variance, 59 | variance_str = unif.variance_str, 60 | range = unif.range, 61 | unif.min, 62 | unif.max 63 | ) 64 | -------------------------------------------------------------------------------- /distributions/continuous/Weibull.R: -------------------------------------------------------------------------------- 1 | # ワイブル分布 ---- 2 | ## Functions ---- 3 | weibull.func_p <- function(shape, scale) function(x) dweibull(x, shape = shape, scale = scale) 4 | weibull.func_c <- function(shape, scale) function(x) pweibull(x, shape = shape, scale = scale) 5 | weibull.formula <- " 6 | f(t)=\\frac{m}{\\eta}\\left(\\frac{t}{\\eta}\\right)^{m-1} 7 | \\exp \\left\\{-\\left(\\frac{t}{\\eta}\\right)^m\\right\\} 8 | " 9 | 10 | weibull.x_filter <- function(x, shape, scale) { 11 | if (shape < 1) { 12 | x <- x[x != 0] 13 | } 14 | return(x) 15 | } 16 | 17 | ## Moments ---- 18 | weibull.mean <- function(shape, scale) scale * gamma(1 + 1 / shape) 19 | weibull.mean_str <- "\\eta \\Gamma(1+1/m)" 20 | weibull.variance <- function(shape, scale) { 21 | (scale ** 2) * (gamma(1 + 2 / shape) - gamma(1 + 1 / shape) ** 2) 22 | } 23 | weibull.variance_str <- "\\eta^2\\left[\\Gamma\\left(1+\\frac{2}{m}\\right) - \\left(\\Gamma\\left(1+\\frac{1}{m}\\right)\\right)^2\\right]" 24 | 25 | ## Parameters ---- 26 | weibull.range <- list( 27 | min = 0, 28 | max = 100, 29 | value = c(0, 20), 30 | step = 0.5 31 | ) 32 | weibull.shape <- list( 33 | name = "shape", 34 | label_name = "Shape", 35 | label_symbol = "m", 36 | min = 0.1, 37 | max = 20, 38 | value = 1, 39 | step = 0.1 40 | ) 41 | weibull.scale <- list( 42 | name = "scale", 43 | label_name = "Scale", 44 | label_symbol = "\\eta", 45 | min = 0.1, 46 | max = 20, 47 | value = 1, 48 | step = 0.1 49 | ) 50 | 51 | ## Instance ---- 52 | weibull <- Distribution$new( 53 | dist = "weibull", 54 | name = "Weibull distribution", 55 | wiki = "https://en.wikipedia.org/wiki/Weibull_distribution", 56 | c_or_d = "c", 57 | func_p = weibull.func_p, 58 | func_c = weibull.func_c, 59 | formula = weibull.formula, 60 | x_filter = weibull.x_filter, 61 | mean = weibull.mean, 62 | mean_str = weibull.mean_str, 63 | variance = weibull.variance, 64 | variance_str = weibull.variance_str, 65 | range = weibull.range, 66 | weibull.shape, 67 | weibull.scale 68 | ) 69 | -------------------------------------------------------------------------------- /distributions/continuous/t.R: -------------------------------------------------------------------------------- 1 | # t分布 ---- 2 | ## Functions ---- 3 | t_dist.func_p <- function(df) function(x) dt(x, df = df, ncp = 0L) 4 | t_dist.func_c <- function(df) function(x) pt(x, df = df, ncp = 0L) 5 | t_dist.formula <- " 6 | f(x) = \\frac{\\Gamma((\\nu+1)/2)}{\\sqrt{\\nu\\pi\\,}\\, 7 | \\Gamma(\\nu/2)} (1+x^2/\\nu)^{-(\\nu+1)/2} 8 | " 9 | 10 | t_dist.x_filter <- NULL 11 | 12 | ## Moments ---- 13 | t_dist.mean <- function(df) 0L 14 | t_dist.mean_str <- "e^{\\mu+\\sigma^2/2}" 15 | t_dist.variance <- function(df) { 16 | if (df <= 2) { 17 | return(Inf) 18 | } else { 19 | return(df / (df - 2)) 20 | } 21 | } 22 | t_dist.variance_str <- "\\frac{\\nu}{\\nu-2}" 23 | 24 | ## Parameters ---- 25 | t_dist.range <- list( 26 | min = -100, 27 | max = 100, 28 | value = c(-10, 10), 29 | step = 0.5 30 | ) 31 | t_dist.df <- list( 32 | name = "df", 33 | label_name = "Degrees of freedom", 34 | label_symbol = "\\nu", 35 | min = 1, 36 | max = 20, 37 | value = 1 38 | ) 39 | 40 | ## Instance ---- 41 | t_dist <- Distribution$new( 42 | dist = "t_dist", 43 | name = "Student's t-distribution", 44 | wiki = "https://en.wikipedia.org/wiki/Student%27s_t-distribution", 45 | c_or_d = "c", 46 | formula = t_dist.formula, 47 | func_p = t_dist.func_p, 48 | func_c = t_dist.func_c, 49 | x_filter = t_dist.x_filter, 50 | mean = t_dist.mean, 51 | mean_str = t_dist.mean_str, 52 | variance = t_dist.variance, 53 | variance_str = t_dist.variance_str, 54 | range = t_dist.range, 55 | t_dist.df 56 | ) 57 | -------------------------------------------------------------------------------- /distributions/discrete/Binomial.R: -------------------------------------------------------------------------------- 1 | # 二項分布 ---- 2 | ## Functions ---- 3 | binom.func_p <- function(size, prob) function(x) dbinom(x, size = size, prob = prob) 4 | binom.func_c <- function(size, prob) function(x) pbinom(x, size = size, prob = prob) 5 | binom.formula <- " 6 | P[X=k]={n\\choose k}p^k(1-p)^{n-k}\\quad\\mbox{for}\\ k=0,1,2,\\dots,n 7 | " 8 | 9 | binom.x_filter <- NULL 10 | 11 | ## Moments ---- 12 | binom.mean <- function(size, prob) size * prob 13 | binom.mean_str <- "np" 14 | binom.variance <- function(size, prob) size * prob * (1 - prob) 15 | binom.variance_str <- "np(1-p)" 16 | 17 | ## Parameters ---- 18 | binom.range <- list( 19 | min = 0, 20 | max = 100, 21 | value = c(0, 20), 22 | step = 1 23 | ) 24 | binom.size <- list( 25 | name = "size", 26 | label_name = "Number of trials", 27 | label_symbol = "n", 28 | min = 0, 29 | max = 40, 30 | value = 10, 31 | step = 1 32 | ) 33 | binom.prob <- list( 34 | name = "prob", 35 | label_name = "Probability of successful trial", 36 | label_symbol = "p", 37 | min = 0, 38 | max = 1, 39 | value = 0.5, 40 | step = 0.01 41 | ) 42 | 43 | ## Instance ---- 44 | binom <- Distribution$new( 45 | dist = "binom", 46 | name = "Binomial distribution", 47 | wiki = "https://en.wikipedia.org/wiki/Binomial_distribution", 48 | c_or_d = "d", 49 | formula = binom.formula, 50 | func_p = binom.func_p, 51 | func_c = binom.func_c, 52 | x_filter = binom.x_filter, 53 | mean = binom.mean, 54 | mean_str = binom.mean_str, 55 | variance = binom.variance, 56 | variance_str = binom.variance_str, 57 | range = binom.range, 58 | binom.size, 59 | binom.prob 60 | ) 61 | -------------------------------------------------------------------------------- /distributions/discrete/Discrete_uniform.R: -------------------------------------------------------------------------------- 1 | # 離散一様分布 2 | ## functions ---- 3 | dunif.func_p <- function(min, max) function(x) dunif(x, min = min, max = max) 4 | dunif.func_c <- function(min, max) function(x) punif(x, min = min, max = max) 5 | dunif.formula <- " 6 | f(x)=\\begin{cases} 7 | \\frac{1}{n} & \\mathrm{for}\\ a \\le x \\le b, \\\\[8pt] 8 | 0 & \\mathrm{for}\\ xb 9 | \\end{cases} 10 | " 11 | 12 | dunif.x_filter <- NULL 13 | 14 | ## Moments ---- 15 | dunif.mean <- function(min, max) (min + max) / 2 16 | dunif.mean_str <- "\\frac{a+b}{2}" 17 | dunif.variance <- function(min, max) (((max - min + 1) ** 2) - 1) / 12 18 | dunif.variance_str <- "\\frac{(b-a+1)^2 -1}{12}" 19 | 20 | ## Parameters ---- 21 | dunif.range <- list( 22 | min = 0, 23 | max = 100, 24 | value = c(0, 20), 25 | step = 1 26 | ) 27 | dunif.min <- list( 28 | name = "min", 29 | label_name = "Min", 30 | label_symbol = "a", 31 | min = 0, 32 | max = 100, 33 | value = 0, 34 | step = 1 35 | ) 36 | dunif.max <- list( 37 | name = "max", 38 | label_name = "Max", 39 | label_symbol = "b", 40 | min = 0, 41 | max = 100, 42 | value = 20, 43 | step = 1 44 | ) 45 | 46 | ## Instance ---- 47 | dunif <- Distribution$new( 48 | dist = "dunif", 49 | name = "Discrete uniform distribution", 50 | wiki = "https://en.wikipedia.org/wiki/Discrete_uniform_distribution", 51 | c_or_d = "d", 52 | formula = dunif.formula, 53 | func_p = dunif.func_p, 54 | func_c = dunif.func_c, 55 | x_filter = dunif.x_filter, 56 | mean = dunif.mean, 57 | mean_str = dunif.mean_str, 58 | variance = dunif.variance, 59 | variance_str = dunif.variance_str, 60 | range = dunif.range, 61 | dunif.min, 62 | dunif.max 63 | ) 64 | -------------------------------------------------------------------------------- /distributions/discrete/Geometric.R: -------------------------------------------------------------------------------- 1 | # 幾何分布 ---- 2 | ## Functions ---- 3 | geom.func_p <- function(prob) function(x) dgeom(x, prob = prob) 4 | geom.func_c <- function(prob) function(x) pgeom(x, prob = prob) 5 | geom.formula <- " 6 | Pr(X = k) = p(1-p)^{k} 7 | " 8 | 9 | geom.x_filter <- NULL 10 | 11 | ## Moments ---- 12 | geom.mean <- function(prob) (1 - prob) / prob 13 | geom.mean_str <- "\\frac{1-p}{p}" 14 | geom.variance <- function(prob) (1 - prob) / prob ** 2 15 | geom.variance_str <- "\\frac{1-p}{p^2}" 16 | 17 | ## Parameters ---- 18 | geom.range <- list( 19 | min = 0, 20 | max = 100, 21 | value = c(0, 20), 22 | step = 1 23 | ) 24 | geom.prob <- list( 25 | name = "prob", 26 | label_name = "Probability of successful trial", 27 | label_symbol = "p", 28 | min = 0, 29 | max = 1, 30 | value = 0.5, 31 | step = 0.01 32 | ) 33 | 34 | ## Instance ---- 35 | geom <- Distribution$new( 36 | dist = "geom", 37 | name = "Geometric distribution", 38 | wiki = "https://en.wikipedia.org/wiki/Geometric_distribution", 39 | c_or_d = "d", 40 | formula = geom.formula, 41 | func_p = geom.func_p, 42 | func_c = geom.func_c, 43 | x_filter = geom.x_filter, 44 | mean = geom.mean, 45 | mean_str = geom.mean_str, 46 | variance = geom.variance, 47 | variance_str = geom.variance_str, 48 | range = geom.range, 49 | geom.prob 50 | ) 51 | -------------------------------------------------------------------------------- /distributions/discrete/Hypergeometric.R: -------------------------------------------------------------------------------- 1 | # 超幾何分布 ---- 2 | ## Functions ---- 3 | hyper.func_p <- function(m, n, k) function(x) dhyper(x, m = m, n = n, k = k) 4 | hyper.func_c <- function(m, n, k) function(x) phyper(x, m = m, n = n, k = k) 5 | hyper.formula <- " 6 | \\operatorname{P}(X=x) 7 | = \\frac{\\binom{m}{x}\\binom{n}{k-x}}{\\binom{m+n}{k}} 8 | " 9 | 10 | hyper.x_filter <- NULL 11 | 12 | ## Moments ---- 13 | hyper.mean <- function(m, n, k) k * m / (m + n) 14 | hyper.mean_str <- "\\frac{km}{m+n}" 15 | hyper.variance <- function(m, n, k) k * m * n * (m + n - k) / (((m + n) ** 2) * (m + n - 1)) 16 | hyper.variance_str <- "\\frac{kmn(m+n-k)}{(m+n)^2 (m+n-1)}" 17 | 18 | ## Parameters ---- 19 | hyper.range <- list( 20 | min = 0, 21 | max = 100, 22 | value = c(0, 50), 23 | step = 1 24 | ) 25 | hyper.m <- list( 26 | name = "m", 27 | label_name = "Number of white balls in the urn", 28 | label_symbol = "m", 29 | min = 0, 30 | max = 100, 31 | value = 50, 32 | step = 1 33 | ) 34 | hyper.n <- list( 35 | name = "n", 36 | label_name = "Number of black balls in the urn", 37 | label_symbol = "n", 38 | min = 0, 39 | max = 100, 40 | value = 50, 41 | step = 1 42 | ) 43 | hyper.k <- list( 44 | name = "k", 45 | label_name = "Number of balls drawn from the urn", 46 | label_symbol = "k", 47 | min = 0, 48 | max = 100, 49 | value = 50, 50 | step = 1 51 | ) 52 | 53 | ## Instance ---- 54 | hyper <- Distribution$new( 55 | dist = "hyper", 56 | name = "Hypergeometric distribution", 57 | wiki = "https://en.wikipedia.org/wiki/Hypergeometric_distribution", 58 | c_or_d = "d", 59 | formula = hyper.formula, 60 | func_p = hyper.func_p, 61 | func_c = hyper.func_c, 62 | x_filter = hyper.x_filter, 63 | mean = hyper.mean, 64 | mean_str = hyper.mean_str, 65 | variance = hyper.variance, 66 | variance_str = hyper.variance_str, 67 | range = hyper.range, 68 | hyper.m, 69 | hyper.n, 70 | hyper.k 71 | ) 72 | -------------------------------------------------------------------------------- /distributions/discrete/Negative_binomial.R: -------------------------------------------------------------------------------- 1 | # 負の二項分布 ---- 2 | ## Functions ---- 3 | nbinom.func_p <- function(size, prob) function(x) dnbinom(x, size = size, prob = prob) 4 | nbinom.func_c <- function(size, prob) function(x) pnbinom(x, size = size, prob = prob) 5 | nbinom.formula <- "f(x)=P(X=x) = {x-1 \\choose r-1} p^r (1-p)^{x-r}" 6 | 7 | nbinom.x_filter <- NULL 8 | 9 | ## Moments ---- 10 | nbinom.mean <- function(size, prob) { 11 | if (is.null(prob) || prob == 0) { 12 | value <- Inf 13 | } else { 14 | value <- size / prob 15 | } 16 | return(value) 17 | } 18 | nbinom.mean_str <- "\\frac{r}{p}" 19 | nbinom.variance <- function(size, prob) { 20 | if (is.null(prob) || prob == 0) { 21 | value <- Inf 22 | } else { 23 | value <- size * (1 - prob) / (prob ** 2) 24 | } 25 | return(value) 26 | } 27 | nbinom.variance_str <- "\\frac{r(1-p)}{p^2}" 28 | 29 | ## Parameters ---- 30 | nbinom.range <- list( 31 | min = 0, 32 | max = 100, 33 | value = c(0, 20), 34 | step = 1 35 | ) 36 | nbinom.size <- list( 37 | name = "size", 38 | label_name = "target for number of successful trials", 39 | label_symbol = "r", 40 | min = 1, 41 | max = 20, 42 | value = 1, 43 | step = 1 44 | ) 45 | nbinom.prob <- list( 46 | name = "prob", 47 | label_name = "Probability of successful trial", 48 | label_symbol = "p", 49 | min = 0, 50 | max = 1, 51 | value = 0.5, 52 | step = 0.01 53 | ) 54 | 55 | ## Instance ---- 56 | nbinom <- Distribution$new( 57 | dist = "nbinom", 58 | name = "Negative binomial distribution", 59 | wiki = "https://en.wikipedia.org/wiki/Negative_binomial_distribution", 60 | c_or_d = "d", 61 | formula = nbinom.formula, 62 | func_p = nbinom.func_p, 63 | func_c = nbinom.func_c, 64 | x_filter = nbinom.x_filter, 65 | mean = nbinom.mean, 66 | mean_str = nbinom.mean_str, 67 | variance = nbinom.variance, 68 | variance_str = nbinom.variance_str, 69 | range = nbinom.range, 70 | nbinom.size, 71 | nbinom.prob 72 | ) 73 | -------------------------------------------------------------------------------- /distributions/discrete/Poisson.R: -------------------------------------------------------------------------------- 1 | # ポアソン分布 ---- 2 | ## Functions ---- 3 | pois.func_p <- function(lambda) function(x) dpois(x, lambda = lambda) 4 | pois.func_c <- function(lambda) function(x) ppois(x, lambda = lambda) 5 | pois.formula <- " 6 | P(X=k)=\\frac{\\lambda^k e^{-\\lambda}}{k!} 7 | " 8 | 9 | pois.x_filter <- NULL 10 | 11 | ## Moments ---- 12 | pois.mean <- function(lambda) lambda 13 | pois.mean_str <- "\\lambda" 14 | pois.variance <- function(lambda) lambda 15 | pois.variance_str <- "\\lambda" 16 | 17 | ## Parameters ---- 18 | pois.range <- list( 19 | min = 0, 20 | max = 100, 21 | value = c(0, 20), 22 | step = 1 23 | ) 24 | pois.lambda <- list( 25 | name = "lambda", 26 | label_name = "", 27 | label_symbol = "\\lambda", 28 | min = 1, 29 | max = 20, 30 | value = 1, 31 | step = 0.5 32 | ) 33 | 34 | ## Instance ---- 35 | pois <- Distribution$new( 36 | dist = "pois", 37 | name = "Poisson distribution", 38 | wiki = "https://en.wikipedia.org/wiki/Poisson_distribution", 39 | c_or_d = "d", 40 | formula = pois.formula, 41 | func_p = pois.func_p, 42 | func_c = pois.func_c, 43 | x_filter = pois.x_filter, 44 | mean = pois.mean, 45 | mean_str = pois.mean_str, 46 | variance = pois.variance, 47 | variance_str = pois.variance_str, 48 | range = pois.range, 49 | pois.lambda 50 | ) 51 | -------------------------------------------------------------------------------- /doc/demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksmzn/ProbabilityDistributionsViewer/ba24761a890e7d4f06f180316ca088d8210c4940/doc/demo.png -------------------------------------------------------------------------------- /doc/ja/demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksmzn/ProbabilityDistributionsViewer/ba24761a890e7d4f06f180316ca088d8210c4940/doc/ja/demo.png -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | https-portal: 2 | image: steveltn/https-portal:1 3 | ports: 4 | - '80:80' 5 | - '443:443' 6 | links: 7 | - statdist 8 | restart: always 9 | environment: 10 | DOMAINS: 'statdist.ksmzn.com -> http://statdist:3838' 11 | STAGE: 'production' 12 | # FORCE_RENEW: 'true' 13 | 14 | statdist: 15 | build: . 16 | -------------------------------------------------------------------------------- /global.R: -------------------------------------------------------------------------------- 1 | # Any code in this file is guaranteed to be called before either 2 | # ui.R or server.R 3 | 4 | enableBookmarking(store = "url") 5 | 6 | source("utils/all.R") 7 | source("nvd3chart.R") 8 | source("i18n/main.R") 9 | source("distributions/all.R") 10 | source("components/modules.R") -------------------------------------------------------------------------------- /i18n/config.yaml: -------------------------------------------------------------------------------- 1 | cultural_date_format: "%d/%m/%Y" 2 | cultural_bignumer_mark: " " 3 | cultural_punctuation_mark: "," 4 | -------------------------------------------------------------------------------- /i18n/main.R: -------------------------------------------------------------------------------- 1 | library(shiny.i18n) 2 | 3 | I18N_DIR <- "./i18n" 4 | 5 | translator <- Translator$new( 6 | translation_csvs_path = I18N_DIR, 7 | translation_csv_config = file.path(I18N_DIR, "config.yaml") 8 | ) 9 | -------------------------------------------------------------------------------- /i18n/translation_ja.csv: -------------------------------------------------------------------------------- 1 | English,Japanese 2 | about.md,about_ja.md 3 | This link stores the current state of this application.,このURLはアプリの状態を保持したものです。 4 | Bookmarked application link,ブックマーク用リンク 5 | Dismiss,閉じる 6 | Press Ctrl-C to copy.,Ctrl-C を押してコピーできます。 7 | Press ⌘-C to copy.,⌘-C を押してコピーできます。 8 | mean,期待値 9 | Mean,期待値 10 | variance,分散 11 | Variance,分散 12 | Standard deviation,標準偏差 13 | Shape,形状 14 | Scale,尺度 15 | Degrees of freedom,自由度 16 | Noncentrality parameter,非中心度 17 | Location,位置 18 | Mean Log,平均log 19 | Standard deviation Log,標準偏差log 20 | Probability of successful trial,成功確率 21 | Number of trials,試行回数 22 | target for number of successful trials,成功をする前に失敗した試行回数 23 | Number of white balls in the urn,成功状態の数 24 | Number of black balls in the urn,失敗状態の数 25 | Number of balls drawn from the urn,取り出す数 26 | Min,最小値 27 | Max,最大値 28 | Undefined,定義されない 29 | Plot,プロット 30 | variance(∞ if 1 <= ν <= 2),分散 (自由度が2以下のときは∞) 31 | Probability Distributions Viewer,確率分布 Viewer 32 | Reference,参考 33 | Parameters,パラメータ 34 | Probability density function (PDF),確率密度関数 35 | Probability mass function (PMF),確率関数 36 | Cumulative distribution function (CDF),累積分布関数 37 | Range,範囲 38 | Continuous distributions,連続分布 39 | Normal distribution,正規分布 40 | https://en.wikipedia.org/wiki/Normal_distribution,https://ja.wikipedia.org/wiki/正規分布 41 | Erlang distribution,アーラン分布 42 | https://en.wikipedia.org/wiki/Erlang_distribution,https://ja.wikipedia.org/wiki/アーラン分布 43 | F-distribution,F分布 44 | https://en.wikipedia.org/wiki/F-distribution,https://ja.wikipedia.org/wiki/F分布 45 | Noncentral F-distribution,非心F分布 46 | https://en.wikipedia.org/wiki/Noncentral_F-distribution,https://en.wikipedia.org/wiki/Noncentral_F-distribution 47 | Chi-squared distribution,カイ二乗分布 48 | https://en.wikipedia.org/wiki/Chi-squared_distribution,https://ja.wikipedia.org/wiki/カイ二乗分布 49 | Noncentral chi-squared distribution,非心カイ二乗分布 50 | https://en.wikipedia.org/wiki/Noncentral_chi-squared_distribution,https://ja.wikipedia.org/wiki/非心カイ二乗分布 51 | Gamma distribution,ガンマ分布 52 | https://en.wikipedia.org/wiki/Gamma_distribution,https://ja.wikipedia.org/wiki/ガンマ分布 53 | Cauchy distribution,コーシー分布 54 | https://en.wikipedia.org/wiki/Cauchy_distribution,https://ja.wikipedia.org/wiki/コーシー分布 55 | Exponential distribution,指数分布 56 | https://en.wikipedia.org/wiki/Exponential_distribution,https://ja.wikipedia.org/wiki/指数分布 57 | Log-normal distribution,対数正規分布 58 | https://en.wikipedia.org/wiki/Log-normal_distribution,https://ja.wikipedia.org/wiki/対数正規分布 59 | Student's t-distribution,t分布 60 | https://en.wikipedia.org/wiki/Student%27s_t-distribution,https://ja.wikipedia.org/wiki/t分布 61 | Noncentral t-distribution,非心t分布 62 | https://en.wikipedia.org/wiki/Noncentral_t-distribution,https://ja.wikipedia.org/wiki/非心t分布 63 | Beta distribution,ベータ分布 64 | https://en.wikipedia.org/wiki/Beta_distribution,https://ja.wikipedia.org/wiki/ベータ分布 65 | Noncentral beta distribution,非心ベータ分布 66 | https://en.wikipedia.org/wiki/Noncentral_beta_distribution,https://en.wikipedia.org/wiki/Noncentral_beta_distribution 67 | Uniform distribution (continuous),連続一様分布 68 | https://en.wikipedia.org/wiki/Uniform_distribution_(continuous),https://ja.wikipedia.org/wiki/連続一様分布 69 | Logistic distribution,ロジスティック分布 70 | https://en.wikipedia.org/wiki/Logistic_distribution,https://ja.wikipedia.org/wiki/ロジスティック分布 71 | Weibull distribution,ワイブル分布 72 | https://en.wikipedia.org/wiki/Weibull_distribution,https://ja.wikipedia.org/wiki/ワイブル分布 73 | Discrete distributions,離散分布 74 | Geometric distribution,幾何分布 75 | https://en.wikipedia.org/wiki/Geometric_distribution,https://ja.wikipedia.org/wiki/幾何分布 76 | Hypergeometric distribution,超幾何分布 77 | https://en.wikipedia.org/wiki/Hypergeometric_distribution,https://ja.wikipedia.org/wiki/超幾何分布 78 | Binomial distribution,二項分布 79 | https://en.wikipedia.org/wiki/Binomial_distribution,https://ja.wikipedia.org/wiki/二項分布 80 | Negative binomial distribution,負の二項分布 81 | https://en.wikipedia.org/wiki/Negative_binomial_distribution,https://ja.wikipedia.org/wiki/負の二項分布 82 | Poisson distribution,ポアソン分布 83 | https://en.wikipedia.org/wiki/Poisson_distribution,https://ja.wikipedia.org/wiki/ポアソン分布 84 | Discrete uniform distribution,離散一様分布 85 | https://en.wikipedia.org/wiki/Discrete_uniform_distribution,https://ja.wikipedia.org/wiki/離散一様分布 86 | -------------------------------------------------------------------------------- /markdown/about.md: -------------------------------------------------------------------------------- 1 | ## Shiny web app for live demonstration of probability distributions 2 | 3 | This web app enables visual inspection of various probability distributions commonly used in statistics. 4 | You can modify their parameters, and check how they influence the distributions. 5 | From the **left menu**, choose a probability distribution of interest. 6 | 7 | The web app was authored by @ksmzn using the Shiny R web app framework and the NVD3.js graphing framework. @kaz_yos translated it into English. 8 | 9 | - The original code is avaialbe at: https://github.com/ksmzn/ProbabilityDistributionsViewer 10 | 11 | ### References 12 | 13 | #### Shiny 14 | 15 | + [Shiny Official Tutorial](http://shiny.rstudio.com/tutorial/) 16 | + [Shiny - Bookmarking state](https://shiny.rstudio.com/articles/bookmarking-state.html) 17 | + [Shiny - Advanced bookmarking](https://shiny.rstudio.com/articles/advanced-bookmarking.html) 18 | + [Shiny - Modularizing Shiny app code](https://shiny.rstudio.com/articles/modules.html) 19 | 20 | #### shinydashboard 21 | 22 | + [shinydashboard](https://rstudio.github.io/shinydashboard/) 23 | + [Shiny Dashboard Behavior](https://rstudio.github.io/shinydashboard/behavior.html) 24 | 25 | #### shiny.i18n 26 | 27 | + [GitHub - Appsilon/shiny.i18n](https://github.com/Appsilon/shiny.i18n) 28 | 29 | #### JavaScript 30 | 31 | + [Simple Line Chart - NVD3.js](http://nvd3.org/examples/line.html) 32 | 33 | #### Tutorial & Example 34 | 35 | + [ボケて(bokete)のネタを全自動で流し見できるサイト作った - ほくそ笑む](http://d.hatena.ne.jp/hoxo_m/20140731/p1) (in Japanese) 36 | + [RStudio Shiny チュートリアル レッスン1 ようこそ Shiny へ - Qiita](http://qiita.com/hoxo_m/items/c8365117f3444fb51df4) (in Japanese) 37 | 38 | ### Author's blog article (in Japanese) 39 | 40 | + [Shinyで確率分布を動かして遊べるページ作った](http://ksmzn.hatenablog.com/entry/statdist-shiny) 41 | -------------------------------------------------------------------------------- /markdown/about_ja.md: -------------------------------------------------------------------------------- 1 | ## 確率分布 Viewer 2 | 3 | 様々な確率分布のカタチを見ることができるWebアプリです。 4 | R言語でアプリを作れる [Shiny](http://shiny.rstudio.com) で作りました。 5 | 6 | パラメータを変えて、確率分布のカタチがどのように変わるのか観察しましょう。 7 | 平均値・分散の値も知ることができます。 8 | 9 | 上部のBookmarkボタンで、作成した分布の状態を保存できます。 10 | URLをコピーすれば、シェアすることも可能です。 11 | 12 | **左メニュー** からお好きな確率分布を選んでください。 13 | 14 | **【2018年2月3日 追記】** 15 | 16 | - ブックマーク機能を作成しました。 17 | 右上の「Bookmark」ボタンからどうぞ。 18 | 19 | - 言語切り替え機能を作成しました。 20 | 右上の選択ボタンからどうぞ。 21 | 現在対応しているのは日本語と英語です。 22 | その他の言語の対応は未定ですが、[PullRequest](https://github.com/ksmzn/ProbabilityDistributionsViewer/pulls) は大歓迎です。 23 | よろしくお願いします。 24 | 25 | **【2015年1月14日 追記】** 26 | 27 | NVD3.jsを使ったグラフに変更しました! 28 | また、分布名の隣に、日本版Wikipediaへのリンクを追加しました。 29 | 30 | **【2015年1月27日 追記】** 31 | 32 | なんと、 33 | このアプリを 34 | @kaz_yos 35 | さんが英語に翻訳して下さいました!! 36 | 37 |

Shiny web app for live demonstration of probability distributions

38 | 39 | @kaz_yos 40 | さん、ありがとうございました。 41 | 42 | **【2015年2月25日 追記】** 43 | 44 | shinydashboard 45 | を使って 46 | デザインやUIを一新しました。 47 | shinydashboard は綺麗なデザインが簡単にできて素晴らしいですね。 48 | 49 | また、期待値や分散を追加しました。 50 | より便利になったと思います。 51 | 52 | ### 参考文献 53 | 54 | このアプリを作る際に参考にしたページは以下です。 55 | 特に、作成当時はShinyの日本語情報が少ないなか、 56 | @hoxo_mさんの記事やコードはとても参考になりました。 57 | @hoxo_mさん、ありがとうございました。 58 | 59 | #### Shiny 60 | 61 | + [Shiny Official Tutorial](http://shiny.rstudio.com/tutorial/) 62 | + [Shiny - Bookmarking state](https://shiny.rstudio.com/articles/bookmarking-state.html) 63 | + [Shiny - Advanced bookmarking](https://shiny.rstudio.com/articles/advanced-bookmarking.html) 64 | + [Shiny - Modularizing Shiny app code](https://shiny.rstudio.com/articles/modules.html) 65 | 66 | #### shinydashboard 67 | 68 | + [shinydashboard](https://rstudio.github.io/shinydashboard/) 69 | + [Shiny Dashboard Behavior](https://rstudio.github.io/shinydashboard/behavior.html) 70 | 71 | #### shiny.i18n 72 | 73 | + [GitHub - Appsilon/shiny.i18n](https://github.com/Appsilon/shiny.i18n) 74 | 75 | #### JavaScript 76 | 77 | + [Simple Line Chart - NVD3.js](http://nvd3.org/examples/line.html) 78 | 79 | #### Tutorial & Example 80 | 81 | + [ボケて(bokete)のネタを全自動で流し見できるサイト作った - ほくそ笑む](http://d.hatena.ne.jp/hoxo_m/20140731/p1) 82 | + [RStudio Shiny チュートリアル レッスン1 ようこそ Shiny へ - Qiita](http://qiita.com/hoxo_m/items/c8365117f3444fb51df4) 83 | 84 | ### 拙ブログ 85 | 86 | + [Shinyで確率分布を動かして遊べるページ作った](http://ksmzn.hatenablog.com/entry/statdist-shiny) 87 | + [Shinyで作った確率分布を動かせるページを, NVD3.jsでヌルヌルでインタラクティブなグラフにしました。そしてShinyでD3.jsを使う方法3つ。](http://ksmzn.hatenablog.com/entry/shiny-nvd3-js-nuru) 88 | + [確率分布を学ぶアプリを、shinydashboard を使って新しくしてみた & 英訳していただきました。](http://ksmzn.hatenablog.com/entry/shiny-dashboard-english) 89 | + [Dockerを使ってDigitalOceanにShinyアプリを公開する](http://ksmzn.hatenablog.com/entry/degitalocean-shiny-docker) 90 | + [shiny.i18nパッケージでshinyを多言語対応](http://ksmzn.hatenablog.com/entry/shiny-i18n) 91 | + [「ShinyModule」で中規模Shinyアプリをキレイにする](http://ksmzn.hatenablog.com/entry/shiny-module) 92 | 93 | 94 | -------------------------------------------------------------------------------- /nvd3chart.R: -------------------------------------------------------------------------------- 1 | library(shiny) 2 | 3 | # To be called from ui.R 4 | nvd3ChartOutput <- function(inputId, type, width="100%", height="400px") { 5 | style <- sprintf( 6 | "width: %s; height: %s;", 7 | validateCssUnit(width), validateCssUnit(height) 8 | ) 9 | if (type == "line") { 10 | class <- "nvd3-linechart" 11 | } else { 12 | class <- "nvd3-scatterchart" 13 | } 14 | 15 | tagList( 16 | # Include CSS/JS dependencies. Use "singleton" to make sure that even 17 | # if multiple lineChartOutputs are used in the same page, we'll still 18 | # only include these chunks once. 19 | singleton(tags$head( 20 | tags$script(src = "js/d3/d3.v3.min.js"), 21 | tags$script(src = "js/nvd3/nv.d3.min.js"), 22 | tags$link(rel = "stylesheet", type = "text/css", href = "js/nvd3/nv.d3.min.css"), 23 | tags$script(src = "js/linechart-binding.js"), 24 | tags$script(src = "js/scatterchart-binding.js") 25 | )), 26 | div( 27 | id = inputId, class = class, style = style, 28 | tag("svg", list()) 29 | ) 30 | ) 31 | } 32 | 33 | # To be called from server.R 34 | renderNvd3Chart <- function(expr, env=parent.frame(), quoted=FALSE) { 35 | # This piece of boilerplate converts the expression `expr` into a 36 | # function called `func`. It's needed for the RStudio IDE's built-in 37 | # debugger to work properly on the expression. 38 | installExprFunction(expr, "func", env, quoted) 39 | 40 | function() { 41 | dataframe <- func() 42 | mapply(function(name) { 43 | values <- mapply(function(i, j) { 44 | list(x = i, y = j) 45 | }, dataframe$x, dataframe$y, SIMPLIFY = FALSE, USE.NAMES = FALSE) 46 | list(key = name, values = values) 47 | }, c("y"), SIMPLIFY = FALSE, USE.NAMES = FALSE) 48 | } 49 | } 50 | 51 | 52 | # Data frame or list looks like: 53 | # 54 | # { 55 | # "Series A": [1,2,3,4,5], 56 | # "Series B": [6,7,8,9,10] 57 | # } 58 | # 59 | # D3 expects: 60 | # 61 | # [ 62 | # { 63 | # key: "Series A", 64 | # values: [{x:1,y:1}, {x:2,y:2}, {x:3,y:3}, {x:4,y:4}, {x:5,y:5}] 65 | # }, 66 | # { 67 | # key: "Series B", 68 | # values: [{x:1,y:6}, {x:2,y:7}, {x:3,y:8}, {x:4,y:9}, {x:5,y:10}] 69 | # } 70 | # ] -------------------------------------------------------------------------------- /rsconnect/shinyapps.io/ksmzn/statdist.dcf: -------------------------------------------------------------------------------- 1 | name: statdist 2 | account: ksmzn 3 | bundleId: 161364 4 | url: http://ksmzn.shinyapps.io/statdist 5 | server: shinyapps.io 6 | -------------------------------------------------------------------------------- /ui.R: -------------------------------------------------------------------------------- 1 | library(shiny) 2 | library(shinydashboard) 3 | library(rmarkdown) 4 | 5 | pageTitle <- "Probability Distributions Viewer" 6 | sidebarWidth <- 300 7 | 8 | # CSS Files 9 | cssFiles <- tags$head( 10 | tags$link(rel = "stylesheet", type = "text/css", href = "css/main.css") 11 | ) 12 | # JavaScript Files 13 | jsFiles <- tags$head( 14 | tags$script(src = "js/google-analytics.js") 15 | ) 16 | 17 | #################################################### 18 | # UI ---- 19 | #################################################### 20 | header <- dashboardHeader( 21 | title = pageTitle, 22 | titleWidth = sidebarWidth, 23 | .list = list( 24 | tags$li( 25 | class = "dropdown dummy", 26 | bookmarkButton() 27 | ), 28 | tags$li( 29 | class = "dropdown dummy", 30 | uiOutput("language_selector") 31 | ) 32 | ) 33 | ) 34 | 35 | sidebar <- dashboardSidebar( 36 | width = sidebarWidth, 37 | sidebarMenuOutput("sidebar_menu") 38 | ) 39 | 40 | board.about <- tabItem( 41 | tabName = "about", 42 | uiOutput("about") 43 | ) 44 | #################################################### 45 | # Tab Items for Distributions ---- 46 | #################################################### 47 | # 連続分布 ---- 48 | ## Normal 49 | board.norm <- distTabUI(norm) 50 | board.erlang <- distTabUI(erlang) 51 | board.f <- distTabUI(f) 52 | board.ncf <- distTabUI(ncf, wide = T) 53 | board.chisq <- distTabUI(chisq) 54 | board.ncChisq <- distTabUI(ncChisq) 55 | board.gamma <- distTabUI(gamma) 56 | board.cauchy <- distTabUI(cauchy) 57 | board.exp_dist <- distTabUI(exp_dist) 58 | board.lnormal <- distTabUI(lnormal) 59 | board.t_dist <- distTabUI(t_dist) 60 | board.nct <- distTabUI(nct, wide = T) 61 | board.beta <- distTabUI(beta) 62 | board.ncbeta <- distTabUI(ncbeta, wide = T) 63 | board.unif <- distTabUI(unif) 64 | board.logis <- distTabUI(logis) 65 | board.weibull <- distTabUI(weibull, wide = T) 66 | # 離散分布 67 | board.geom <- distTabUI(geom) 68 | board.hyper <- distTabUI(hyper) 69 | board.binom <- distTabUI(binom) 70 | board.nbinom <- distTabUI(nbinom) 71 | board.pois <- distTabUI(pois) 72 | board.dunif <- distTabUI(dunif) 73 | 74 | body <- dashboardBody( 75 | cssFiles, 76 | jsFiles, 77 | tabItems( 78 | # Continuous 79 | board.norm, 80 | board.erlang, 81 | board.f, 82 | board.ncf, 83 | board.chisq, 84 | board.ncChisq, 85 | board.gamma, 86 | board.cauchy, 87 | board.exp_dist, 88 | board.lnormal, 89 | board.t_dist, 90 | board.nct, 91 | board.beta, 92 | board.ncbeta, 93 | board.unif, 94 | board.logis, 95 | board.weibull, 96 | # Discrete 97 | board.geom, 98 | board.hyper, 99 | board.binom, 100 | board.nbinom, 101 | board.pois, 102 | board.dunif, 103 | # About 104 | board.about 105 | ) 106 | ) 107 | 108 | ui <- function(req) { 109 | dashboardPage(header, sidebar, body) 110 | } -------------------------------------------------------------------------------- /utils/all.R: -------------------------------------------------------------------------------- 1 | # Read all R files 2 | source("utils/bookmark.R") 3 | -------------------------------------------------------------------------------- /www/css/main.css: -------------------------------------------------------------------------------- 1 | .wrapper { 2 | overflow-y: hidden; 3 | } 4 | .dummy { 5 | padding: 7px 15px 0 0; 6 | } 7 | #language_selector > .form-group { 8 | margin-bottom: 0px; 9 | } 10 | #language_selector .selectize-control { 11 | margin-bottom: 0px; 12 | } 13 | 14 | .btn-twitter { 15 | text-align: left; 16 | float: left; 17 | } 18 | -------------------------------------------------------------------------------- /www/img/external.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksmzn/ProbabilityDistributionsViewer/ba24761a890e7d4f06f180316ca088d8210c4940/www/img/external.png -------------------------------------------------------------------------------- /www/js/google-analytics.js: -------------------------------------------------------------------------------- 1 | // Initial Tracking Code 2 | (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 3 | (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 4 | m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) 5 | })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); 6 | (function(){ 7 | var uaid = ''; 8 | var domain = 'statdist.ksmzn.com'; 9 | 10 | if (location.host == domain){ 11 | uaid = 'UA-12393166-9'; 12 | }else{ 13 | uaid = 'UA-12393166-8'; 14 | } 15 | 16 | ga('create', uaid, 'auto'); 17 | ga('send', 'pageview'); 18 | })(); 19 | 20 | // Event Tracking Code 21 | $(document).on('shiny:inputchanged', function(event) { 22 | if(['selected_language', 'tabs'].indexOf(event.name) >= 0 && event.value !== null){ 23 | ga('send', 'event', 'input', 24 | 'updates', event.name, event.value); 25 | } 26 | }) 27 | -------------------------------------------------------------------------------- /www/js/linechart-binding.js: -------------------------------------------------------------------------------- 1 | // Put code in an Immediately Invoked Function Expression (IIFE). 2 | // This isn't strictly necessary, but it's good JavaScript hygiene. 3 | (function() { 4 | 5 | // See http://rstudio.github.io/shiny/tutorial/#building-outputs for 6 | // more information on creating output bindings. 7 | 8 | // First create a generic output binding instance, then overwrite 9 | // specific methods whose behavior we want to change. 10 | var binding = new Shiny.OutputBinding(); 11 | 12 | binding.find = function(scope) { 13 | // For the given scope, return the set of elements that belong to 14 | // this binding. 15 | return $(scope).find(".nvd3-linechart"); 16 | }; 17 | 18 | binding.renderValue = function(el, data) { 19 | // This function will be called every time we receive new output 20 | // values for a line chart from Shiny. The "el" argument is the 21 | // div for this particular chart. 22 | 23 | var $el = $(el); 24 | 25 | // The first time we render a value for a particular element, we 26 | // need to initialize the nvd3 line chart and d3 selection. We'll 27 | // store these on $el as a data value called "state". 28 | if (!$el.data("state")) { 29 | var chart = nv.models.lineChart() 30 | .margin({left: 100}) 31 | .useInteractiveGuideline(true) 32 | // .transitionDuration(350) 33 | .showLegend(false) 34 | .showYAxis(true) 35 | .showXAxis(true); 36 | 37 | chart.xAxis //Chart x-axis settings 38 | .axisLabel('X') 39 | .tickFormat(d3.format('.01f')); 40 | 41 | chart.yAxis //Chart y-axis settings 42 | .axisLabel('P') 43 | .tickFormat(d3.format('.02f')); 44 | 45 | nv.utils.windowResize(chart.update); 46 | 47 | var selection = d3.select(el).select("svg"); 48 | 49 | // Store the chart object on el so we can get it next time 50 | $el.data("state", { 51 | chart: chart, 52 | selection: selection 53 | }); 54 | } 55 | 56 | // Now, the code that'll run every time a value is rendered... 57 | 58 | // Retrieve the chart and selection we created earlier 59 | var state = $el.data("state"); 60 | 61 | // Schedule some work with nvd3 62 | nv.addGraph(function() { 63 | // Update the chart 64 | state.selection 65 | .datum(data) 66 | .transition(500) 67 | .call(state.chart); 68 | return state.chart; 69 | }); 70 | }; 71 | 72 | // Tell Shiny about our new output binding 73 | Shiny.outputBindings.register(binding, "stat_dist.nvd3-linechart"); 74 | 75 | })(); 76 | -------------------------------------------------------------------------------- /www/js/nvd3/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Jekyll Files # 3 | ################ 4 | _site 5 | 6 | 7 | # Random Files # 8 | ################ 9 | *.swp 10 | *~ 11 | *.log 12 | 13 | 14 | # Private Test Data # 15 | ##################### 16 | *REALDATA* 17 | 18 | 19 | # OS generated files # 20 | ###################### 21 | .DS_Store* 22 | ehthumbs.db 23 | Icon? 24 | Thumbs.db 25 | # nodejs packages # 26 | ###################### 27 | node_modules 28 | -------------------------------------------------------------------------------- /www/js/nvd3/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "asi": true 3 | } 4 | -------------------------------------------------------------------------------- /www/js/nvd3/GruntFile.js: -------------------------------------------------------------------------------- 1 | module.exports = function(grunt) { 2 | 3 | //Project configuration. 4 | grunt.initConfig({ 5 | pkg: grunt.file.readJSON('package.json'), 6 | concat: { 7 | options: { 8 | separator: '' 9 | }, 10 | dist: { 11 | src: [ 12 | 'src/intro.js', 13 | 'src/core.js', 14 | 'src/interactiveLayer.js', 15 | 'src/tooltip.js', 16 | 'src/utils.js', 17 | 'src/models/axis.js', 18 | 'src/models/historicalBar.js', 19 | 'src/models/bullet.js', 20 | 'src/models/bulletChart.js', 21 | 'src/models/cumulativeLineChart.js', 22 | 'src/models/discreteBar.js', 23 | 'src/models/discreteBarChart.js', 24 | 'src/models/distribution.js', 25 | 'src/models/historicalBar.js', 26 | 'src/models/historicalBarChart.js', 27 | 'src/models/indentedTree.js', 28 | 'src/models/legend.js', 29 | 'src/models/line.js', 30 | 'src/models/lineChart.js', 31 | 'src/models/linePlusBarChart.js', 32 | 'src/models/lineWithFocusChart.js', 33 | 'src/models/linePlusBarWithFocusChart.js', 34 | 'src/models/multiBar.js', 35 | 'src/models/multiBarChart.js', 36 | 'src/models/multiBarHorizontal.js', 37 | 'src/models/multiBarHorizontalChart.js', 38 | 'src/models/multiChart.js', 39 | 'src/models/ohlcBar.js', 40 | 'src/models/pie.js', 41 | 'src/models/pieChart.js', 42 | 'src/models/scatter.js', 43 | 'src/models/scatterChart.js', 44 | 'src/models/scatterPlusLineChart.js', 45 | 'src/models/sparkline.js', 46 | 'src/models/sparklinePlus.js', 47 | 'src/models/stackedArea.js', 48 | 'src/models/stackedAreaChart.js', 49 | 'src/outro.js' 50 | ], 51 | dest: 'nv.d3.js' 52 | } 53 | }, 54 | uglify: { 55 | options: { 56 | banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' + 57 | '<%= grunt.template.today("yyyy-mm-dd") %> */' 58 | }, 59 | js: { 60 | files: { 61 | 'nv.d3.min.js': ['nv.d3.js'] 62 | } 63 | } 64 | }, 65 | jshint: { 66 | foo: { 67 | src: "src/**/*.js" 68 | }, 69 | options: { 70 | jshintrc: '.jshintrc' 71 | } 72 | }, 73 | watch: { 74 | js: { 75 | files: ["src/**/*.js"], 76 | tasks: ['concat'] 77 | } 78 | }, 79 | copy: { 80 | css: { 81 | files: [ 82 | { src: 'src/nv.d3.css', dest: 'nv.d3.css' } 83 | ] 84 | } 85 | }, 86 | cssmin: { 87 | dist: { 88 | files: { 89 | 'nv.d3.min.css' : ['nv.d3.css'] 90 | } 91 | } 92 | } 93 | }); 94 | 95 | grunt.loadNpmTasks('grunt-contrib-watch'); 96 | grunt.loadNpmTasks('grunt-contrib-concat'); 97 | grunt.loadNpmTasks('grunt-contrib-jshint'); 98 | grunt.loadNpmTasks('grunt-contrib-uglify'); 99 | grunt.loadNpmTasks('grunt-contrib-copy'); 100 | grunt.loadNpmTasks('grunt-contrib-cssmin'); 101 | 102 | grunt.registerTask('default', ['concat', 'copy']); 103 | grunt.registerTask('production', ['concat', 'uglify', 'copy', 'cssmin']); 104 | grunt.registerTask('release', ['production']); 105 | grunt.registerTask('lint', ['jshint']); 106 | }; 107 | -------------------------------------------------------------------------------- /www/js/nvd3/LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | ##nvd3.js License 3 | 4 | Copyright (c) 2011, 2012 [Novus Partners, Inc.][novus] 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | 18 | [novus]: https://www.novus.com/ 19 | 20 | 21 | 22 | ##d3.js License 23 | 24 | Copyright (c) 2012, Michael Bostock 25 | All rights reserved. 26 | 27 | Redistribution and use in source and binary forms, with or without 28 | modification, are permitted provided that the following conditions are met: 29 | 30 | * Redistributions of source code must retain the above copyright notice, this 31 | list of conditions and the following disclaimer. 32 | 33 | * Redistributions in binary form must reproduce the above copyright notice, 34 | this list of conditions and the following disclaimer in the documentation 35 | and/or other materials provided with the distribution. 36 | 37 | * The name Michael Bostock may not be used to endorse or promote products 38 | derived from this software without specific prior written permission. 39 | 40 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 41 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 43 | DISCLAIMED. IN NO EVENT SHALL MICHAEL BOSTOCK BE LIABLE FOR ANY DIRECT, 44 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 45 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 46 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 47 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 48 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 49 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 50 | -------------------------------------------------------------------------------- /www/js/nvd3/Makefile: -------------------------------------------------------------------------------- 1 | JS_FILES = \ 2 | src/intro.js \ 3 | src/core.js \ 4 | src/interactiveLayer.js \ 5 | src/tooltip.js \ 6 | src/utils.js \ 7 | src/models/axis.js \ 8 | src/models/bullet.js \ 9 | src/models/bulletChart.js \ 10 | src/models/cumulativeLineChart.js \ 11 | src/models/discreteBar.js \ 12 | src/models/discreteBarChart.js \ 13 | src/models/distribution.js \ 14 | src/models/historicalBar.js \ 15 | src/models/historicalBarChart.js \ 16 | src/models/indentedTree.js \ 17 | src/models/legend.js \ 18 | src/models/line.js \ 19 | src/models/lineChart.js \ 20 | src/models/linePlusBarChart.js \ 21 | src/models/lineWithFocusChart.js \ 22 | src/models/linePlusBarWithFocusChart.js \ 23 | src/models/multiBar.js \ 24 | src/models/multiBarChart.js \ 25 | src/models/multiBarHorizontal.js \ 26 | src/models/multiBarHorizontalChart.js \ 27 | src/models/multiChart.js \ 28 | src/models/ohlcBar.js \ 29 | src/models/pie.js \ 30 | src/models/pieChart.js \ 31 | src/models/scatter.js \ 32 | src/models/scatterChart.js \ 33 | src/models/scatterPlusLineChart.js \ 34 | src/models/sparkline.js \ 35 | src/models/sparklinePlus.js \ 36 | src/models/stackedArea.js \ 37 | src/models/stackedAreaChart.js \ 38 | src/outro.js 39 | CSS_FILES = \ 40 | src/nv.d3.css 41 | 42 | JS_COMPILER = \ 43 | uglifyjs 44 | 45 | CSS_COMPILER = \ 46 | cssmin 47 | 48 | all: nv.d3.js nv.d3.min.js nv.d3.css nv.d3.min.css 49 | nv.d3.js: $(JS_FILES) 50 | nv.d3.min.js: $(JS_FILES) 51 | nv.d3.css: $(CSS_FILES) 52 | nv.d3.min.css: $(CSS_FILES) 53 | 54 | nv.d3.js: Makefile 55 | rm -f $@ 56 | cat $(filter %.js,$^) >> $@ 57 | 58 | nv.d3.css: Makefile 59 | rm -f $@ 60 | cat $(filter %.css,$^) >> $@ 61 | 62 | %.min.js:: Makefile 63 | rm -f $@ 64 | $(JS_COMPILER) nv.d3.js >> $@ 65 | 66 | %.min.css:: Makefile 67 | rm -f $@ 68 | $(CSS_COMPILER) nv.d3.css >> $@ 69 | 70 | 71 | clean: 72 | rm -rf nv.d3*.js nv.d3*.css 73 | -------------------------------------------------------------------------------- /www/js/nvd3/README.md: -------------------------------------------------------------------------------- 1 | # NVD3 - v1.1.15-beta 2 | ## Release notes for version 1.1.15 beta 3 | * Various fixes across the board 4 | 5 | ## Overview 6 | A reusable chart library for d3.js. 7 | 8 | NVD3 may change from its current state, but will always try to follow the style of d3.js. 9 | 10 | You can also check out the [examples page](http://nvd3.org/ghpages/examples.html). 11 | **Note:** The examples on nvd3.org are outdated. For examples on how to use the latest NVD3, please checkout the **examples/** directory in the repository. 12 | 13 | --- 14 | 15 | # Current development focus 16 | 17 | - Getting documentation up. 18 | - Unifying common API functions between charts. 19 | - Bug fixes that come up. 20 | 21 | --- 22 | 23 | # Installation Instructions 24 | 25 | `d3.v3.js` is a dependency of `nv.d3.js`. Be sure to include in in your project, then: 26 | Add a script tag to include `nv.d3.js` OR `nv.d3.min.js` in your project. 27 | Also add a link to the `nv.d3.css` file. 28 | 29 | See wiki -> Documentation for more detail 30 | 31 | --- 32 | 33 | If one of [the existing models](https://github.com/novus/nvd3/tree/master/src/models) doesn't meet your needs, fork the project, implement the model and an example using it, send us a pull request, for consideration for inclusion in the project. 34 | 35 | We cannot honor all pull requests, but we will review all of them. 36 | 37 | Please do not aggregate pull requests. Aggregated pull requests are actually more difficult to review. 38 | 39 | We are currently changing our branch structure so that master will be gauranteed stable. In addition, there is now a "development" branch. This branch reflects the latest changes to NVD3 and is not necessarily stable. 40 | 41 | --- 42 | 43 | ## Minifying your fork: 44 | 45 | ### Using Make 46 | The Makefile requires [UglifyJS](https://github.com/mishoo/UglifyJS) and [CSSMin](https://github.com/jbleuzen/node-cssmin) 47 | 48 | The easiest way to install UglifyJS and CSSMin is via npm. Run `npm install -g uglify-js cssmin`. After installing verify the setup by running `uglifyjs --version` and `cssmin --help`. 49 | 50 | Once you have the `uglifyjs` and `cssmin` commands available, running `make` from your 51 | fork's root directory will rebuild both `nv.d3.js` and `nv.d3.min.js`. 52 | 53 | make # build nv.d3.js and nv.d3.css and minify 54 | make nv.d3.js # Build nv.d3.js 55 | make nv.d3.min.js # Minify nv.d3.js into nv.d3.min.js 56 | make nv.d3.css # Build nv.d3.css 57 | make nv.d3.min.css # Minify nv.d3.css into nv.d3.min.css 58 | make clean # Delete nv.d3.*js and nv.d3.*css 59 | 60 | 61 | *Without UglifyJS of CSSMin, you won't get the minified versions when running make.** 62 | 63 | ### Using Grunt 64 | 65 | You can use grunt instead of makefile to build js file. See more about [grunt](http://gruntjs.com/). 66 | ***[Nodejs](http://nodejs.org/) must be installed before you can use grunt.*** 67 | Run `npm install` in root dir to install grunt and it's dependencies. 68 | 69 | Then, you can use these commands: 70 | 71 | grunt # build nv.d3.js 72 | grunt production # build nv.d3.js and nv.d3.min.js 73 | grunt watch # watch file changes in src/, and rebuild nv.d3.js, it's very helpful when delevop NVD3 74 | grunt lint # run jshint on src/**/*.js 75 | 76 | **We ask that you DO NOT minify pull requests... 77 | If you need to minify please build pull request in separate branch, and 78 | merge and minify in your master. 79 | 80 | ## Supported Browsers 81 | NVD3 runs best on WebKit based browsers. 82 | 83 | * **Google Chrome: latest version (preferred)** 84 | * **Opera 15+ (preferred)** 85 | * Safari: latest version 86 | * Firefox: latest version 87 | * Internet Explorer: 9 and 10 88 | -------------------------------------------------------------------------------- /www/js/nvd3/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nvd3", 3 | "version": "1.1.15-beta", 4 | "homepage": "http://www.nvd3.org", 5 | "authors": [ 6 | "Bob Monteverde", 7 | "Tyler Wolf", 8 | "Robin Hu", 9 | "Frank Shao" 10 | ], 11 | "description": "Re-usable charts and chart components for d3.", 12 | "main": ["nv.d3.js", "src/nv.d3.css"], 13 | "keywords": [ 14 | "d3", 15 | "visualization", 16 | "svg", 17 | "charts" 18 | ], 19 | "license": "Apache License, v2.0", 20 | "dependencies": { 21 | "d3": "~3.3.13" 22 | }, 23 | "ignore" : [ 24 | "**/.*", 25 | "node_modules", 26 | "bower_components", 27 | "test", 28 | "tests", 29 | "src/models/*", 30 | "src/*.js", 31 | "lib", 32 | "examples", 33 | "deprecated" 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /www/js/nvd3/build.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | copy src\intro.js /B + src\core.js /B + src\tooltip.js /B temp1.js /B 3 | copy src\models\*.js /B temp2.js /B 4 | copy temp1.js /B + temp2.js /B + src\outro.js /B nv.d3.js /B 5 | del temp1.js 6 | del temp2.js 7 | -------------------------------------------------------------------------------- /www/js/nvd3/deprecated/discreteBarChartWithEnabledTooltip.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 42 | 43 |
44 | 45 |
46 | 47 |
48 | 49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 129 | -------------------------------------------------------------------------------- /www/js/nvd3/deprecated/lineChart-old.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 29 | 30 | 31 |
32 |
33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 84 | -------------------------------------------------------------------------------- /www/js/nvd3/deprecated/lineWithFocus.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 18 | 19 | 20 |
21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 138 | -------------------------------------------------------------------------------- /www/js/nvd3/deprecated/lineWithLegend.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 33 | 34 | 35 |
36 |
37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 143 | -------------------------------------------------------------------------------- /www/js/nvd3/deprecated/monthendAxis.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 100 | -------------------------------------------------------------------------------- /www/js/nvd3/deprecated/scatterChart.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 40 | 41 | 42 | 43 |
44 |
45 | 46 |
47 |
48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 111 | -------------------------------------------------------------------------------- /www/js/nvd3/deprecated/scatterWithLegend.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 34 | 35 | 36 | 37 |
38 |
39 | 40 |
41 |
42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 168 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/bullet.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 |




14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 98 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/bulletChart.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 14 |




15 | 16 | Normal Bullet Chart 17 | 18 | 19 | Bullet Chart with Custom Labels 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 117 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/crossfilter.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 33 | 34 | 35 |
36 | 37 |
38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 168 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/discreteBarChart.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 33 | 34 | 35 |
36 | 37 |
38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 118 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/historicalBar.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 159 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/historicalBarChart.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | 17 |
18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 107 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/images/grey-minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksmzn/ProbabilityDistributionsViewer/ba24761a890e7d4f06f180316ca088d8210c4940/www/js/nvd3/examples/images/grey-minus.png -------------------------------------------------------------------------------- /www/js/nvd3/examples/images/grey-plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksmzn/ProbabilityDistributionsViewer/ba24761a890e7d4f06f180316ca088d8210c4940/www/js/nvd3/examples/images/grey-plus.png -------------------------------------------------------------------------------- /www/js/nvd3/examples/images/nvd3_sampleLineChart1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksmzn/ProbabilityDistributionsViewer/ba24761a890e7d4f06f180316ca088d8210c4940/www/js/nvd3/examples/images/nvd3_sampleLineChart1.png -------------------------------------------------------------------------------- /www/js/nvd3/examples/indentedtree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 | 128 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | NVD3 Examples List 4 | 5 | 48 |

NVD3 Examples List

49 | 70 | 86 | 87 | 97 | 98 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/legend.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 77 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/line.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 97 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/lineChart.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 37 | 38 | 39 |
40 | 41 |
42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 133 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/lineChartSVGResize.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 21 | 22 |
23 | Zoom In Zoom Out 24 |
25 | 26 |
27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 152 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/lineWithFisheyeChart.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 33 | 34 | 35 |
36 | 37 |
38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 102 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/lineWithFocusChart.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 33 | 34 | 35 |
36 | 37 |
38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 88 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/multiBar.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 18 | 19 | 20 |
21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 95 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/multiBarChart.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 29 | 30 | 31 |
32 | 33 |
34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 106 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/multiChart.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 30 | 31 | 32 |
33 | 34 |
35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 96 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/pie.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 95 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/pieChart.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 20 | 21 |

Test1

22 | 23 | 24 |

Test2

25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 123 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/scatter.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 97 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/scatterChart.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 40 | 41 | 42 | 43 |
44 |
45 | 46 |
47 |
48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 119 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/scatterPlusLineChart.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 40 | 41 | 42 | 43 |
44 |
45 | 46 |
47 |
48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 116 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/sparkline.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | 22 | 23 |

Sparkline:

24 | 25 | 26 | 27 | 28 | 29 | 63 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/sparklinePlus.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | 17 |

SparklinePlus:

18 |

19 |
20 |

APPL:

21 | 22 |

GOOG:

23 | 24 | 25 | 26 | 27 | 28 | 29 | 87 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/stackedArea.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 |
20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 | 157 | -------------------------------------------------------------------------------- /www/js/nvd3/examples/stream_layers.js: -------------------------------------------------------------------------------- 1 | 2 | /* Inspired by Lee Byron's test data generator. */ 3 | function stream_layers(n, m, o) { 4 | if (arguments.length < 3) o = 0; 5 | function bump(a) { 6 | var x = 1 / (.1 + Math.random()), 7 | y = 2 * Math.random() - .5, 8 | z = 10 / (.1 + Math.random()); 9 | for (var i = 0; i < m; i++) { 10 | var w = (i / m - y) * z; 11 | a[i] += x * Math.exp(-w * w); 12 | } 13 | } 14 | return d3.range(n).map(function() { 15 | var a = [], i; 16 | for (i = 0; i < m; i++) a[i] = o + o * Math.random(); 17 | for (i = 0; i < 5; i++) bump(a); 18 | return a.map(stream_index); 19 | }); 20 | } 21 | 22 | /* Another layer generator using gamma distributions. */ 23 | function stream_waves(n, m) { 24 | return d3.range(n).map(function(i) { 25 | return d3.range(m).map(function(j) { 26 | var x = 20 * j / m - i / 3; 27 | return 2 * x * Math.exp(-.5 * x); 28 | }).map(stream_index); 29 | }); 30 | } 31 | 32 | function stream_index(d, i) { 33 | return {x: i, y: Math.max(0, d)}; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /www/js/nvd3/lib/fisheye.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | d3.fisheye = { 3 | scale: function(scaleType) { 4 | return d3_fisheye_scale(scaleType(), 3, 0); 5 | }, 6 | circular: function() { 7 | var radius = 200, 8 | distortion = 2, 9 | k0, 10 | k1, 11 | focus = [0, 0]; 12 | 13 | function fisheye(d) { 14 | var dx = d.x - focus[0], 15 | dy = d.y - focus[1], 16 | dd = Math.sqrt(dx * dx + dy * dy); 17 | if (!dd || dd >= radius) return {x: d.x, y: d.y, z: 1}; 18 | var k = k0 * (1 - Math.exp(-dd * k1)) / dd * .75 + .25; 19 | return {x: focus[0] + dx * k, y: focus[1] + dy * k, z: Math.min(k, 10)}; 20 | } 21 | 22 | function rescale() { 23 | k0 = Math.exp(distortion); 24 | k0 = k0 / (k0 - 1) * radius; 25 | k1 = distortion / radius; 26 | return fisheye; 27 | } 28 | 29 | fisheye.radius = function(_) { 30 | if (!arguments.length) return radius; 31 | radius = +_; 32 | return rescale(); 33 | }; 34 | 35 | fisheye.distortion = function(_) { 36 | if (!arguments.length) return distortion; 37 | distortion = +_; 38 | return rescale(); 39 | }; 40 | 41 | fisheye.focus = function(_) { 42 | if (!arguments.length) return focus; 43 | focus = _; 44 | return fisheye; 45 | }; 46 | 47 | return rescale(); 48 | } 49 | }; 50 | 51 | function d3_fisheye_scale(scale, d, a) { 52 | 53 | function fisheye(_) { 54 | var x = scale(_), 55 | left = x < a, 56 | v, 57 | range = d3.extent(scale.range()), 58 | min = range[0], 59 | max = range[1], 60 | m = left ? a - min : max - a; 61 | if (m == 0) m = max - min; 62 | return (left ? -1 : 1) * m * (d + 1) / (d + (m / Math.abs(x - a))) + a; 63 | } 64 | 65 | fisheye.distortion = function(_) { 66 | if (!arguments.length) return d; 67 | d = +_; 68 | return fisheye; 69 | }; 70 | 71 | fisheye.focus = function(_) { 72 | if (!arguments.length) return a; 73 | a = +_; 74 | return fisheye; 75 | }; 76 | 77 | fisheye.copy = function() { 78 | return d3_fisheye_scale(scale.copy(), d, a); 79 | }; 80 | 81 | fisheye.nice = scale.nice; 82 | fisheye.ticks = scale.ticks; 83 | fisheye.tickFormat = scale.tickFormat; 84 | return d3.rebind(fisheye, scale, "domain", "range"); 85 | } 86 | })(); 87 | -------------------------------------------------------------------------------- /www/js/nvd3/lib/hive.js: -------------------------------------------------------------------------------- 1 | d3.hive = {}; 2 | 3 | d3.hive.link = function() { 4 | var source = function(d) { return d.source; }, 5 | target = function(d) { return d.target; }, 6 | angle = function(d) { return d.angle; }, 7 | startRadius = function(d) { return d.radius; }, 8 | endRadius = startRadius, 9 | arcOffset = -Math.PI / 2; 10 | 11 | function link(d, i) { 12 | var s = node(source, this, d, i), 13 | t = node(target, this, d, i), 14 | x; 15 | if (t.a < s.a) x = t, t = s, s = x; 16 | if (t.a - s.a > Math.PI) s.a += 2 * Math.PI; 17 | var a1 = s.a + (t.a - s.a) / 3, 18 | a2 = t.a - (t.a - s.a) / 3; 19 | return s.r0 - s.r1 || t.r0 - t.r1 20 | ? "M" + Math.cos(s.a) * s.r0 + "," + Math.sin(s.a) * s.r0 21 | + "L" + Math.cos(s.a) * s.r1 + "," + Math.sin(s.a) * s.r1 22 | + "C" + Math.cos(a1) * s.r1 + "," + Math.sin(a1) * s.r1 23 | + " " + Math.cos(a2) * t.r1 + "," + Math.sin(a2) * t.r1 24 | + " " + Math.cos(t.a) * t.r1 + "," + Math.sin(t.a) * t.r1 25 | + "L" + Math.cos(t.a) * t.r0 + "," + Math.sin(t.a) * t.r0 26 | + "C" + Math.cos(a2) * t.r0 + "," + Math.sin(a2) * t.r0 27 | + " " + Math.cos(a1) * s.r0 + "," + Math.sin(a1) * s.r0 28 | + " " + Math.cos(s.a) * s.r0 + "," + Math.sin(s.a) * s.r0 29 | : "M" + Math.cos(s.a) * s.r0 + "," + Math.sin(s.a) * s.r0 30 | + "C" + Math.cos(a1) * s.r1 + "," + Math.sin(a1) * s.r1 31 | + " " + Math.cos(a2) * t.r1 + "," + Math.sin(a2) * t.r1 32 | + " " + Math.cos(t.a) * t.r1 + "," + Math.sin(t.a) * t.r1; 33 | } 34 | 35 | function node(method, thiz, d, i) { 36 | var node = method.call(thiz, d, i), 37 | a = +(typeof angle === "function" ? angle.call(thiz, node, i) : angle) + arcOffset, 38 | r0 = +(typeof startRadius === "function" ? startRadius.call(thiz, node, i) : startRadius), 39 | r1 = (startRadius === endRadius ? r0 : +(typeof endRadius === "function" ? endRadius.call(thiz, node, i) : endRadius)); 40 | return {r0: r0, r1: r1, a: a}; 41 | } 42 | 43 | link.source = function(_) { 44 | if (!arguments.length) return source; 45 | source = _; 46 | return link; 47 | }; 48 | 49 | link.target = function(_) { 50 | if (!arguments.length) return target; 51 | target = _; 52 | return link; 53 | }; 54 | 55 | link.angle = function(_) { 56 | if (!arguments.length) return angle; 57 | angle = _; 58 | return link; 59 | }; 60 | 61 | link.radius = function(_) { 62 | if (!arguments.length) return startRadius; 63 | startRadius = endRadius = _; 64 | return link; 65 | }; 66 | 67 | link.startRadius = function(_) { 68 | if (!arguments.length) return startRadius; 69 | startRadius = _; 70 | return link; 71 | }; 72 | 73 | link.endRadius = function(_) { 74 | if (!arguments.length) return endRadius; 75 | endRadius = _; 76 | return link; 77 | }; 78 | 79 | return link; 80 | }; 81 | -------------------------------------------------------------------------------- /www/js/nvd3/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nvd3", 3 | "version": "0.0.1", 4 | "devDependencies": { 5 | "grunt": "~0.4.1", 6 | "grunt-contrib-jshint": "~0.3.0", 7 | "grunt-contrib-watch": "~0.3.1", 8 | "grunt-contrib-uglify": "~0.2.0", 9 | "grunt-contrib-concat": "~0.2.0", 10 | "grunt-contrib-copy": "~0.4.1", 11 | "grunt-contrib-cssmin": "~0.6.2" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /www/js/nvd3/src/core.js: -------------------------------------------------------------------------------- 1 | 2 | var nv = window.nv || {}; 3 | 4 | 5 | nv.version = '1.1.15b'; 6 | nv.dev = true //set false when in production 7 | 8 | window.nv = nv; 9 | 10 | nv.tooltip = nv.tooltip || {}; // For the tooltip system 11 | nv.utils = nv.utils || {}; // Utility subsystem 12 | nv.models = nv.models || {}; //stores all the possible models/components 13 | nv.charts = {}; //stores all the ready to use charts 14 | nv.graphs = []; //stores all the graphs currently on the page 15 | nv.logs = {}; //stores some statistics and potential error messages 16 | 17 | nv.dispatch = d3.dispatch('render_start', 'render_end'); 18 | 19 | // ************************************************************************* 20 | // Development render timers - disabled if dev = false 21 | 22 | if (nv.dev) { 23 | nv.dispatch.on('render_start', function(e) { 24 | nv.logs.startTime = +new Date(); 25 | }); 26 | 27 | nv.dispatch.on('render_end', function(e) { 28 | nv.logs.endTime = +new Date(); 29 | nv.logs.totalTime = nv.logs.endTime - nv.logs.startTime; 30 | nv.log('total', nv.logs.totalTime); // used for development, to keep track of graph generation times 31 | }); 32 | } 33 | 34 | // ******************************************** 35 | // Public Core NV functions 36 | 37 | // Logs all arguments, and returns the last so you can test things in place 38 | // Note: in IE8 console.log is an object not a function, and if modernizr is used 39 | // then calling Function.prototype.bind with with anything other than a function 40 | // causes a TypeError to be thrown. 41 | nv.log = function() { 42 | if (nv.dev && console.log && console.log.apply) 43 | console.log.apply(console, arguments) 44 | else if (nv.dev && typeof console.log == "function" && Function.prototype.bind) { 45 | var log = Function.prototype.bind.call(console.log, console); 46 | log.apply(console, arguments); 47 | } 48 | return arguments[arguments.length - 1]; 49 | }; 50 | 51 | 52 | nv.render = function render(step) { 53 | step = step || 1; // number of graphs to generate in each timeout loop 54 | 55 | nv.render.active = true; 56 | nv.dispatch.render_start(); 57 | 58 | setTimeout(function() { 59 | var chart, graph; 60 | 61 | for (var i = 0; i < step && (graph = nv.render.queue[i]); i++) { 62 | chart = graph.generate(); 63 | if (typeof graph.callback == typeof(Function)) graph.callback(chart); 64 | nv.graphs.push(chart); 65 | } 66 | 67 | nv.render.queue.splice(0, i); 68 | 69 | if (nv.render.queue.length) setTimeout(arguments.callee, 0); 70 | else { 71 | nv.dispatch.render_end(); 72 | nv.render.active = false; 73 | } 74 | }, 0); 75 | }; 76 | 77 | nv.render.active = false; 78 | nv.render.queue = []; 79 | 80 | nv.addGraph = function(obj) { 81 | if (typeof arguments[0] === typeof(Function)) 82 | obj = {generate: arguments[0], callback: arguments[1]}; 83 | 84 | nv.render.queue.push(obj); 85 | 86 | if (!nv.render.active) nv.render(); 87 | }; 88 | 89 | nv.identity = function(d) { return d; }; 90 | 91 | nv.strip = function(s) { return s.replace(/(\s|&)/g,''); }; 92 | 93 | function daysInMonth(month,year) { 94 | return (new Date(year, month+1, 0)).getDate(); 95 | } 96 | 97 | function d3_time_range(floor, step, number) { 98 | return function(t0, t1, dt) { 99 | var time = floor(t0), times = []; 100 | if (time < t0) step(time); 101 | if (dt > 1) { 102 | while (time < t1) { 103 | var date = new Date(+time); 104 | if ((number(date) % dt === 0)) times.push(date); 105 | step(time); 106 | } 107 | } else { 108 | while (time < t1) { times.push(new Date(+time)); step(time); } 109 | } 110 | return times; 111 | }; 112 | } 113 | 114 | d3.time.monthEnd = function(date) { 115 | return new Date(date.getFullYear(), date.getMonth(), 0); 116 | }; 117 | 118 | d3.time.monthEnds = d3_time_range(d3.time.monthEnd, function(date) { 119 | date.setUTCDate(date.getUTCDate() + 1); 120 | date.setDate(daysInMonth(date.getMonth() + 1, date.getFullYear())); 121 | }, function(date) { 122 | return date.getMonth(); 123 | } 124 | ); 125 | 126 | -------------------------------------------------------------------------------- /www/js/nvd3/src/intro.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | -------------------------------------------------------------------------------- /www/js/nvd3/src/models/boilerplate.js: -------------------------------------------------------------------------------- 1 | 2 | nv.models.chartName = function() { 3 | "use strict"; 4 | //============================================================ 5 | // Public Variables with Default Settings 6 | //------------------------------------------------------------ 7 | 8 | 9 | var margin = {top: 30, right: 10, bottom: 10, left: 10} 10 | , width = 960 11 | , height = 500 12 | , color = nv.utils.getColor(d3.scale.category20c().range()) 13 | , dispatch = d3.dispatch('stateChange', 'changeState') 14 | ; 15 | 16 | //============================================================ 17 | 18 | 19 | //============================================================ 20 | // Private Variables 21 | //------------------------------------------------------------ 22 | 23 | 24 | //============================================================ 25 | 26 | 27 | function chart(selection) { 28 | selection.each(function(data) { 29 | var availableWidth = width - margin.left - margin.right, 30 | availableHeight = height - margin.top - margin.bottom, 31 | container = d3.select(this); 32 | 33 | 34 | //------------------------------------------------------------ 35 | // Setup Scales 36 | 37 | 38 | //------------------------------------------------------------ 39 | 40 | 41 | //------------------------------------------------------------ 42 | // Setup containers and skeleton of chart 43 | 44 | var wrap = container.selectAll('g.nv-wrap.nv-chartName').data([data]); 45 | var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-chartName'); 46 | var gEnter = wrapEnter.append('g'); 47 | var g = wrap.select('g') 48 | 49 | gEnter.append('g').attr('class', 'nv-mainWrap'); 50 | 51 | wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); 52 | 53 | //------------------------------------------------------------ 54 | 55 | 56 | 57 | 58 | }); 59 | 60 | return chart; 61 | } 62 | 63 | 64 | //============================================================ 65 | // Expose Public Variables 66 | //------------------------------------------------------------ 67 | 68 | 69 | chart.dispatch = dispatch; 70 | 71 | chart.options = nv.utils.optionsFunc.bind(chart); 72 | 73 | chart.margin = function(_) { 74 | if (!arguments.length) return margin; 75 | margin.top = typeof _.top != 'undefined' ? _.top : margin.top; 76 | margin.right = typeof _.right != 'undefined' ? _.right : margin.right; 77 | margin.bottom = typeof _.bottom != 'undefined' ? _.bottom : margin.bottom; 78 | margin.left = typeof _.left != 'undefined' ? _.left : margin.left; 79 | return chart; 80 | }; 81 | 82 | chart.width = function(_) { 83 | if (!arguments.length) return width; 84 | width = _; 85 | return chart; 86 | }; 87 | 88 | chart.height = function(_) { 89 | if (!arguments.length) return height; 90 | height = _; 91 | return chart; 92 | }; 93 | 94 | chart.color = function(_) { 95 | if (!arguments.length) return color; 96 | color = nv.utils.getColor(_) 97 | return chart; 98 | }; 99 | 100 | //============================================================ 101 | 102 | 103 | return chart; 104 | } 105 | -------------------------------------------------------------------------------- /www/js/nvd3/src/outro.js: -------------------------------------------------------------------------------- 1 | })(); -------------------------------------------------------------------------------- /www/js/nvd3/test/interactiveBisectTest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |

Unit tests for nv.interactiveBisect - this function is important for rendering tooltips and the guideline on charts.

9 | 15 | 16 | 17 | 18 | 19 | 20 | 159 | -------------------------------------------------------------------------------- /www/js/nvd3/test/multiBarChartTest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

Multibar chart test cases - feel free to add more tests

8 | 11 |
12 | Normal chart, with transition delay, and bar color set. 13 | 14 |
15 |
16 | Normal chart, no transitionDuration or delay, no bar color set. 17 | 18 |
19 |
20 | Chart with single series, no group spacing. 21 | 22 |
23 |
24 | Chart with 18 series, 7 data points per series. 25 | 26 |
27 |
28 | Chart with 1 data point 29 | 30 |
31 |
32 | Chart with 2 data points 33 | 34 |
35 |
36 | Chart with 0 data points 37 | 38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 149 | -------------------------------------------------------------------------------- /www/js/nvd3/test/realTimeChartTest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 15 |

Example showing real time chart updating

16 | The chart below is a historical bar chart, which is ideal for visualizing time series data.
17 | First, you need to update the data model for the chart. In the example, we append a random number 18 | every half a second. Then, you call chart.update(). 19 | 20 |
21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /www/js/nvd3/test/testScript.js: -------------------------------------------------------------------------------- 1 | //A little snippet of D3 code that creates a button that lets you toggle whether a chart is the only one visible on a page or not. 2 | d3.selectAll(".chart button").on("click",function() { 3 | var thisId = this.parentElement.id; 4 | 5 | var chartContainer = d3.select("#" + thisId); 6 | if (chartContainer.attr("class").match("selected")) 7 | chartContainer.classed("selected",false); 8 | else 9 | chartContainer.classed("selected",true); 10 | 11 | d3.selectAll(".chart").style("display",function() { 12 | if (thisId === this.id) return "block"; 13 | 14 | if (d3.select(this).style("display") === "none") 15 | return "block"; 16 | else 17 | return "none"; 18 | }); 19 | window.onresize(); 20 | }); -------------------------------------------------------------------------------- /www/js/nvd3/test/teststyle.css: -------------------------------------------------------------------------------- 1 | body { 2 | overflow-y:scroll; 3 | font-family: arial; 4 | } 5 | 6 | text { 7 | font: 12px sans-serif; 8 | } 9 | 10 | .chart { 11 | float:left; 12 | height: 500px; 13 | text-align: center; 14 | font-weight: bold; 15 | margin-bottom: 2em; 16 | } 17 | .chart.full { 18 | width: 100%; 19 | } 20 | 21 | .chart.half { 22 | width: 50%; 23 | } 24 | 25 | .chart.third { 26 | width: 33%; 27 | } 28 | 29 | .chart.selected { 30 | width: 100% !important; 31 | } 32 | 33 | .navigation a{ 34 | margin-right: 1em; 35 | } 36 | 37 | .navigation { 38 | margin-bottom: 1em; 39 | } 40 | -------------------------------------------------------------------------------- /www/js/scatterchart-binding.js: -------------------------------------------------------------------------------- 1 | // Put code in an Immediately Invoked Function Expression (IIFE). 2 | // This isn't strictly necessary, but it's good JavaScript hygiene. 3 | (function() { 4 | 5 | // See http://rstudio.github.io/shiny/tutorial/#building-outputs for 6 | // more information on creating output bindings. 7 | 8 | // First create a generic output binding instance, then overwrite 9 | // specific methods whose behavior we want to change. 10 | var binding = new Shiny.OutputBinding(); 11 | 12 | binding.find = function(scope) { 13 | // For the given scope, return the set of elements that belong to 14 | // this binding. 15 | return $(scope).find(".nvd3-scatterchart"); 16 | }; 17 | 18 | binding.renderValue = function(el, data) { 19 | // This function will be called every time we receive new output 20 | // values for a line chart from Shiny. The "el" argument is the 21 | // div for this particular chart. 22 | 23 | var $el = $(el); 24 | 25 | // The first time we render a value for a particular element, we 26 | // need to initialize the nvd3 line chart and d3 selection. We'll 27 | // store these on $el as a data value called "state". 28 | if (!$el.data("state")) { 29 | // var chart = nv.models.lineChart() 30 | var chart = nv.models.scatterChart() 31 | .margin({left: 100}) 32 | // .useInteractiveGuideline(true) 33 | // .transitionDuration(350) 34 | // .showLegend(true) 35 | .size(1) 36 | .sizeRange([50,50]) 37 | .showLegend(false) 38 | .showYAxis(true) 39 | .showXAxis(true); 40 | 41 | chart.xAxis //Chart x-axis settings 42 | .axisLabel('X') 43 | .tickFormat(d3.format('d')); 44 | // .tickFormat(d3.format('.00f')); 45 | // .tickFormat(d3.format('.01f')); 46 | 47 | chart.yAxis //Chart y-axis settings 48 | .axisLabel('P') 49 | .tickFormat(d3.format('.02f')); 50 | 51 | nv.utils.windowResize(chart.update); 52 | 53 | var selection = d3.select(el).select("svg"); 54 | 55 | // Store the chart object on el so we can get it next time 56 | $el.data("state", { 57 | chart: chart, 58 | selection: selection 59 | }); 60 | } 61 | 62 | // Now, the code that'll run every time a value is rendered... 63 | 64 | // Retrieve the chart and selection we created earlier 65 | var state = $el.data("state"); 66 | 67 | // Schedule some work with nvd3 68 | nv.addGraph(function() { 69 | // Update the chart 70 | state.selection 71 | .datum(data) 72 | .transition(500) 73 | .call(state.chart); 74 | return state.chart; 75 | }); 76 | }; 77 | 78 | // Tell Shiny about our new output binding 79 | Shiny.outputBindings.register(binding, "stat_dist.nvd3-scatterchart"); 80 | 81 | })(); 82 | --------------------------------------------------------------------------------