Skip to content

Commit

Permalink
Port package dev version over to fresh repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Doi90 committed Sep 1, 2022
1 parent af8772a commit 8f6ce80
Show file tree
Hide file tree
Showing 164 changed files with 21,064 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ..Rcheck/00check.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
* using log directory ‘/home/cantabile/Documents/repos/aggreCAT/..Rcheck’
* using R version 3.6.2 (2019-12-12)
* using platform: x86_64-pc-linux-gnu (64-bit)
* using session charset: UTF-8
* checking for file ‘./DESCRIPTION’ ... ERROR
Required fields missing or empty:
‘Author’ ‘Maintainer’
* DONE
Status: 1 ERROR
25 changes: 25 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
^aggreCAT\.Rproj$
^\.Rproj\.user$
^LICENSE\.md$
^README\.Rmd$
^\.travis\.yml$
^codemeta\.json$
^\.github$
^codecov\.yml$
^archived$
^data-raw$
^resources$
^analysis$
^data-export$
^data-anon$
^aggreCAT$
Mixed_Methods_Analysis.html
Mixed_Methods_Analysis.Rmd
SIPS_ArMean_figure.png
SIPS_cs.csv
^doc$
^Meta$
vignettes/test_table.Rmd
^ms$
^test_tble$
^test$
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
docs/* linguist-detectable=false
*.html linguist-detectable=false
*.css linguist-detectable=false
*.js linguist-detectable=false
*.tex linguist-detectable=false
93 changes: 93 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Package: aggreCAT
Title: Mathematically Aggregating Expert Judgments
Version: 0.0.0.9000
Authors@R: c(person(given = "Aaron",
family = "Willcox",
role = "aut",
email = " [email protected]",
comment = structure("0000-0003-2536-2596", .Names = "ORCID")),
person(given = "Charles",
family = "Gray",
role = c("aut"),
comment = structure("00000-0002-9978-011X", .Names = "ORCID")),
person(given = "Elliot",
family = "Gould",
role = "aut",
comment = structure("0000-0002-6585-538X", .Names = "ORCID")),
person(given = "David",
family = "Wilkinson",
role = c("aut", "cre"),
email = "[email protected]",
comment = structure("0000-0002-9560-6499", .Names = "ORCID")
),
person(given = "Anca",
family = "Hanea",
role = "aut",
comment = structure("0000-0003-3870-5949", .Names = "ORCID")),
person(given = "Bonnie",
family = "Wintle",
role = "aut",
comment = structure("0000-0003-0236-6906", .Names = "ORCID")),
person(given = "Rose",
family = "E. O'Dea",
role = "aut",
comment = structure("0000-0001-8177-5075", .Names = "ORCID"))
)
Description: Aggregator methods for confidence scores.
URL: https://replicats.research.unimelb.edu.au/
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
Suggests:
testthat (>= 2.1.0),
knitr,
rmarkdown,
covr,
pointblank,
janitor,
DescTools,
qualtRics,
here,
readxl,
readr,
stats,
lubridate,
forcats,
ggforce,
ggpubr,
ggridges,
rjags,
tidybayes,
tidyverse,
usethis,
nlme,
gt,
gtExtras
RoxygenNote: 7.2.1
Depends:
R (>= 2.10)
Imports:
magrittr,
GoFKernel,
purrr,
R2jags,
coda,
precrec,
mathjaxr,
cli,
VGAM,
crayon,
dplyr,
rfUtilities,
stringr,
tidyr,
tibble,
ggplot2,
insight
Remotes:
softloud/neet
VignetteBuilder: knitr
RdMacros: mathjaxr
Config/testthat/parallel: true
Config/testthat/edition: 3
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YEAR: 2020
COPYRIGHT HOLDER: Charles Gray
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MIT License

Copyright (c) 2020 Charles Gray

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:

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

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.
28 changes: 28 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(AverageWAgg)
export(BayesianWAgg)
export(DistributionWAgg)
export(ExtremisationWAgg)
export(IntervalWAgg)
export(LinearWAgg)
export(ReasoningWAgg)
export(ShiftingWAgg)
export(confidence_score_evaluation)
export(confidence_score_heatmap)
export(confidence_score_ridgeplot)
export(method_placeholder)
export(postprocess_judgements)
export(preprocess_judgements)
export(weight_asym)
export(weight_interval)
export(weight_nIndivInterval)
export(weight_outlier)
export(weight_reason)
export(weight_reason2)
export(weight_varIndivInterval)
importFrom(insight,format_capitalize)
importFrom(magrittr,"%>%")
importFrom(stats,median)
importFrom(stats,var)
174 changes: 174 additions & 0 deletions R/AverageWAgg.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#' @title
#' Aggregation Method: AverageWAgg
#'
#' @description
#' Calculate one of several types of averaged best estimates.
#'
#' @details
#' This function returns the average, median and transformed averages of
#' best-estimate judgements for each claim.
#'
#' `type` may be one of the following:
#' \loadmathjax
#'
#' **ArMean**: Arithmetic mean of the best estimates
#' \mjdeqn{\hat{p}_c\left(ArMean \right ) = \frac{1}{N}\sum_{i=1}^N B_{i,c}}{ascii}
#' **Median**: Median of the best estimates
#' \mjdeqn{\hat{p}_c \left(\text{median} \right) = \text{median} \{ B^i_c\}_{i=1,...,N}}{ascii}
#' **GeoMean**: Geometric mean of the best estimates
#' \mjdeqn{GeoMean_{c}= \left(\prod_{i=1}^N B_{i,c}\right)^{\frac{1}{N}}}{ascii}
#' **LOArMean**: Arithmetic mean of the log odds transformed best estimates
#' \mjdeqn{LogOdds_{i,c}= \frac{1}{N} \sum_{i=1}^N log\left( \frac{B_{i,c}}{1-B_{i,c}}\right)}{ascii}
#' The average log odds estimate is then back transformed to give a final group estimate:
#' \mjdeqn{\hat{p}_c\left( LOArMean \right) = \frac{e^{LogOdds_{i,c}}}{1+e^{LogOdds_{i,c}}}}{ascii}
#' **ProbitArMean**: Arithmetic mean of the probit transformed best estimates
#' \mjdeqn{Probit_{c}= \frac{1}{N} \sum_{i=1}^N \Phi^{-1}\left( B_{i,c}\right)}{ascii}
#' The average probit estimate is then back transformed to give a final group estimate:
#' \mjdeqn{\hat{p}_c\left(ProbitArMean \right) = \Phi\left({Probit_{c}}\right)}{ascii}
#'
#' @param expert_judgements A dataframe in the format of [data_ratings].
#' @param type One of `"ArMean"`, `"Median"`, `"GeoMean"`, `"LOArMean"`, or `"ProbitArMean"`.
#' @param name Name for aggregation method. Defaults to `type` unless specified.
#' @param placeholder Toggle the output of the aggregation method to impute placeholder data.
#' @param percent_toggle Change the values to probabilities. Default is `FALSE`.
#'
#' @return A tibble of confidence scores `cs` for each `paper_id`.
#'
#' @examples
#' \dontrun{AverageWAgg(data_ratings)}
#'
#' @export
#' @md

AverageWAgg <- function(expert_judgements,
type = "ArMean",
name = NULL,
placeholder = FALSE,
percent_toggle = FALSE) {

if(!(type %in% c("ArMean",
"GeoMean",
"Median",
"LOArMean",
"LOGeoMean",
"ProbitArMean"))){

stop('`type` must be one of "ArMean", "GeoMean", "Median", "LOArMean", "LOGeoMean", or "ProbitArMean"')

}

## Set name argument

name <- ifelse(is.null(name),
type,
name)

cli::cli_h1(sprintf("AverageWAgg: %s",
name))

if(isTRUE(placeholder)){

method_placeholder(expert_judgements,
name)

} else {

df <- expert_judgements %>%
preprocess_judgements(percent_toggle = {{percent_toggle}}) %>%
dplyr::filter(element == "three_point_best") %>%
dplyr::group_by(paper_id)

switch(type,
"ArMean" = {

df <- df %>%
dplyr::summarise(
aggregated_judgement = mean(value,
na.rm = TRUE),
n_experts = dplyr::n()
)

},
"GeoMean" = {

df <- df %>%
dplyr::summarise(n_experts = dplyr::n(),
aggregated_judgement = (prod(value, na.rm = TRUE)) ^ (1/n_experts))

},
"Median" = {

df <- df %>%
dplyr::summarise(
aggregated_judgement = median(value,
na.rm = TRUE),
n_experts = dplyr::n()
)

},
"LOArMean" = {

if(any(df$value < 0) | any(df$value > 1)){

stop("LOArMean requires probabilistic judgements. Check your data compatability or `percent_toggle` argument.")

}

df <- df %>%
dplyr::mutate(value = dplyr::case_when(value == 1 ~ value - .Machine$double.eps,
value == 0 ~ value + .Machine$double.eps,
TRUE ~ value),
log_odds = log(abs(value / (1 - value)))) %>%
dplyr::summarise(
aggregated_judgement = mean(log_odds,
na.rm = TRUE),
n_experts = dplyr::n()
) %>%
dplyr::mutate(
aggregated_judgement = exp(aggregated_judgement) / (1 + exp(aggregated_judgement))
)

},
"LOGeoMean" = {

if(any(df$value < 0) | any(df$value > 1)){

stop("LOGeoMean requires probabilistic judgements. Check your data compatability or `percent_toggle` argument.")

}

df <- df %>%
dplyr::mutate(value = dplyr::case_when(value == 1 ~ value - .Machine$double.eps,
value == 0 ~ value + .Machine$double.eps,
value == 0.5 ~ value + .Machine$double.eps,
TRUE ~ value),
log_odds = log(abs(value / (1 - value)))) %>%
# dplyr::summarise(n_experts = dplyr::n(),
# aggregated_judgement = (prod(log_odds, na.rm = TRUE))) %>%
dplyr::summarise(n_experts = dplyr::n(),
aggregated_judgement = (prod(log_odds, na.rm = TRUE)) ^ (1/n_experts)) %>%
dplyr::mutate(
aggregated_judgement = exp(aggregated_judgement) / (1 + exp(aggregated_judgement))
)

},
"ProbitArMean" = {


df <- df %>%
dplyr::mutate(probit = VGAM::probitlink(value,
bvalue = .Machine$double.eps)) %>%
dplyr::summarise(aggregated_judgement = mean(probit,
na.rm = TRUE),
n_experts = dplyr::n()) %>%
dplyr::mutate(aggregated_judgement = VGAM::probitlink(aggregated_judgement,
inverse = TRUE))

})

df %>%
dplyr::mutate(method = name) %>%
postprocess_judgements()

}
}
Loading

0 comments on commit 8f6ce80

Please sign in to comment.