cont_add_data() adds data to an elic_cont object from
different sources.
Usage
cont_add_data(
x,
data_source,
round,
...,
sep = ",",
sheet = 1,
overwrite = FALSE,
verbose = TRUE,
anonymise = TRUE
)Arguments
- x
an object of class elic_cont created with cont_start.
- data_source
either a
data.frameortibble, a string with the path to a csv or xlsx file, or anything accepted by the read_sheet function.- round
integer (1 or 2) indicating if the data belongs to the first or second elicitation round. See section rounds for more detail.
- ...
Unused arguments, included only for future extensions of the function.
- sep
character used as field separator, used only when
data_sourceis a path to a csv file.- sheet
integer or character to select the sheet. The sheet can be referenced by its position with a number or by its name with a string. Used only when
data_sourceis a path to a xlsx file or when data are imported from Google Sheets.- overwrite
logical, whether to overwrite existing data already added to the elic_cont object. See section rounds for more detail.
- verbose
logical, if
TRUEit prints informative messages.- anonymise
logical, if
TRUEexpert names are anonymised before adding the data to the elic_cont object.
Value
The provided object of class elic_cont updated with the data.
Rounds
elicitr supports two elicitation rounds, following approaches such as the Delphi and IDEA protocols. The idea behind the two rounds is that experts first provide individual estimates, then review feedback or discuss differences before submitting revised estimates in a second round. This gives experts an opportunity to reconsider their judgments while retaining both sets of responses for comparison.
When adding data to the elic_cont object previously created with cont_start, elicitr checks that the number of responses matches the declared number of experts. When adding round 2, it matches expert IDs across rounds and aligns their responses. It also flags inconsistencies in expert IDs and can correct a single differing ID as a presumed typo under specific conditions. Data must be loaded in round 1 before a second elicitation round can be loaded in round 2. To replace existing data, the argument overwrite must be set to TRUE in cont_add_data.
Data format
Data are expected to have the name of the expert always as first column. The only exception is for data coming from Google Sheet which can have an additional column with a timestamp. This column is automatically removed before the data are added to the elic_cont object (see "Data cleaning"). After the name there should be one or more blocks which follow the specifications below:
One point elicitation:
var_best: best estimate for the variableThree points elicitation:
var_min: minimum estimate for the variablevar_max: maximum estimate for the variablevar_best: best estimate for the variableFour points elicitation:
var_min: minimum estimate for the variablevar_max: maximum estimate for the variablevar_best: best estimate for the variablevar_conf: confidence for the estimateThe column with names is unique, the other columns are a block and can be repeated for each variable.
Column and variable names
The name of the columns is not important, as long as they are different.
cont_add_data() will overwrite them according to the convention
variable_name_suffix with suffix being one of min, max, best, or
conf. The information to build the column names is taken from the
metadata available in the elic_cont object.
var_conf, given as percentage, can be any number in the range (50, 100].
This is because any value smaller or equal to 50 would imply that the
accuracy of the estimates is only due to chance).
NAs
Experts can decide to not provide estimates for all variables. In this
case, the missing values should be recorded as NA. However, experts
should always answer completely to a variable (aka provide values for all
aspect of the variable (minimum, maximum, best guess and confidence)) or
not at all. If estimates are only partially given for a variable (example
min and max provided but not best for a three-point elicitation), an
error is raised.
Data cleaning
When data are added to the elic_cont object, first names are standardised by converting capital letters to lower case, and by removing any whitespaces and punctuation. Then, data are anonymised by converting names to short sha1 hashes. In this way, sensible information collected during the elicitation process never reaches the elic_cont object. For three and four points elicitation processes, the order of the values is checked for each expert. If it is not min-max-best, the values are swapped accordingly and a informative warn is raised.
If the data are imported from Google Sheets, cont_add_data() performs
additional data cleaning operations. This is relevant when data are
collected with Google Forms because, for example, there could be multiple
submission by the same expert or a different decimal separator could be
used. When data are collected with Google Form, a column with the date and
time is recorded. First, the function checks for multiple submissions and
if present, only the last submission is retained. Second, the function
removes the column with the timestamp. Then it checks for consistency of
the decimal separator, i.e. commas , are replaced with periods ..
Finally, all columns but the first one (which contains the names) are
forced to numeric.
See also
Other cont data helpers:
cont_get_data(),
cont_sample_data(),
cont_start(),
summary.cont_sample()
Examples
# Create the elic_cont object for an elicitation process that estimates 3
# variables, the first for a one point estimation of a positive round number,
# the second for three points estimation of a negative real, and the last for
# a four point estimation of a probability
x <- cont_start(var_names = c("var1", "var2", "var3"),
var_types = "ZNp",
elic_types = "134",
experts = 6)
#> ✔ <elic_cont> object for "Elicitation" correctly initialised
# Add data for the first and second round from a data.frame. Notice that the
# two commands can be piped
my_elicit <- cont_add_data(x, data_source = round_1, round = 1) |>
cont_add_data(data_source = round_2, round = 2)
#> ✔ Data added to "Round 1" from "data.frame"
#> ✔ Data added to "Round 2" from "data.frame"
my_elicit
#>
#> ── Elicitation ──
#>
#> • Variables: "var1", "var2", and "var3"
#> • Variable types: "Z", "N", and "p"
#> • Elicitation types: "1p", "3p", and "4p"
#> • Number of experts: 6
#> • Number of rounds: 2
# Add data for the first and second round from a csv file
files <- list.files(path = system.file("extdata", package = "elicitr"),
pattern = "round_",
full.names = TRUE)
my_elicit <- cont_add_data(x, data_source = files[1], round = 1) |>
cont_add_data(data_source = files[2], round = 2)
#> ✔ Data added to "Round 1" from "csv file"
#> ✔ Data added to "Round 2" from "csv file"
my_elicit
#>
#> ── Elicitation ──
#>
#> • Variables: "var1", "var2", and "var3"
#> • Variable types: "Z", "N", and "p"
#> • Elicitation types: "1p", "3p", and "4p"
#> • Number of experts: 6
#> • Number of rounds: 2
# Add data for the first and second round from a xlsx file with two sheets
file <- list.files(path = system.file("extdata", package = "elicitr"),
pattern = "rounds",
full.names = TRUE)
# Using the sheet index
my_elicit <- cont_add_data(x, data_source = file, sheet = 1, round = 1) |>
cont_add_data(data_source = file, sheet = 2, round = 2)
#> ✔ Data added to "Round 1" from "xlsx file"
#> ✔ Data added to "Round 2" from "xlsx file"
my_elicit
#>
#> ── Elicitation ──
#>
#> • Variables: "var1", "var2", and "var3"
#> • Variable types: "Z", "N", and "p"
#> • Elicitation types: "1p", "3p", and "4p"
#> • Number of experts: 6
#> • Number of rounds: 2
# Using the sheet name
my_elicit <- cont_add_data(x, data_source = file,
sheet = "Round 1", round = 1) |>
cont_add_data(data_source = file, sheet = "Round 2", round = 2)
#> ✔ Data added to "Round 1" from "xlsx file"
#> ✔ Data added to "Round 2" from "xlsx file"
my_elicit
#>
#> ── Elicitation ──
#>
#> • Variables: "var1", "var2", and "var3"
#> • Variable types: "Z", "N", and "p"
#> • Elicitation types: "1p", "3p", and "4p"
#> • Number of experts: 6
#> • Number of rounds: 2
if (FALSE) { # interactive()
# Add data for the first and second round from Google Sheets
googlesheets4::gs4_deauth()
gs1 <- "12lGIPa-jJOh3fogUDaERmkf04pVpPu9i8SloL2jAdqc"
gs2 <- "1wImcfJYnC9a423jlxZiU_BFKXZpTZ7AIsZSxFtEsBQw"
my_elicit <- cont_add_data(x, data_source = gs1, round = 1) |>
cont_add_data(data_source = gs2, round = 2)
my_elicit
}
