├── .Rbuildignore ├── .gitignore ├── DESCRIPTION ├── LICENSE ├── LICENSE.md ├── NAMESPACE ├── R ├── beta_pal.R ├── beta_plot.R ├── get_objective.R ├── globals.R └── utils-pipe.R ├── README.Rmd ├── README.md ├── archive └── beta_pal_firsttry.R ├── docs ├── 404.html ├── LICENSE-text.html ├── LICENSE.html ├── articles │ ├── betapal.html │ ├── betapal_files │ │ ├── accessible-code-block-0.0.1 │ │ │ └── empty-anchor.js │ │ ├── figure-html │ │ │ ├── unnamed-chunk-11-1.png │ │ │ ├── unnamed-chunk-12-1.png │ │ │ └── unnamed-chunk-6-1.png │ │ └── header-attrs-2.3 │ │ │ └── header-attrs.js │ └── index.html ├── authors.html ├── bootstrap-toc.css ├── bootstrap-toc.js ├── docsearch.css ├── docsearch.js ├── index.html ├── link.svg ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml └── reference │ ├── beta_pal.html │ ├── beta_plot.html │ ├── figures │ ├── README-unnamed-chunk-11-1.png │ ├── README-unnamed-chunk-12-1.png │ ├── README-unnamed-chunk-13-1.png │ ├── README-unnamed-chunk-14-1.png │ ├── README-unnamed-chunk-15-1.png │ ├── README-unnamed-chunk-5-1.png │ ├── README-unnamed-chunk-6-1.png │ ├── README-unnamed-chunk-7-1.png │ ├── README-unnamed-chunk-8-1.png │ └── README-unnamed-chunk-9-1.png │ ├── get_objective.html │ ├── index.html │ └── pipe.html ├── inst ├── _pkgdown.yml └── tutorials │ └── ppalhelp │ ├── README.md │ ├── css │ └── miceeseese.css │ └── parameterpal_help.Rmd ├── man ├── beta_pal.Rd ├── beta_plot.Rd ├── figures │ ├── README-unnamed-chunk-11-1.png │ ├── README-unnamed-chunk-12-1.png │ ├── README-unnamed-chunk-13-1.png │ ├── README-unnamed-chunk-14-1.png │ ├── README-unnamed-chunk-15-1.png │ ├── README-unnamed-chunk-5-1.png │ ├── README-unnamed-chunk-6-1.png │ ├── README-unnamed-chunk-7-1.png │ ├── README-unnamed-chunk-8-1.png │ └── README-unnamed-chunk-9-1.png ├── get_objective.Rd └── pipe.Rd ├── parameterpal.Rproj ├── tests ├── testthat.R └── testthat │ ├── test-beta_plot.R │ └── test-betapal.R └── vignettes ├── .gitignore └── betapal.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^parameterpal\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^LICENSE\.md$ 4 | ^README\.Rmd$ 5 | ^doc$ 6 | ^Meta$ 7 | ^_pkgdown\.yml$ 8 | ^docs$ 9 | ^pkgdown$ 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | inst/doc 3 | doc 4 | Meta 5 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: parameterpal 2 | Title: Intepretable parameters for the beta distribution 3 | Version: 0.0.1 4 | Authors@R: c( 5 | person(given = "Charles", 6 | family = "Gray", 7 | role = c("aut", "cre"), 8 | email = "charlestigray@gmail.com", 9 | comment = c(ORCID = "0000-0002-9978-011X")), 10 | person(given = "Hien", 11 | family = "Nguyen", 12 | role = "ctb"), 13 | person(given = "Matthew", 14 | family = "Grainger", 15 | role = "ctb"), 16 | person(given = "Matthew", 17 | family = "Henderson", 18 | role = "ctb"), 19 | person(given = "Daniel", 20 | family = "Oberski", 21 | role = "ctb"), 22 | person(given = "Yanina", 23 | family = "Saibene", 24 | role = "ctb"), 25 | person(given = "Laura", 26 | family = "Acion", 27 | role = "ctb"), 28 | person(given = "Heather", 29 | family = "Turner", 30 | role = "ctb")) 31 | Description: From the measure we expect, how much we expect yea much of the measure falling within, we interpret beta distribution parameters. 32 | License: MIT + file LICENSE 33 | Encoding: UTF-8 34 | LazyData: true 35 | Roxygen: list(markdown = TRUE) 36 | RoxygenNote: 7.1.1 37 | Suggests: 38 | rmarkdown, 39 | testthat 40 | VignetteBuilder: knitr 41 | Imports: 42 | magrittr, 43 | tibble, 44 | ggplot2, 45 | stringr, 46 | assertthat, 47 | knitr, 48 | ggthemes 49 | Date: 2020 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2020 2 | COPYRIGHT HOLDER: Charles Gray 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2020 Charles Gray 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 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export("%>%") 4 | export(beta_pal) 5 | export(beta_plot) 6 | importFrom(magrittr,"%>%") 7 | -------------------------------------------------------------------------------- /R/beta_pal.R: -------------------------------------------------------------------------------- 1 | #' Beta parameters from interpretable conditions 2 | #' 3 | #' Rather than knowing intrinsically what parameters are required for a 4 | #' distribution, scientists tend to have a sense of what value they 5 | #' *expect* a measure to take, *how much* they expect observations to fall 6 | #' *within* a certain distance of that value. 7 | #' 8 | #' This solution coded by by this most helpful 9 | #' [gist](https://gist.github.com/daob/1422e978ff98bdf466fbcb4d9bf3e53e). 10 | #' 11 | #' Visualise the distribution with [beta_plot]. 12 | #' See `vignette("beta_pal")` for derivations and more information. 13 | #' 14 | #' @param expected_value Expected value of beta distrbution from \[0,1\]. 15 | #' @param within Specify distance `this_much` falls within. 16 | #' @param this_much What proportion falls `within` the specified interval. 17 | #' 18 | #' @return List of parameters appropriate for [rbeta] family of functions. 19 | #' 20 | #' @export 21 | 22 | beta_pal <- function(expected_value, 23 | within, 24 | this_much) { 25 | # check inputs 26 | assertthat::assert_that(expected_value > 0 & 27 | expected_value < 1, 28 | msg = "expected_value must be from (0,1)") 29 | assertthat::assert_that(within > 0 & 30 | within < 1, 31 | msg = "within must be from (0,1)") 32 | assertthat::assert_that(this_much > 0 & this_much < 1, 33 | msg = 34 | "this_much must be a value from [0,1].") 35 | 36 | # Function that takes desrired mean, distance, and probability, and outputs 37 | # another function to be optimized. 38 | my_objective <- 39 | get_objective( 40 | desired_mean = expected_value, 41 | desired_dist = within, 42 | desired_mass = this_much 43 | ) 44 | 45 | res <- 46 | optim(1, 47 | my_objective, 48 | method = "Brent", 49 | lower = 1e-3, 50 | upper = 10) 51 | 52 | shape1_est <- res$par 53 | shape2_est <- shape1_est * ((1 / expected_value) - 1) 54 | 55 | list(shape1_est = shape1_est, shape2_est = shape2_est) 56 | } 57 | -------------------------------------------------------------------------------- /R/beta_plot.R: -------------------------------------------------------------------------------- 1 | #' Plot beta distribution 2 | #' 3 | #' This function utlises [beta_pal] to produce a visualisation of the beta 4 | #' distribution, with user-specified interpretable conditions. 5 | #' 6 | #' 7 | #' @inheritParams beta_pal 8 | #' @param caption_width Option to control the width of the caption, defaults to 9 | #' 70. 10 | #' @param theme_default Currently defaults to `ggthemes::theme_tufte`. 11 | #' 12 | #' @export 13 | 14 | beta_plot <- function(expected_value, 15 | within, 16 | this_much, 17 | caption_width = 70, 18 | theme_default = TRUE) { 19 | # calculate parameters 20 | par <- 21 | beta_pal(expected_value = expected_value, 22 | within = within, 23 | this_much = this_much) 24 | 25 | # return plot of beta distribution with parameters 26 | tibble::tibble(x = c(0, 1)) %>% 27 | ggplot2::ggplot(ggplot2::aes(x = x)) + 28 | 29 | # desired quantiles 30 | ggplot2::geom_rect( 31 | xmin = expected_value - within, 32 | xmax = expected_value + within, 33 | ymin = 0, 34 | ymax = Inf, 35 | alpha = 0.2 36 | ) + 37 | 38 | ggplot2::geom_vline(xintercept = expected_value, 39 | linetype = "dashed", 40 | alpha = 0.8) + 41 | ggplot2::stat_function( 42 | fun = dbeta, 43 | linetype = "dotted", 44 | args = list( 45 | shape1 = par$shape1_est, 46 | shape2 = par$shape2_est 47 | ) 48 | ) + 49 | ggplot2::labs( 50 | title = sprintf("beta(%.1f, %.1f)", 51 | par$shape1_est, 52 | par$shape2_est), 53 | y = NULL, 54 | x = NULL, 55 | caption = sprintf( 56 | "Assuming a beta distribution (dotted line), with expected value %g (vertical dashed line), and %g per cent of falling within %g of %g, parameterpal:: approximates the distribution beta(%g, %g). Parameters in the title are rounded. The shaded region shows the desired region %g per cent of values falling within %g of %g, under the approximated distribution, beta(%g, %g), %g per cent of values fall within this region.", 57 | expected_value, 58 | this_much * 100, 59 | within, 60 | expected_value, 61 | par$shape1_est, 62 | par$shape2_est, 63 | this_much * 100, 64 | within, 65 | expected_value, 66 | par$shape1_est, 67 | par$shape2_est, 68 | ( 69 | pbeta(q = expected_value + within, par$shape1_est, par$shape2_est) - 70 | pbeta(q = expected_value - within, par$shape1_est, par$shape2_est) 71 | ) * 100 72 | ) %>% stringr::str_wrap(width = caption_width) 73 | ) + 74 | ggplot2::theme( 75 | axis.text.y = ggplot2::element_blank(), 76 | axis.ticks.y = ggplot2::element_blank() 77 | ) -> bplot 78 | 79 | if (isTRUE(theme_default)) { 80 | bplot + ggthemes::theme_tufte(base_size = 12) + ggplot2::theme( 81 | axis.text.y = ggplot2::element_blank(), 82 | axis.ticks.y = ggplot2::element_blank() 83 | ) 84 | 85 | } else { 86 | bplot 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /R/get_objective.R: -------------------------------------------------------------------------------- 1 | #' Objective function 2 | #' 3 | #' Function that takes desrired mean, distance, and probability, and outputs 4 | #' another function to be optimized. Adapted into [beta_pal]. 5 | #' 6 | #' This solution coded by by this most helpful 7 | #' [gist](https://gist.github.com/daob/1422e978ff98bdf466fbcb4d9bf3e53e). 8 | #' 9 | #' 10 | #' @param desired_mean expected_value. 11 | #' @param desired_dist within. 12 | #' @param desired_mass this_much. 13 | #' 14 | #' This function is called by [beta_pal] internally. 15 | 16 | get_objective <- function(desired_mean, desired_dist, desired_mass) { 17 | # Return a function that can be passed to optim() 18 | function(shape1) { 19 | # Enforce desired mean: 20 | shape2 <- shape1 * ((1 / desired_mean) - 1) 21 | 22 | # Use R internals to get the definite integral: 23 | current_mass <- pbeta(q = desired_mean + desired_dist, 24 | shape1 = shape1, shape2 = shape2) - 25 | pbeta(q = desired_mean - desired_dist, 26 | shape1 = shape1, shape2 = shape2) 27 | 28 | # Loss is squared difference between desired and obtained measure: 29 | (current_mass - desired_mass)^2 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /R/globals.R: -------------------------------------------------------------------------------- 1 | # following this advice: 2 | # https://community.rstudio.com/t/how-to-solve-no-visible-binding-for-global-variable-note/28887 3 | 4 | utils::globalVariables(c("x", "dbeta")) 5 | -------------------------------------------------------------------------------- /R/utils-pipe.R: -------------------------------------------------------------------------------- 1 | #' Pipe operator 2 | #' 3 | #' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 4 | #' 5 | #' @name %>% 6 | #' @rdname pipe 7 | #' @keywords internal 8 | #' @export 9 | #' @importFrom magrittr %>% 10 | #' @usage lhs \%>\% rhs 11 | NULL 12 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | 7 | ```{r, include = FALSE} 8 | knitr::opts_chunk$set( 9 | collapse = TRUE, 10 | comment = "#>", 11 | fig.path = "man/figures/README-", 12 | out.width = "100%", 13 | fig.height = 3 14 | ) 15 | ``` 16 | 17 | # parameterpal 18 | 19 | 20 | 21 | 22 | Rather than knowing intrinsically what parameters are required for a distribution, scientists tend to have a sense of what value they *expect* a measure to take, *how many* observations should fall *within* a certain distance of that value. 23 | 24 | For the normal distribution, this is straightforward, as the parameters reflect the expected value and variance. However, for the beta distribution, the parameters are not so readily interpretable. 25 | 26 | `parameterpal::` provides a means of obtaining the parameters required for the beta distribution from interpretable conditions. 27 | 28 | ## installation 29 | 30 | ```{r eval=FALSE} 31 | devtools::install_github("softloud/parameterpal", build_vignettes = TRUE) 32 | ``` 33 | 34 | ## launch tutorial 35 | 36 | After installation, the `parameterpal::` tutorial will be available in the Tutorial pane of Rstudio. 37 | 38 | ```{r eval=FALSE} 39 | # executing this code will launch the tutorial in your browser 40 | learnr::run_tutorial("ppalhelp", package = "parameterpal") 41 | ``` 42 | 43 | 44 | 45 | ## documentation 46 | 47 | See this package's [`pkgdown::`](https://pkgdown.r-lib.org/articles/pkgdown.html)-generated [site for more information](https://softloud.github.io/parameterpal/). 48 | 49 | 50 | 51 | ## intended user 52 | 53 | This package was developed for a friend and collaborator, computational ecologist [Dr Matthew Grainger](https://github.com/DrMattG), who previously used browser-based tools to obtain beta parameters to inform his rstats workflow. I hope he finds this package a useful augment to his codeflow. 54 | 55 | 56 | # vignette 57 | 58 | See `vignette("betapal")` for ~~more information~~ the same information, but from the handy ease of your Rstudio Viewer pane. 59 | 60 | Full disclosure, I need to update it after I 61 | fully understand this [gist](https://gist.github.com/daob/1422e978ff98bdf466fbcb4d9bf3e53e) I was provided with after posting the first version of this software to twitter. Open science at its best. Blogpost incoming on open science and why it's good to share bad math and beta research code. So cool I've ended up with a better, more mathematically correct solution after posting it. 62 | 63 | # other distributions 64 | 65 | No reason the same math can't be applied to other distributions. Open an issue if you'd like me to provide parameters from interpretable conditions for another distribution. 66 | 67 | # development on hold 68 | 69 | Currently softloud is finishing her dissertation, and with it so close, she's focussed on wrapping that up before extending any software beyond what's required for the thesis. 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # parameterpal 5 | 6 | 7 | 8 | 9 | 10 | Rather than knowing intrinsically what parameters are required for a 11 | distribution, scientists tend to have a sense of what value they 12 | *expect* a measure to take, *how many* observations should fall *within* 13 | a certain distance of that value. 14 | 15 | For the normal distribution, this is straightforward, as the parameters 16 | reflect the expected value and variance. However, for the beta 17 | distribution, the parameters are not so readily interpretable. 18 | 19 | `parameterpal::` provides a means of obtaining the parameters required 20 | for the beta distribution from interpretable conditions. 21 | 22 | ## installation 23 | 24 | ``` r 25 | devtools::install_github("softloud/parameterpal", build_vignettes = TRUE) 26 | ``` 27 | 28 | ## launch tutorial 29 | 30 | After installation, the `parameterpal::` tutorial will be available in 31 | the Tutorial pane of Rstudio. 32 | 33 | ``` r 34 | # executing this code will launch the tutorial in your browser 35 | learnr::run_tutorial("ppalhelp", package = "parameterpal") 36 | ``` 37 | 38 | ## documentation 39 | 40 | See this package’s 41 | [`pkgdown::`](https://pkgdown.r-lib.org/articles/pkgdown.html)-generated 42 | [site for more information](https://softloud.github.io/parameterpal/). 43 | 44 | ## intended user 45 | 46 | This package was developed for a friend and collaborator, computational 47 | ecologist [Dr Matthew Grainger](https://github.com/DrMattG), who 48 | previously used browser-based tools to obtain beta parameters to inform 49 | his rstats workflow. I hope he finds this package a useful augment to 50 | his codeflow. 51 | 52 | # vignette 53 | 54 | See `vignette("betapal")` for ~~more information~~ the same information, 55 | but from the handy ease of your Rstudio Viewer pane. 56 | 57 | Full disclosure, I need to update it after I fully understand this 58 | [gist](https://gist.github.com/daob/1422e978ff98bdf466fbcb4d9bf3e53e) I 59 | was provided with after posting the first version of this software to 60 | twitter. Open science at its best. Blogpost incoming on open science and 61 | why it’s good to share bad math and beta research code. So cool I’ve 62 | ended up with a better, more mathematically correct solution after 63 | posting it. 64 | 65 | # other distributions 66 | 67 | No reason the same math can’t be applied to other distributions. Open an 68 | issue if you’d like me to provide parameters from interpretable 69 | conditions for another distribution. 70 | 71 | # development on hold 72 | 73 | Currently softloud is finishing her dissertation, and with it so close, 74 | she’s focussed on wrapping that up before extending any software beyond 75 | what’s required for the thesis. 76 | -------------------------------------------------------------------------------- /archive/beta_pal_firsttry.R: -------------------------------------------------------------------------------- 1 | #' Beta parameters from interpretable conditions 2 | #' 3 | #' Rather than knowing intrinsically what parameters are required for a 4 | #' distribution, scientists tend to have a sense of what value they 5 | #' *expect* a measure to take, *how much* they expect observations to fall 6 | #' *within* a certain distance of that value. 7 | #' 8 | #' Visualise the distribution with [beta_plot]. 9 | #' See `vignette("beta_pal")` for derivations and more information. 10 | #' 11 | #' @param expected_value Expected value of beta distrbution from \[0,1\]. 12 | #' @param within Specify distance `this_much` falls within. 13 | #' @param this_much What proportion falls `within` the specified interval. 14 | #' Defaults to 0.95. 15 | #' 16 | #' @return List of parameters appropriate for [rbeta] family of functions. 17 | #' 18 | #' @export 19 | 20 | beta_pal <- function(expected_value, 21 | within, 22 | this_much = 0.95) { 23 | 24 | # check inputs 25 | assertthat::assert_that(expected_value > 0 & 26 | expected_value < 1, 27 | msg = "expected_value must be from (0,1)") 28 | assertthat::assert_that(within > 0 & 29 | within < 1, 30 | msg = "within must be from (0,1)") 31 | assertthat::assert_that( 32 | this_much > 0 & this_much < 1, 33 | msg = "within expected_valuest be a value from [0,1].") 34 | 35 | 36 | # calculate beta distribution parameters 37 | gamma <- (1 - this_much)^-1 38 | 39 | shape1 <- expected_value * ( 40 | ( 41 | expected_value^2 * (1 / expected_value - 1) 42 | ) / ( 43 | within^2 * (1 - this_much) 44 | ) - 1 45 | ) 46 | 47 | shape2 <- shape1 / expected_value - shape1 48 | 49 | # return list of parameters 50 | return(list(shape1 = shape1, 51 | shape2 = shape2)) 52 | } 53 | -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Page not found (404) • parameterpal 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 58 | 59 | 60 | 61 | 62 | 63 | 64 |
65 |
66 | 112 | 113 | 114 | 115 |
116 | 117 |
118 |
119 | 122 | 123 | Content not found. Please use links in the navbar. 124 | 125 |
126 | 127 | 132 | 133 |
134 | 135 | 136 | 137 | 147 |
148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /docs/LICENSE-text.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | License • parameterpal 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 58 | 59 | 60 | 61 | 62 | 63 | 64 |
65 |
66 | 112 | 113 | 114 | 115 |
116 | 117 |
118 |
119 | 122 | 123 |
YEAR: 2020
124 | COPYRIGHT HOLDER: Charles Gray
125 | 
126 | 127 |
128 | 129 | 134 | 135 |
136 | 137 | 138 | 139 | 149 |
150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /docs/LICENSE.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | MIT License • parameterpal 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 58 | 59 | 60 | 61 | 62 | 63 | 64 |
65 |
66 | 112 | 113 | 114 | 115 |
116 | 117 |
118 |
119 | 122 | 123 |
124 | 125 |

Copyright (c) 2020 Charles Gray

126 |

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

127 |

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

128 |

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

129 |
130 | 131 |
132 | 133 | 138 | 139 |
140 | 141 | 142 | 143 | 153 |
154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /docs/articles/betapal.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Obtain beta parameters from interpretable conditions • parameterpal 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 23 | 24 | 25 |
26 |
71 | 72 | 73 | 74 | 75 |
76 |
77 | 87 | 88 | 89 | 90 |

Do you use beta distributions in your science? Do you find the parameters uninterpretable?

91 |

Obtain parameters for the beta distribution from interpretable conditions.

92 |
93 |

94 | installation

95 |
devtools::install_github("softloud/parameterpal", build_vignettes = TRUE)
96 |
97 |
98 |

99 | using parameterpal:: 100 |

101 |
library(parameterpal)
102 |
usage_example <- list(
103 |   expected_value = 0.3,
104 |   within = 0.2,
105 |   this_much = 0.8
106 | )
107 |

Suppose we expect a value of 0.3, with 80 per cent of observations falling within a distance of 0.2 from 0.3.

108 |

That is, we expect 80 per cent of observations to fall within (0.1, 0.5). Assuming data follow a beta distribution, what are its parameters?

109 |
beta_pal(expected_value = usage_example$expected_value,
110 |          within = usage_example$within,
111 |          this_much = usage_example$this_much)
112 | #> $shape1_est
113 | #> [1] 2.306909
114 | #> 
115 | #> $shape2_est
116 | #> [1] 5.382787
117 |

We can plot this intuition to see the shape of the resulting beta distribution.

118 |
beta_plot(expected_value = usage_example$expected_value,
119 |          within = usage_example$within,
120 |          this_much = usage_example$this_much)
121 |

122 |

Specifying the width enables us to escape the ubiquitous tyranny of the arbitary bounds of 95 per cent, which doesn’t necessarily reflect our intuition, suppose we thought only

123 |
new_example_width <- 0.3
124 |

30 per cent of values fall within the interval.

125 |
beta_pal(expected_value = usage_example$expected_value,
126 |          within = usage_example$within,
127 |          this_much = new_example_width)
128 | #> $shape1_est
129 | #> [1] 0.3087453
130 | #> 
131 | #> $shape2_est
132 | #> [1] 0.7204056
133 |
134 |
135 |

136 | motivation

137 |

Rather than knowing intrinsically what parameters are required for a distribution, scientists tend to have indirect knowledge. A researcher may have a sense of what value they expect a measure to take, how many observations should fall within a certain distance of that value. As well as the overall shape of the data, the distribution. Distributions are not defined in the intuitive terms the scientist has, but equational parameters commonly (but not always) \(\mu\) and \(\sigma\) for the normal distribution, \(\lambda\) for the exponential, and \(\alpha\) and \(\beta\) for the beta distribution. However, calculating the required parameters is not necessarily straightfoward, despite the conditioning we receive from the normal distribution.

138 |
# set normal distribution example parameters
139 | norm_expected_value <- 0.5
140 | norm_within <- 0.2
141 |

For the normal distribution, obtaining the parameters from these assumptions is straightforward. The expected value and variance, which is to say, centre and spread, of the normal distribution, are both easily interpretable and translate directly to the parameters required for the distribution. So, to sample three values from a normal distribution where we expect a value of 0.5 with two-thirds of values falling within 0.2 of 0.5, we simply run the following code.

142 |
rnorm(n = 3,
143 |       mean = norm_expected_value,
144 |       sd = norm_within)
145 | #> [1] 0.1499015 0.1982818 0.2273453
146 |

The first parameter is the expected value, and the second, the variance. For the normal distribution, the standard deviation is interpretable. We know two-thirds of values fall within one standard deviation of the mean. If we shade this area in a visualisation, it’s convincing that two-thirds of values fall within this range.

147 |
148 | library(ggplot2)
149 | 
150 | ggplot() +
151 |   xlim(0, 1) +
152 |   geom_rect(
153 |     aes(
154 |       xmin = norm_expected_value - norm_within,
155 |       xmax = norm_expected_value + norm_within,
156 |       ymin = 0,
157 |       ymax = Inf,
158 |       alpha = 0.2)) +
159 | stat_function(
160 |   fun = dnorm,
161 |   args = list(mean = norm_expected_value, sd = norm_within)
162 | ) +
163 |   theme(legend.position = "none") +
164 |   labs(
165 |     y = NULL,
166 |     title = sprintf("normal(%g, %g)", norm_expected_value, norm_within),
167 |     caption = sprintf("Two-thirds of normally distributed values fall within %g of %g.", norm_within, norm_expected_value)
168 |   )
169 |

170 |

The beta distribution, on the other hand, requires two shape parameters, shape1 and shape2, which do not immediately reflect our intuition of what value we expect the measure to take, nor how much variance we expect.

171 |

But if we wished to sample from beta distribution, however, the parameters, shape1 and shape2, are not readily interpretable from expected value and variance. parameterpal:: provides a means of obtaining the parameters required for the beta distribution from interpretable conditions.

172 |
173 |
174 |

175 | beta distribution

176 |

The beta distribution has some really nice properties. It is bounded by a minimum value of 0 and a maximum of 1, so is perfect for modeling proportions.

177 |

Under some circumstances it can mimic a truncated bell curve, as well as flexibility for other shapes, such as a truncated parabola.

178 |

But this is not intuitive. What shape do we expect \(\mathrm{beta}(1,2)\) to take? It’s hard to intuit from the parameters 1 and 2. But, we likely do not expect a negatively sloped line.

179 |
ggplot() +
180 |   xlim(0, 1) +
181 | stat_function(
182 |   fun = dbeta,
183 |   args = list(shape1 = 1, shape2 = 2)
184 | )
185 |

186 |
187 |
188 |

189 | original application

190 |

This code was developed for softloud/simeta::, research software that supported softloud’s dissertation. This problem is a very small component of a larger collection of simulation functions for randomly generating meta-analysis data.

191 |

In this case, given a population \(N\), what proportion are allocated to the case and control groups? A desire to reflect the uncertainty of designed experiments motivated this code.

192 |

For example, even if case and control groups were assigned evenly, in experimental science there are many reasons individuals may drop out of the groups. Thus a proportion of \(N\) was sampled from a beta distribution (which is bounded between 0 and 1, as proportions are, too), with an intuition of how many drop outs are anticipated.

193 |
194 |
195 |

196 | citing this package

197 |
citation(package = "parameterpal")
198 | #> Warning in citation(package = "parameterpal"): could not determine year for
199 | #> 'parameterpal' from package DESCRIPTION file
200 | #> 
201 | #> To cite package 'parameterpal' in publications use:
202 | #> 
203 | #>   Charles Gray (NA). parameterpal: Intepretable parameters for the beta
204 | #>   distribution. R package version 0.0.1.
205 | #> 
206 | #> A BibTeX entry for LaTeX users is
207 | #> 
208 | #>   @Manual{,
209 | #>     title = {parameterpal: Intepretable parameters for the beta distribution},
210 | #>     author = {Charles Gray},
211 | #>     note = {R package version 0.0.1},
212 | #>   }
213 |
214 |
215 | 216 | 221 | 222 |
223 | 224 | 225 | 226 | 235 |
236 | 237 | 238 | 239 | 240 | 241 | 242 | -------------------------------------------------------------------------------- /docs/articles/betapal_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /docs/articles/betapal_files/figure-html/unnamed-chunk-11-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/docs/articles/betapal_files/figure-html/unnamed-chunk-11-1.png -------------------------------------------------------------------------------- /docs/articles/betapal_files/figure-html/unnamed-chunk-12-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/docs/articles/betapal_files/figure-html/unnamed-chunk-12-1.png -------------------------------------------------------------------------------- /docs/articles/betapal_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/docs/articles/betapal_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/articles/betapal_files/header-attrs-2.3/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Articles • parameterpal 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 58 | 59 | 60 | 61 | 62 | 63 | 64 |
65 |
66 | 112 | 113 | 114 | 115 |
116 | 117 |
118 |
119 | 122 | 123 |
124 |

All vignettes

125 |

126 | 127 |
128 |
Obtain beta parameters from interpretable conditions
129 |
130 |
131 |
132 |
133 |
134 | 135 | 136 | 146 |
147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Authors • parameterpal 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 58 | 59 | 60 | 61 | 62 | 63 | 64 |
65 |
66 | 112 | 113 | 114 | 115 |
116 | 117 |
118 |
119 | 122 | 123 |
    124 |
  • 125 |

    Charles Gray. Author, maintainer. 126 |

    127 |
  • 128 |
  • 129 |

    Hien Nguyen. Contributor. 130 |

    131 |
  • 132 |
  • 133 |

    Matthew Grainger. Contributor. 134 |

    135 |
  • 136 |
  • 137 |

    Matthew Henderson. Contributor. 138 |

    139 |
  • 140 |
  • 141 |

    Daniel Oberski. Contributor. 142 |

    143 |
  • 144 |
  • 145 |

    Yanina Saibene. Contributor. 146 |

    147 |
  • 148 |
  • 149 |

    Laura Acion. Contributor. 150 |

    151 |
  • 152 |
  • 153 |

    Heather Turner. Contributor. 154 |

    155 |
  • 156 |
157 | 158 |
159 | 160 |
161 | 162 | 163 | 164 | 174 |
175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $(''); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /docs/docsearch.css: -------------------------------------------------------------------------------- 1 | /* Docsearch -------------------------------------------------------------- */ 2 | /* 3 | Source: https://github.com/algolia/docsearch/ 4 | License: MIT 5 | */ 6 | 7 | .algolia-autocomplete { 8 | display: block; 9 | -webkit-box-flex: 1; 10 | -ms-flex: 1; 11 | flex: 1 12 | } 13 | 14 | .algolia-autocomplete .ds-dropdown-menu { 15 | width: 100%; 16 | min-width: none; 17 | max-width: none; 18 | padding: .75rem 0; 19 | background-color: #fff; 20 | background-clip: padding-box; 21 | border: 1px solid rgba(0, 0, 0, .1); 22 | box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .175); 23 | } 24 | 25 | @media (min-width:768px) { 26 | .algolia-autocomplete .ds-dropdown-menu { 27 | width: 175% 28 | } 29 | } 30 | 31 | .algolia-autocomplete .ds-dropdown-menu::before { 32 | display: none 33 | } 34 | 35 | .algolia-autocomplete .ds-dropdown-menu [class^=ds-dataset-] { 36 | padding: 0; 37 | background-color: rgb(255,255,255); 38 | border: 0; 39 | max-height: 80vh; 40 | } 41 | 42 | .algolia-autocomplete .ds-dropdown-menu .ds-suggestions { 43 | margin-top: 0 44 | } 45 | 46 | .algolia-autocomplete .algolia-docsearch-suggestion { 47 | padding: 0; 48 | overflow: visible 49 | } 50 | 51 | .algolia-autocomplete .algolia-docsearch-suggestion--category-header { 52 | padding: .125rem 1rem; 53 | margin-top: 0; 54 | font-size: 1.3em; 55 | font-weight: 500; 56 | color: #00008B; 57 | border-bottom: 0 58 | } 59 | 60 | .algolia-autocomplete .algolia-docsearch-suggestion--wrapper { 61 | float: none; 62 | padding-top: 0 63 | } 64 | 65 | .algolia-autocomplete .algolia-docsearch-suggestion--subcategory-column { 66 | float: none; 67 | width: auto; 68 | padding: 0; 69 | text-align: left 70 | } 71 | 72 | .algolia-autocomplete .algolia-docsearch-suggestion--content { 73 | float: none; 74 | width: auto; 75 | padding: 0 76 | } 77 | 78 | .algolia-autocomplete .algolia-docsearch-suggestion--content::before { 79 | display: none 80 | } 81 | 82 | .algolia-autocomplete .ds-suggestion:not(:first-child) .algolia-docsearch-suggestion--category-header { 83 | padding-top: .75rem; 84 | margin-top: .75rem; 85 | border-top: 1px solid rgba(0, 0, 0, .1) 86 | } 87 | 88 | .algolia-autocomplete .ds-suggestion .algolia-docsearch-suggestion--subcategory-column { 89 | display: block; 90 | padding: .1rem 1rem; 91 | margin-bottom: 0.1; 92 | font-size: 1.0em; 93 | font-weight: 400 94 | /* display: none */ 95 | } 96 | 97 | .algolia-autocomplete .algolia-docsearch-suggestion--title { 98 | display: block; 99 | padding: .25rem 1rem; 100 | margin-bottom: 0; 101 | font-size: 0.9em; 102 | font-weight: 400 103 | } 104 | 105 | .algolia-autocomplete .algolia-docsearch-suggestion--text { 106 | padding: 0 1rem .5rem; 107 | margin-top: -.25rem; 108 | font-size: 0.8em; 109 | font-weight: 400; 110 | line-height: 1.25 111 | } 112 | 113 | .algolia-autocomplete .algolia-docsearch-footer { 114 | width: 110px; 115 | height: 20px; 116 | z-index: 3; 117 | margin-top: 10.66667px; 118 | float: right; 119 | font-size: 0; 120 | line-height: 0; 121 | } 122 | 123 | .algolia-autocomplete .algolia-docsearch-footer--logo { 124 | background-image: url("data:image/svg+xml;utf8,"); 125 | background-repeat: no-repeat; 126 | background-position: 50%; 127 | background-size: 100%; 128 | overflow: hidden; 129 | text-indent: -9000px; 130 | width: 100%; 131 | height: 100%; 132 | display: block; 133 | transform: translate(-8px); 134 | } 135 | 136 | .algolia-autocomplete .algolia-docsearch-suggestion--highlight { 137 | color: #FF8C00; 138 | background: rgba(232, 189, 54, 0.1) 139 | } 140 | 141 | 142 | .algolia-autocomplete .algolia-docsearch-suggestion--text .algolia-docsearch-suggestion--highlight { 143 | box-shadow: inset 0 -2px 0 0 rgba(105, 105, 105, .5) 144 | } 145 | 146 | .algolia-autocomplete .ds-suggestion.ds-cursor .algolia-docsearch-suggestion--content { 147 | background-color: rgba(192, 192, 192, .15) 148 | } 149 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | parameterpal • parameterpal 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 23 | 24 | 25 |
    26 |
    71 | 72 | 73 | 74 | 75 |
    76 |
    77 | 78 |
    79 | 81 | 82 | 83 |

    Rather than knowing intrinsically what parameters are required for a distribution, scientists tend to have a sense of what value they expect a measure to take, how many observations should fall within a certain distance of that value.

    84 |

    For the normal distribution, this is straightforward, as the parameters reflect the expected value and variance. However, for the beta distribution, the parameters are not so readily interpretable.

    85 |

    parameterpal:: provides a means of obtaining the parameters required for the beta distribution from interpretable conditions.

    86 |
    87 |

    88 | installation

    89 |
    devtools::install_github("softloud/parameterpal", build_vignettes = TRUE)
    90 |
    91 |
    92 |

    93 | launch tutorial

    94 |

    After installation, the parameterpal:: tutorial will be available in the Tutorial pane of Rstudio.

    95 |
    # executing this code will launch the tutorial in your browser
     96 | learnr::run_tutorial("ppalhelp", package = "parameterpal")
    97 |
    98 |
    99 |

    100 | documentation

    101 |

    See this package’s pkgdown::-generated site for more information.

    102 |
    103 |
    104 |

    105 | intended user

    106 |

    This package was developed for a friend and collaborator, computational ecologist Dr Matthew Grainger, who previously used browser-based tools to obtain beta parameters to inform his rstats workflow. I hope he finds this package a useful augment to his codeflow.

    107 |
    108 |
    109 |
    110 |

    111 | vignette

    112 |

    See vignette("betapal") for more information the same information, but from the handy ease of your Rstudio Viewer pane.

    113 |

    Full disclosure, I need to update it after I fully understand this gist I was provided with after posting the first version of this software to twitter. Open science at its best. Blogpost incoming on open science and why it’s good to share bad math and beta research code. So cool I’ve ended up with a better, more mathematically correct solution after posting it.

    114 |
    115 |
    116 |

    117 | other distributions

    118 |

    No reason the same math can’t be applied to other distributions. Open an issue if you’d like me to provide parameters from interpretable conditions for another distribution.

    119 |
    120 |
    121 |

    122 | development on hold

    123 |

    Currently softloud is finishing her dissertation, and with it so close, she’s focussed on wrapping that up before extending any software beyond what’s required for the thesis.

    124 |
    125 | 126 |
    127 | 128 | 145 |
    146 | 147 | 148 |
    151 | 152 |
    153 |

    Site built with pkgdown 1.5.1.

    154 |
    155 | 156 |
    157 |
    158 | 159 | 160 | 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/pkgdown.css: -------------------------------------------------------------------------------- 1 | /* Sticky footer */ 2 | 3 | /** 4 | * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ 5 | * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css 6 | * 7 | * .Site -> body > .container 8 | * .Site-content -> body > .container .row 9 | * .footer -> footer 10 | * 11 | * Key idea seems to be to ensure that .container and __all its parents__ 12 | * have height set to 100% 13 | * 14 | */ 15 | 16 | html, body { 17 | height: 100%; 18 | } 19 | 20 | body { 21 | position: relative; 22 | } 23 | 24 | body > .container { 25 | display: flex; 26 | height: 100%; 27 | flex-direction: column; 28 | } 29 | 30 | body > .container .row { 31 | flex: 1 0 auto; 32 | } 33 | 34 | footer { 35 | margin-top: 45px; 36 | padding: 35px 0 36px; 37 | border-top: 1px solid #e5e5e5; 38 | color: #666; 39 | display: flex; 40 | flex-shrink: 0; 41 | } 42 | footer p { 43 | margin-bottom: 0; 44 | } 45 | footer div { 46 | flex: 1; 47 | } 48 | footer .pkgdown { 49 | text-align: right; 50 | } 51 | footer p { 52 | margin-bottom: 0; 53 | } 54 | 55 | img.icon { 56 | float: right; 57 | } 58 | 59 | img { 60 | max-width: 100%; 61 | } 62 | 63 | /* Fix bug in bootstrap (only seen in firefox) */ 64 | summary { 65 | display: list-item; 66 | } 67 | 68 | /* Typographic tweaking ---------------------------------*/ 69 | 70 | .contents .page-header { 71 | margin-top: calc(-60px + 1em); 72 | } 73 | 74 | dd { 75 | margin-left: 3em; 76 | } 77 | 78 | /* Section anchors ---------------------------------*/ 79 | 80 | a.anchor { 81 | margin-left: -30px; 82 | display:inline-block; 83 | width: 30px; 84 | height: 30px; 85 | visibility: hidden; 86 | 87 | background-image: url(./link.svg); 88 | background-repeat: no-repeat; 89 | background-size: 20px 20px; 90 | background-position: center center; 91 | } 92 | 93 | .hasAnchor:hover a.anchor { 94 | visibility: visible; 95 | } 96 | 97 | @media (max-width: 767px) { 98 | .hasAnchor:hover a.anchor { 99 | visibility: hidden; 100 | } 101 | } 102 | 103 | 104 | /* Fixes for fixed navbar --------------------------*/ 105 | 106 | .contents h1, .contents h2, .contents h3, .contents h4 { 107 | padding-top: 60px; 108 | margin-top: -40px; 109 | } 110 | 111 | /* Navbar submenu --------------------------*/ 112 | 113 | .dropdown-submenu { 114 | position: relative; 115 | } 116 | 117 | .dropdown-submenu>.dropdown-menu { 118 | top: 0; 119 | left: 100%; 120 | margin-top: -6px; 121 | margin-left: -1px; 122 | border-radius: 0 6px 6px 6px; 123 | } 124 | 125 | .dropdown-submenu:hover>.dropdown-menu { 126 | display: block; 127 | } 128 | 129 | .dropdown-submenu>a:after { 130 | display: block; 131 | content: " "; 132 | float: right; 133 | width: 0; 134 | height: 0; 135 | border-color: transparent; 136 | border-style: solid; 137 | border-width: 5px 0 5px 5px; 138 | border-left-color: #cccccc; 139 | margin-top: 5px; 140 | margin-right: -10px; 141 | } 142 | 143 | .dropdown-submenu:hover>a:after { 144 | border-left-color: #ffffff; 145 | } 146 | 147 | .dropdown-submenu.pull-left { 148 | float: none; 149 | } 150 | 151 | .dropdown-submenu.pull-left>.dropdown-menu { 152 | left: -100%; 153 | margin-left: 10px; 154 | border-radius: 6px 0 6px 6px; 155 | } 156 | 157 | /* Sidebar --------------------------*/ 158 | 159 | #pkgdown-sidebar { 160 | margin-top: 30px; 161 | position: -webkit-sticky; 162 | position: sticky; 163 | top: 70px; 164 | } 165 | 166 | #pkgdown-sidebar h2 { 167 | font-size: 1.5em; 168 | margin-top: 1em; 169 | } 170 | 171 | #pkgdown-sidebar h2:first-child { 172 | margin-top: 0; 173 | } 174 | 175 | #pkgdown-sidebar .list-unstyled li { 176 | margin-bottom: 0.5em; 177 | } 178 | 179 | /* bootstrap-toc tweaks ------------------------------------------------------*/ 180 | 181 | /* All levels of nav */ 182 | 183 | nav[data-toggle='toc'] .nav > li > a { 184 | padding: 4px 20px 4px 6px; 185 | font-size: 1.5rem; 186 | font-weight: 400; 187 | color: inherit; 188 | } 189 | 190 | nav[data-toggle='toc'] .nav > li > a:hover, 191 | nav[data-toggle='toc'] .nav > li > a:focus { 192 | padding-left: 5px; 193 | color: inherit; 194 | border-left: 1px solid #878787; 195 | } 196 | 197 | nav[data-toggle='toc'] .nav > .active > a, 198 | nav[data-toggle='toc'] .nav > .active:hover > a, 199 | nav[data-toggle='toc'] .nav > .active:focus > a { 200 | padding-left: 5px; 201 | font-size: 1.5rem; 202 | font-weight: 400; 203 | color: inherit; 204 | border-left: 2px solid #878787; 205 | } 206 | 207 | /* Nav: second level (shown on .active) */ 208 | 209 | nav[data-toggle='toc'] .nav .nav { 210 | display: none; /* Hide by default, but at >768px, show it */ 211 | padding-bottom: 10px; 212 | } 213 | 214 | nav[data-toggle='toc'] .nav .nav > li > a { 215 | padding-left: 16px; 216 | font-size: 1.35rem; 217 | } 218 | 219 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 220 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 221 | padding-left: 15px; 222 | } 223 | 224 | nav[data-toggle='toc'] .nav .nav > .active > a, 225 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 226 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 227 | padding-left: 15px; 228 | font-weight: 500; 229 | font-size: 1.35rem; 230 | } 231 | 232 | /* orcid ------------------------------------------------------------------- */ 233 | 234 | .orcid { 235 | font-size: 16px; 236 | color: #A6CE39; 237 | /* margins are required by official ORCID trademark and display guidelines */ 238 | margin-left:4px; 239 | margin-right:4px; 240 | vertical-align: middle; 241 | } 242 | 243 | /* Reference index & topics ----------------------------------------------- */ 244 | 245 | .ref-index th {font-weight: normal;} 246 | 247 | .ref-index td {vertical-align: top;} 248 | .ref-index .icon {width: 40px;} 249 | .ref-index .alias {width: 40%;} 250 | .ref-index-icons .alias {width: calc(40% - 40px);} 251 | .ref-index .title {width: 60%;} 252 | 253 | .ref-arguments th {text-align: right; padding-right: 10px;} 254 | .ref-arguments th, .ref-arguments td {vertical-align: top;} 255 | .ref-arguments .name {width: 20%;} 256 | .ref-arguments .desc {width: 80%;} 257 | 258 | /* Nice scrolling for wide elements --------------------------------------- */ 259 | 260 | table { 261 | display: block; 262 | overflow: auto; 263 | } 264 | 265 | /* Syntax highlighting ---------------------------------------------------- */ 266 | 267 | pre { 268 | word-wrap: normal; 269 | word-break: normal; 270 | border: 1px solid #eee; 271 | } 272 | 273 | pre, code { 274 | background-color: #f8f8f8; 275 | color: #333; 276 | } 277 | 278 | pre code { 279 | overflow: auto; 280 | word-wrap: normal; 281 | white-space: pre; 282 | } 283 | 284 | pre .img { 285 | margin: 5px 0; 286 | } 287 | 288 | pre .img img { 289 | background-color: #fff; 290 | display: block; 291 | height: auto; 292 | } 293 | 294 | code a, pre a { 295 | color: #375f84; 296 | } 297 | 298 | a.sourceLine:hover { 299 | text-decoration: none; 300 | } 301 | 302 | .fl {color: #1514b5;} 303 | .fu {color: #000000;} /* function */ 304 | .ch,.st {color: #036a07;} /* string */ 305 | .kw {color: #264D66;} /* keyword */ 306 | .co {color: #888888;} /* comment */ 307 | 308 | .message { color: black; font-weight: bolder;} 309 | .error { color: orange; font-weight: bolder;} 310 | .warning { color: #6A0366; font-weight: bolder;} 311 | 312 | /* Clipboard --------------------------*/ 313 | 314 | .hasCopyButton { 315 | position: relative; 316 | } 317 | 318 | .btn-copy-ex { 319 | position: absolute; 320 | right: 0; 321 | top: 0; 322 | visibility: hidden; 323 | } 324 | 325 | .hasCopyButton:hover button.btn-copy-ex { 326 | visibility: visible; 327 | } 328 | 329 | /* headroom.js ------------------------ */ 330 | 331 | .headroom { 332 | will-change: transform; 333 | transition: transform 200ms linear; 334 | } 335 | .headroom--pinned { 336 | transform: translateY(0%); 337 | } 338 | .headroom--unpinned { 339 | transform: translateY(-100%); 340 | } 341 | 342 | /* mark.js ----------------------------*/ 343 | 344 | mark { 345 | background-color: rgba(255, 255, 51, 0.5); 346 | border-bottom: 2px solid rgba(255, 153, 51, 0.3); 347 | padding: 1px; 348 | } 349 | 350 | /* vertical spacing after htmlwidgets */ 351 | .html-widget { 352 | margin-bottom: 10px; 353 | } 354 | 355 | /* fontawesome ------------------------ */ 356 | 357 | .fab { 358 | font-family: "Font Awesome 5 Brands" !important; 359 | } 360 | 361 | /* don't display links in code chunks when printing */ 362 | /* source: https://stackoverflow.com/a/10781533 */ 363 | @media print { 364 | code a:link:after, code a:visited:after { 365 | content: ""; 366 | } 367 | } 368 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('[data-toggle="tooltip"]').tooltip(); 13 | 14 | var cur_path = paths(location.pathname); 15 | var links = $("#navbar ul li a"); 16 | var max_length = -1; 17 | var pos = -1; 18 | for (var i = 0; i < links.length; i++) { 19 | if (links[i].getAttribute("href") === "#") 20 | continue; 21 | // Ignore external links 22 | if (links[i].host !== location.host) 23 | continue; 24 | 25 | var nav_path = paths(links[i].pathname); 26 | 27 | var length = prefix_length(nav_path, cur_path); 28 | if (length > max_length) { 29 | max_length = length; 30 | pos = i; 31 | } 32 | } 33 | 34 | // Add class to parent
  • , and enclosing
  • if in dropdown 35 | if (pos >= 0) { 36 | var menu_anchor = $(links[pos]); 37 | menu_anchor.parent().addClass("active"); 38 | menu_anchor.closest("li.dropdown").addClass("active"); 39 | } 40 | }); 41 | 42 | function paths(pathname) { 43 | var pieces = pathname.split("/"); 44 | pieces.shift(); // always starts with / 45 | 46 | var end = pieces[pieces.length - 1]; 47 | if (end === "index.html" || end === "") 48 | pieces.pop(); 49 | return(pieces); 50 | } 51 | 52 | // Returns -1 if not found 53 | function prefix_length(needle, haystack) { 54 | if (needle.length > haystack.length) 55 | return(-1); 56 | 57 | // Special case for length-0 haystack, since for loop won't run 58 | if (haystack.length === 0) { 59 | return(needle.length === 0 ? 0 : -1); 60 | } 61 | 62 | for (var i = 0; i < haystack.length; i++) { 63 | if (needle[i] != haystack[i]) 64 | return(i); 65 | } 66 | 67 | return(haystack.length); 68 | } 69 | 70 | /* Clipboard --------------------------*/ 71 | 72 | function changeTooltipMessage(element, msg) { 73 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 74 | element.setAttribute('data-original-title', msg); 75 | $(element).tooltip('show'); 76 | element.setAttribute('data-original-title', tooltipOriginalTitle); 77 | } 78 | 79 | if(ClipboardJS.isSupported()) { 80 | $(document).ready(function() { 81 | var copyButton = ""; 82 | 83 | $(".examples, div.sourceCode").addClass("hasCopyButton"); 84 | 85 | // Insert copy buttons: 86 | $(copyButton).prependTo(".hasCopyButton"); 87 | 88 | // Initialize tooltips: 89 | $('.btn-copy-ex').tooltip({container: 'body'}); 90 | 91 | // Initialize clipboard: 92 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 93 | text: function(trigger) { 94 | return trigger.parentNode.textContent; 95 | } 96 | }); 97 | 98 | clipboardBtnCopies.on('success', function(e) { 99 | changeTooltipMessage(e.trigger, 'Copied!'); 100 | e.clearSelection(); 101 | }); 102 | 103 | clipboardBtnCopies.on('error', function() { 104 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 105 | }); 106 | }); 107 | } 108 | })(window.jQuery || window.$) 109 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 2.9.1 2 | pkgdown: 1.5.1 3 | pkgdown_sha: ~ 4 | articles: 5 | betapal: betapal.html 6 | last_built: 2020-08-29T09:48Z 7 | 8 | -------------------------------------------------------------------------------- /docs/reference/beta_pal.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Beta parameters from interpretable conditions — beta_pal • parameterpal 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 62 | 63 | 64 | 65 | 66 | 67 | 68 |
    69 |
    70 | 116 | 117 | 118 | 119 |
    120 | 121 |
    122 |
    123 | 128 | 129 |
    130 |

    Rather than knowing intrinsically what parameters are required for a 131 | distribution, scientists tend to have a sense of what value they 132 | expect a measure to take, how much they expect observations to fall 133 | within a certain distance of that value.

    134 |
    135 | 136 |
    beta_pal(expected_value, within, this_much)
    137 | 138 |

    Arguments

    139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 |
    expected_value

    Expected value of beta distrbution from [0,1].

    within

    Specify distance this_much falls within.

    this_much

    What proportion falls within the specified interval.

    154 | 155 |

    Value

    156 | 157 |

    List of parameters appropriate for rbeta family of functions.

    158 |

    Details

    159 | 160 |

    This solution coded by by this most helpful 161 | gist.

    162 |

    Visualise the distribution with beta_plot. 163 | See vignette("beta_pal") for derivations and more information.

    164 | 165 |
    166 | 171 |
    172 | 173 | 174 |
    175 | 178 | 179 |
    180 |

    Site built with pkgdown 1.5.1.

    181 |
    182 | 183 |
    184 |
    185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /docs/reference/beta_plot.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Plot beta distribution — beta_plot • parameterpal 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 60 | 61 | 62 | 63 | 64 | 65 | 66 |
    67 |
    68 | 114 | 115 | 116 | 117 |
    118 | 119 |
    120 |
    121 | 126 | 127 |
    128 |

    This function utlises beta_pal to produce a visualisation of the beta 129 | distribution, with user-specified interpretable conditions.

    130 |
    131 | 132 |
    beta_plot(
    133 |   expected_value,
    134 |   within,
    135 |   this_much,
    136 |   caption_width = 70,
    137 |   theme_default = TRUE
    138 | )
    139 | 140 |

    Arguments

    141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 159 | 160 | 161 | 162 | 163 | 164 |
    expected_value

    Expected value of beta distrbution from [0,1].

    within

    Specify distance this_much falls within.

    this_much

    What proportion falls within the specified interval.

    caption_width

    Option to control the width of the caption, defaults to 158 | 70.

    theme_default

    Currently defaults to ggthemes::theme_tufte.

    165 | 166 | 167 |
    168 | 173 |
    174 | 175 | 176 |
    177 | 180 | 181 |
    182 |

    Site built with pkgdown 1.5.1.

    183 |
    184 | 185 |
    186 |
    187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-11-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/docs/reference/figures/README-unnamed-chunk-11-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-12-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/docs/reference/figures/README-unnamed-chunk-12-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-13-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/docs/reference/figures/README-unnamed-chunk-13-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-14-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/docs/reference/figures/README-unnamed-chunk-14-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-15-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/docs/reference/figures/README-unnamed-chunk-15-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/docs/reference/figures/README-unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/docs/reference/figures/README-unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/docs/reference/figures/README-unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/docs/reference/figures/README-unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/docs/reference/figures/README-unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /docs/reference/get_objective.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Objective function — get_objective • parameterpal 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 60 | 61 | 62 | 63 | 64 | 65 | 66 |
    67 |
    68 | 114 | 115 | 116 | 117 |
    118 | 119 |
    120 |
    121 | 126 | 127 |
    128 |

    Function that takes desrired mean, distance, and probability, and outputs 129 | another function to be optimized. Adapted into beta_pal.

    130 |
    131 | 132 |
    get_objective(desired_mean, desired_dist, desired_mass)
    133 | 134 |

    Arguments

    135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 149 | 150 |
    desired_mean

    expected_value.

    desired_dist

    within.

    desired_mass

    this_much.

    148 |

    This function is called by beta_pal internally.

    151 | 152 |

    Details

    153 | 154 |

    This solution coded by by this most helpful 155 | gist.

    156 | 157 |
    158 | 163 |
    164 | 165 | 166 |
    167 | 170 | 171 |
    172 |

    Site built with pkgdown 1.5.1.

    173 |
    174 | 175 |
    176 |
    177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | -------------------------------------------------------------------------------- /docs/reference/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Function reference • parameterpal 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 58 | 59 | 60 | 61 | 62 | 63 | 64 |
    65 |
    66 | 112 | 113 | 114 | 115 |
    116 | 117 |
    118 |
    119 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 148 | 149 | 150 | 151 | 154 | 155 | 156 | 157 | 160 | 161 | 162 | 163 |
    134 |

    All functions

    135 |

    136 |
    146 |

    beta_pal()

    147 |

    Beta parameters from interpretable conditions

    152 |

    beta_plot()

    153 |

    Plot beta distribution

    158 |

    get_objective()

    159 |

    Objective function

    164 |
    165 | 166 | 171 |
    172 | 173 | 174 |
    175 | 178 | 179 |
    180 |

    Site built with pkgdown 1.5.1.

    181 |
    182 | 183 |
    184 |
    185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /docs/reference/pipe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Pipe operator — %>% • parameterpal 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
    66 |
    67 | 113 | 114 | 115 | 116 |
    117 | 118 |
    119 |
    120 | 125 | 126 |
    127 |

    See magrittr::%>% for details.

    128 |
    129 | 130 |
    lhs %>% rhs
    131 | 132 | 133 | 134 |
    135 | 140 |
    141 | 142 | 143 | 153 |
    154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /inst/_pkgdown.yml: -------------------------------------------------------------------------------- 1 | home: 2 | title: parameterpal 3 | description: Beta parameters from interpretable conditions 4 | 5 | template: 6 | params: 7 | bootswatch: sandstone 8 | opengraph: 9 | twitter: 10 | creator: "@cantabile" 11 | site: "@MMetaresearch" 12 | -------------------------------------------------------------------------------- /inst/tutorials/ppalhelp/README.md: -------------------------------------------------------------------------------- 1 | # parameterparTutorial 2 | This Learnr tutorial was made for the `parameterpar`package made by @sofloud 3 | 4 | To bundle a tutorial into an R package: 5 | 6 | 1. Create a tutorials directory within the `inst` sub-directory of your package and then create a directory for your tutorial there (e.g. inst/tutorials/parameterparTutorial). 7 | 2. Add the .Rmd associated with your tutorial in that directory. (You may see a ..._files/_ directory or a .html file that periodically get generated adjacent to your .Rmd tutorial. You can safely ignore, delete, or exclude these from your package and from version control. They are temporary artifacts produced while rendering the tutorial on your specific system and aren’t likely to be portable to other environments.) 8 | 3. Add the `css` folder with the css file for the personalized styles for you package. 9 | -------------------------------------------------------------------------------- /inst/tutorials/ppalhelp/css/miceeseese.css: -------------------------------------------------------------------------------- 1 | /****** 2 | This css is based in Allison Horst custom css https://github.com/allisonhorst/explore-na/blob/master/css/custom_css.css 3 | *******/ 4 | 5 | body { 6 | background-color: #ffffff; 7 | } 8 | 9 | em { 10 | color: purple; 11 | } 12 | 13 | .ace-tm { 14 | background-color: #ffffff; 15 | color: black; 16 | } 17 | 18 | .panel, pre { 19 | border-radius: 0; 20 | border-color: #e0e0e0; 21 | background-color: #ffffff; 22 | } 23 | 24 | .panel-default > .panel-heading { 25 | color: #555555; 26 | background-color: #ffffff; 27 | border-color: #dddddd; 28 | } 29 | 30 | .topicsList .topic { 31 | line-height: 40px; 32 | font-size: 15px; 33 | padding-left: 10px; 34 | cursor: pointer; 35 | background-repeat: no-repeat; 36 | background-size: 2px 80px; 37 | background-position: left 100%; 38 | background-position-y: 100%; 39 | border-bottom: 1px solid purple; 40 | -webkit-transition-property: background-position; 41 | transition-property: background-position; 42 | -webkit-transition-duration: 0.25s; 43 | transition-duration: 0.25s; 44 | } 45 | 46 | .topicsList .topic.current { 47 | background-color: purple; 48 | color: #ffffff; 49 | border: 0px; 50 | } 51 | 52 | code { 53 | color: gray; 54 | background-color: #eee1fc; 55 | font-size: 12px; 56 | } 57 | 58 | a { 59 | color: purple; 60 | text-decoration: none; 61 | } 62 | 63 | .btn-primary, .btn-success, .btn-info { 64 | color: #ffffff; 65 | background-color: purple; 66 | background-image: none; 67 | border: none; 68 | } 69 | 70 | .btn-default { 71 | color: #ffffff; 72 | background-color: purple; 73 | background-image: none; 74 | border: none; 75 | } 76 | 77 | h2 { 78 | color: purple; 79 | } 80 | 81 | h3 { 82 | color: purple; 83 | } 84 | 85 | h4 { 86 | color: purple; 87 | } 88 | 89 | h5 { 90 | color: purple; 91 | background-color: white; 92 | display: inline-block; 93 | } -------------------------------------------------------------------------------- /inst/tutorials/ppalhelp/parameterpal_help.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Obtain beta parameters from interpretable conditions." 3 | author: "Charles T. Gray" 4 | date: "`r Sys.Date()`" 5 | output: 6 | learnr::tutorial: 7 | progressive: true 8 | allow_skip: true 9 | css: css/miceeseese.css 10 | runtime: shiny_prerendered 11 | tutorial: 12 | version: 1.0 13 | description: "This tutorial presents a interactive version of vignettes for the parameterpal package" 14 | --- 15 | 16 | ```{r setup, include=FALSE} 17 | library(learnr) 18 | library(parameterpal) 19 | library(ggplot2) 20 | knitr::opts_chunk$set( 21 | collapse = TRUE, 22 | comment = "#>", 23 | fig.width = 5 24 | ) 25 | ``` 26 | 27 | ## Introduction 28 | 29 | Do you use beta distributions in your science? Do you find the parameters uninterpretable? 30 | 31 | Obtain parameters for the beta distribution from interpretable conditions. 32 | 33 | ### installation 34 | 35 | ```{r eval=FALSE} 36 | devtools::install_github("softloud/parameterpal", build_vignettes = TRUE) 37 | ``` 38 | 39 | 40 | ## Using parameterpal:: 41 | 42 | ```{r} 43 | library(parameterpal) 44 | ``` 45 | 46 | 47 | 48 | ```{r} 49 | usage_example <- list( 50 | expected_value = 0.3, 51 | within = 0.2, 52 | this_much = 0.8 53 | ) 54 | ``` 55 | 56 | Suppose we expect a value of `r usage_example$expected_value`, with `r 100 * usage_example$this_much` per cent of observations falling within a distance of `r usage_example$within` from `r usage_example$expected_value`. 57 | 58 | That is, we expect `r 100 * usage_example$this_much` per cent of observations to fall within (`r usage_example$expected_value - usage_example$within`, `r usage_example$expected_value + usage_example$within`). Assuming data follow a beta distribution, what are its parameters? 59 | 60 | ```{r} 61 | beta_pal(expected_value = usage_example$expected_value, 62 | within = usage_example$within, 63 | this_much = usage_example$this_much) 64 | ``` 65 | 66 | We can plot this intuition to see the shape of the resulting beta distribution. 67 | 68 | ```{r } 69 | beta_plot(expected_value = usage_example$expected_value, 70 | within = usage_example$within, 71 | this_much = usage_example$this_much) 72 | ``` 73 | 74 | Specifying the width enables us to escape the ubiquitous tyranny of the arbitary bounds of 95 per cent, which doesn't necessarily reflect our intuition, suppose we thought only 75 | 76 | ```{r} 77 | new_example_width <- 0.3 78 | 79 | ``` 80 | 81 | 82 | `r new_example_width * 100` per cent of values fall within the interval. 83 | 84 | ```{r } 85 | beta_pal(expected_value = usage_example$expected_value, 86 | within = usage_example$within, 87 | this_much = new_example_width) 88 | ``` 89 | 90 | ## Exercises 91 | 92 | ### Plotting 93 | 94 | Lest try to use `parameterpal` in this interactive code chunks. Whenever you encounter one, you can click _Submit Answer_ to run (or re-run) the code in the chunk. If there is a _Solution_ button, you can click it to see a proposed answer. 95 | 96 | Complete the code below with your own values and run de code to see the result 97 | 98 | ```{r using_parameterpal_plot, exercise=TRUE} 99 | 100 | beta_plot(expected_value = ___, 101 | within = ___, 102 | this_much = ___) 103 | 104 | ``` 105 | 106 | ```{r using_parameterpal_plot-hint} 107 | 108 | Remeber that you _expect a value_, with a per cent of observations falling _within_ a distance from that _expected_value_. 109 | 110 | ``` 111 | 112 | ```{r using_parameterpal_plot-solution} 113 | 114 | # This is an example solution, 115 | # you can use any value that you need in every argument of the beta_plot function 116 | beta_plot(expected_value = 0.5, 117 | within = 0.3, 118 | this_much = 0.9) 119 | 120 | ``` 121 | 122 | ### Getting the parameters 123 | 124 | Now, you can try to get the parameters. Complete the code below with your own values and run de code to see the result. 125 | 126 | 127 | ```{r using_parameterpal, exercise=TRUE} 128 | beta_pal(expected_value = ___, 129 | within = ___, 130 | this_much = ___) 131 | ``` 132 | 133 | ```{r using_parameterpal-hint} 134 | 135 | Remeber that you _expect a value_, with a per cent of observations falling _within_ a distance from that _expected_value_. 136 | 137 | ``` 138 | 139 | ```{r using_parameterpal-solution} 140 | # This is an example solution, 141 | # you can use any value that you need in every argument of the beta_plot function 142 | 143 | beta_pal(expected_value = 0.5, 144 | within = 0.3, 145 | this_much = 0.9) 146 | 147 | ``` 148 | 149 | ## Motivation 150 | 151 | Rather than knowing intrinsically what parameters are required for a distribution, scientists tend to have indirect knowledge. A researcher may have a sense of what value they *expect* a measure to take, *how many* observations should fall *within* a certain distance of that value. As well as the overall shape of the data, the distribution. Distributions are not defined in the intuitive terms the scientist has, but equational parameters commonly (but not always) $\mu$ and $\sigma$ for the normal distribution, $\lambda$ for the exponential, and $\alpha$ and $\beta$ for the beta distribution. However, calculating the required parameters is not necessarily straightfoward, despite the conditioning we receive from the normal distribution. 152 | 153 | ```{r} 154 | # set normal distribution example parameters 155 | norm_expected_value <- 0.5 156 | norm_within <- 0.2 157 | ``` 158 | 159 | 160 | For the normal distribution, obtaining the parameters from these assumptions is straightforward. The expected value and variance, which is to say, centre and spread, of the normal distribution, are both easily interpretable and translate directly to the parameters required for the distribution. So, to sample three values from a normal distribution where we expect a value of `r norm_expected_value` with two-thirds of values falling within `r norm_within` of `r norm_expected_value`, we simply run the following code. 161 | 162 | ```{r} 163 | rnorm(n = 3, 164 | mean = norm_expected_value, 165 | sd = norm_within) 166 | ``` 167 | 168 | 169 | The first parameter is the expected value, and the second, the variance. For the normal distribution, the standard deviation is interpretable. We know two-thirds of values fall within one standard deviation of the mean. If we shade this area in a visualisation, it's convincing that two-thirds of values fall within this range. 170 | 171 | ```{r} 172 | library(ggplot2) 173 | ggplot() + 174 | xlim(0, 1) + 175 | geom_rect( 176 | aes( 177 | xmin = norm_expected_value - norm_within, 178 | xmax = norm_expected_value + norm_within, 179 | ymin = 0, 180 | ymax = Inf, 181 | alpha = 0.2)) + 182 | stat_function( 183 | fun = dnorm, 184 | args = list(mean = norm_expected_value, sd = norm_within) 185 | ) + 186 | theme(legend.position = "none") + 187 | labs( 188 | y = NULL, 189 | title = sprintf("normal(%g, %g)", norm_expected_value, norm_within), 190 | caption = sprintf("Two-thirds of normally distributed values fall within %g of %g.", norm_expected_value, norm_within) 191 | ) 192 | ``` 193 | 194 | The beta distribution, on the other hand, requires two shape parameters, `shape1` and `shape2`, which do not immediately reflect our intuition of what value we expect the measure to take, nor how much variance we expect. 195 | 196 | 197 | 198 | But if we wished to sample from beta distribution, however, the parameters, `shape1` and `shape2`, are not readily interpretable from expected value and variance. `parameterpal::` provides a means of obtaining the parameters required for the beta distribution from interpretable conditions. 199 | 200 | ## beta distribution 201 | 202 | The beta distribution has some really nice properties. It is bounded by a minimum value of 0 and a maximum of 1, so is perfect for modeling proportions. 203 | 204 | Under some circumstances it can mimic a truncated bell curve, as well as flexibility for other shapes, such as a truncated parabola. 205 | 206 | But this is not intuitive. What shape do we expect $\mathrm{beta}(1,2)$ to take? It's hard to intuit from the parameters 1 and 2. But, we likely do not expect a negatively sloped line. 207 | 208 | ```{r} 209 | ggplot() + 210 | xlim(0, 1) + 211 | stat_function( 212 | fun = dbeta, 213 | args = list(shape1 = 1, shape2 = 2) 214 | ) 215 | ``` 216 | 217 | 218 | ## Original application 219 | 220 | This code was developed for [`softloud/simeta::`](https://github.com/softloud/simeta), research software that supported `softloud`'s dissertation. This problem is a very small component of a larger collection of simulation functions for randomly generating meta-analysis data. 221 | 222 | In this case, given a population $N$, what proportion are allocated to the case and control groups? A desire to reflect the uncertainty of designed experiments motivated this code. 223 | 224 | For example, even if case and control groups were assigned evenly, in experimental science there are many reasons individuals may drop out of the groups. Thus a proportion of $N$ was sampled from a beta distribution (which is bounded between 0 and 1, as proportions are, too), with an intuition of how many drop outs are anticipated. 225 | 226 | ## Citing this package 227 | 228 | ```{r warning=FALSE} 229 | citation(package = "parameterpal") 230 | ``` 231 | 232 | ## Contributing and Maintaining 233 | 234 | Contributions are very welcome. By submitting your work, you are agreeing that it may incorporated in either original or edited form and released under the same license as the rest of this material (see License). If your contribution is incorporated, I will add you to the acknowledgments (unless you request otherwise). 235 | 236 | The source code for this package is stored on GitHub at: 237 | 238 | https://github.com/softloud/parameterpal 239 | 240 | If you know how to use Git and GitHub and would like to change, fix, or add something, please submit a pull request. If you want to report an error, ask a question, or make a suggestion, please file an issue in the repository. You need to have a GitHub account in order to do this, but do not need to know how to use Git. 241 | 242 | Finally, I always enjoy hearing how people have used this package. 243 | 244 | 245 | ## License 246 | 247 | Copyright (c) 2020 Charles Gray 248 | 249 | This packages is licensed under the [MIT License ](https://opensource.org/licenses/MIT) 250 | 251 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 252 | 253 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 254 | 255 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /man/beta_pal.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/beta_pal.R 3 | \name{beta_pal} 4 | \alias{beta_pal} 5 | \title{Beta parameters from interpretable conditions} 6 | \usage{ 7 | beta_pal(expected_value, within, this_much) 8 | } 9 | \arguments{ 10 | \item{expected_value}{Expected value of beta distrbution from [0,1].} 11 | 12 | \item{within}{Specify distance \code{this_much} falls within.} 13 | 14 | \item{this_much}{What proportion falls \code{within} the specified interval.} 15 | } 16 | \value{ 17 | List of parameters appropriate for \link{rbeta} family of functions. 18 | } 19 | \description{ 20 | Rather than knowing intrinsically what parameters are required for a 21 | distribution, scientists tend to have a sense of what value they 22 | \emph{expect} a measure to take, \emph{how much} they expect observations to fall 23 | \emph{within} a certain distance of that value. 24 | } 25 | \details{ 26 | This solution coded by by this most helpful 27 | \href{https://gist.github.com/daob/1422e978ff98bdf466fbcb4d9bf3e53e}{gist}. 28 | 29 | Visualise the distribution with \link{beta_plot}. 30 | See \code{vignette("beta_pal")} for derivations and more information. 31 | } 32 | -------------------------------------------------------------------------------- /man/beta_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/beta_plot.R 3 | \name{beta_plot} 4 | \alias{beta_plot} 5 | \title{Plot beta distribution} 6 | \usage{ 7 | beta_plot( 8 | expected_value, 9 | within, 10 | this_much, 11 | caption_width = 70, 12 | theme_default = TRUE 13 | ) 14 | } 15 | \arguments{ 16 | \item{expected_value}{Expected value of beta distrbution from [0,1].} 17 | 18 | \item{within}{Specify distance \code{this_much} falls within.} 19 | 20 | \item{this_much}{What proportion falls \code{within} the specified interval.} 21 | 22 | \item{caption_width}{Option to control the width of the caption, defaults to 23 | 70.} 24 | 25 | \item{theme_default}{Currently defaults to \code{ggthemes::theme_tufte}.} 26 | } 27 | \description{ 28 | This function utlises \link{beta_pal} to produce a visualisation of the beta 29 | distribution, with user-specified interpretable conditions. 30 | } 31 | -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-11-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/man/figures/README-unnamed-chunk-11-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-12-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/man/figures/README-unnamed-chunk-12-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-13-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/man/figures/README-unnamed-chunk-13-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-14-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/man/figures/README-unnamed-chunk-14-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-15-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/man/figures/README-unnamed-chunk-15-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/man/figures/README-unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/man/figures/README-unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/man/figures/README-unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/man/figures/README-unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softloud/parameterpal/003bd0c0da0c1ff877aa9ae2c9c1934bc73467dd/man/figures/README-unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /man/get_objective.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_objective.R 3 | \name{get_objective} 4 | \alias{get_objective} 5 | \title{Objective function} 6 | \usage{ 7 | get_objective(desired_mean, desired_dist, desired_mass) 8 | } 9 | \arguments{ 10 | \item{desired_mean}{expected_value.} 11 | 12 | \item{desired_dist}{within.} 13 | 14 | \item{desired_mass}{this_much. 15 | 16 | This function is called by \link{beta_pal} internally.} 17 | } 18 | \description{ 19 | Function that takes desrired mean, distance, and probability, and outputs 20 | another function to be optimized. Adapted into \link{beta_pal}. 21 | } 22 | \details{ 23 | This solution coded by by this most helpful 24 | \href{https://gist.github.com/daob/1422e978ff98bdf466fbcb4d9bf3e53e}{gist}. 25 | } 26 | -------------------------------------------------------------------------------- /man/pipe.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-pipe.R 3 | \name{\%>\%} 4 | \alias{\%>\%} 5 | \title{Pipe operator} 6 | \usage{ 7 | lhs \%>\% rhs 8 | } 9 | \description{ 10 | See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /parameterpal.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace,vignette 22 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(parameterpal) 3 | 4 | test_check("parameterpal") 5 | -------------------------------------------------------------------------------- /tests/testthat/test-beta_plot.R: -------------------------------------------------------------------------------- 1 | expected_value <- 0.3 2 | this_much <- 0.9 3 | within <- 0.2 4 | 5 | # should this be an S3 method 6 | 7 | test_that("beta plot makes a plot", { 8 | expect_s3_class(beta_plot(expected_value, this_much, within), "ggplot") 9 | }) 10 | -------------------------------------------------------------------------------- /tests/testthat/test-betapal.R: -------------------------------------------------------------------------------- 1 | expected_value <- 0.3 2 | this_much <- 0.9 3 | within <- 0.2 4 | 5 | test_that("betapal produces list", { 6 | expect_type(beta_pal(expected_value, this_much, within), "list") 7 | }) 8 | 9 | 10 | test_that("betapal gets correct answers", { 11 | betapars <- beta_pal(expected_value, this_much, within) 12 | 13 | approx_mean <- rbeta(1e5, betapars[[1]], betapars[[2]]) %>% mean() 14 | 15 | approx_mass <- 16 | pbeta(q = expected_value + within, betapars[[1]], betapars[[2]]) - 17 | pbeta(q = expected_value - within, betapars[[1]], betapars[[2]]) 18 | 19 | expect_true(abs(approx_mean - expected_value) < 0.1) 20 | 21 | expect_true(abs(approx_mass - this_much) < 0.1) 22 | 23 | 24 | }) 25 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /vignettes/betapal.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Obtain beta parameters from interpretable conditions" 3 | author: "Charles T. Gray" 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{betapal} 8 | %\VignetteEngine{knitr::rmarkdown} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | ```{r, include = FALSE} 13 | knitr::opts_chunk$set( 14 | collapse = TRUE, 15 | comment = "#>", 16 | fig.width = 5 17 | ) 18 | 19 | options(rmarkdown.html_vignette.check_title = FALSE) 20 | 21 | ``` 22 | 23 | 24 | Do you use beta distributions in your science? Do you find the parameters uninterpretable? 25 | 26 | Obtain parameters for the beta distribution from interpretable conditions. 27 | 28 | ## installation 29 | 30 | ```{r eval=FALSE} 31 | devtools::install_github("softloud/parameterpal", build_vignettes = TRUE) 32 | ``` 33 | 34 | 35 | ## using `parameterpal::` 36 | 37 | ```{r} 38 | library(parameterpal) 39 | ``` 40 | 41 | 42 | 43 | ```{r} 44 | usage_example <- list( 45 | expected_value = 0.3, 46 | within = 0.2, 47 | this_much = 0.8 48 | ) 49 | 50 | 51 | ``` 52 | 53 | Suppose we expect a value of `r usage_example$expected_value`, with `r 100 * usage_example$this_much` per cent of observations falling within a distance of `r usage_example$within` from `r usage_example$expected_value`. 54 | 55 | That is, we expect `r 100 * usage_example$this_much` per cent of observations to fall within (`r usage_example$expected_value - usage_example$within`, `r usage_example$expected_value + usage_example$within`). Assuming data follow a beta distribution, what are its parameters? 56 | 57 | ```{r} 58 | beta_pal(expected_value = usage_example$expected_value, 59 | within = usage_example$within, 60 | this_much = usage_example$this_much) 61 | 62 | ``` 63 | 64 | We can plot this intuition to see the shape of the resulting beta distribution. 65 | 66 | ```{r } 67 | beta_plot(expected_value = usage_example$expected_value, 68 | within = usage_example$within, 69 | this_much = usage_example$this_much) 70 | 71 | ``` 72 | 73 | Specifying the width enables us to escape the ubiquitous tyranny of the arbitary bounds of 95 per cent, which doesn't necessarily reflect our intuition, suppose we thought only 74 | 75 | ```{r} 76 | new_example_width <- 0.3 77 | 78 | ``` 79 | 80 | 81 | `r new_example_width * 100` per cent of values fall within the interval. 82 | 83 | ```{r } 84 | beta_pal(expected_value = usage_example$expected_value, 85 | within = usage_example$within, 86 | this_much = new_example_width) 87 | 88 | ``` 89 | 90 | ## motivation 91 | 92 | Rather than knowing intrinsically what parameters are required for a distribution, scientists tend to have indirect knowledge. A researcher may have a sense of what value they *expect* a measure to take, *how many* observations should fall *within* a certain distance of that value. As well as the overall shape of the data, the distribution. Distributions are not defined in the intuitive terms the scientist has, but equational parameters commonly (but not always) $\mu$ and $\sigma$ for the normal distribution, $\lambda$ for the exponential, and $\alpha$ and $\beta$ for the beta distribution. However, calculating the required parameters is not necessarily straightfoward, despite the conditioning we receive from the normal distribution. 93 | 94 | ```{r} 95 | # set normal distribution example parameters 96 | norm_expected_value <- 0.5 97 | norm_within <- 0.2 98 | 99 | ``` 100 | 101 | 102 | For the normal distribution, obtaining the parameters from these assumptions is straightforward. The expected value and variance, which is to say, centre and spread, of the normal distribution, are both easily interpretable and translate directly to the parameters required for the distribution. So, to sample three values from a normal distribution where we expect a value of `r norm_expected_value` with two-thirds of values falling within `r norm_within` of `r norm_expected_value`, we simply run the following code. 103 | 104 | ```{r} 105 | rnorm(n = 3, 106 | mean = norm_expected_value, 107 | sd = norm_within) 108 | 109 | ``` 110 | 111 | 112 | The first parameter is the expected value, and the second, the variance. For the normal distribution, the standard deviation is interpretable. We know two-thirds of values fall within one standard deviation of the mean. If we shade this area in a visualisation, it's convincing that two-thirds of values fall within this range. 113 | 114 | ```{r} 115 | 116 | library(ggplot2) 117 | 118 | ggplot() + 119 | xlim(0, 1) + 120 | geom_rect( 121 | aes( 122 | xmin = norm_expected_value - norm_within, 123 | xmax = norm_expected_value + norm_within, 124 | ymin = 0, 125 | ymax = Inf, 126 | alpha = 0.2)) + 127 | stat_function( 128 | fun = dnorm, 129 | args = list(mean = norm_expected_value, sd = norm_within) 130 | ) + 131 | theme(legend.position = "none") + 132 | labs( 133 | y = NULL, 134 | title = sprintf("normal(%g, %g)", norm_expected_value, norm_within), 135 | caption = sprintf("Two-thirds of normally distributed values fall within %g of %g.", norm_within, norm_expected_value) 136 | ) 137 | 138 | 139 | ``` 140 | 141 | The beta distribution, on the other hand, requires two shape parameters, `shape1` and `shape2`, which do not immediately reflect our intuition of what value we expect the measure to take, nor how much variance we expect. 142 | 143 | 144 | 145 | But if we wished to sample from beta distribution, however, the parameters, `shape1` and `shape2`, are not readily interpretable from expected value and variance. `parameterpal::` provides a means of obtaining the parameters required for the beta distribution from interpretable conditions. 146 | 147 | ## beta distribution 148 | 149 | The beta distribution has some really nice properties. It is bounded by a minimum value of 0 and a maximum of 1, so is perfect for modeling proportions. 150 | 151 | Under some circumstances it can mimic a truncated bell curve, as well as flexibility for other shapes, such as a truncated parabola. 152 | 153 | But this is not intuitive. What shape do we expect $\mathrm{beta}(1,2)$ to take? It's hard to intuit from the parameters 1 and 2. But, we likely do not expect a negatively sloped line. 154 | 155 | ```{r} 156 | ggplot() + 157 | xlim(0, 1) + 158 | stat_function( 159 | fun = dbeta, 160 | args = list(shape1 = 1, shape2 = 2) 161 | ) 162 | 163 | 164 | 165 | ``` 166 | 167 | 168 | ## original application 169 | 170 | This code was developed for [`softloud/simeta::`](https://github.com/softloud/simeta), research software that supported `softloud`'s dissertation. This problem is a very small component of a larger collection of simulation functions for randomly generating meta-analysis data. 171 | 172 | In this case, given a population $N$, what proportion are allocated to the case and control groups? A desire to reflect the uncertainty of designed experiments motivated this code. 173 | 174 | For example, even if case and control groups were assigned evenly, in experimental science there are many reasons individuals may drop out of the groups. Thus a proportion of $N$ was sampled from a beta distribution (which is bounded between 0 and 1, as proportions are, too), with an intuition of how many drop outs are anticipated. 175 | 176 | # citing this package 177 | 178 | ```{r} 179 | citation(package = "parameterpal") 180 | 181 | ``` 182 | 183 | --------------------------------------------------------------------------------