Skip to content

Instantly share code, notes, and snippets.

@mcfrank
Last active October 12, 2023 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcfrank/396cf53be62b3b07635389f1c890bef5 to your computer and use it in GitHub Desktop.
Save mcfrank/396cf53be62b3b07635389f1c890bef5 to your computer and use it in GitHub Desktop.
pseudocode for knower level simulation
library(tidyverse)
library(assertthat)
shuffle_data <- function(d) {
d$participant_id <- shuffle(d$participant_id)
return(d)
}
get_knower_level <- function (q, r, technique = "perfect") {
# perfect technique - your KL is the max q at which you get all correct
if (technique == "perfect") {
# fill in KL computation
} else if (technique == "2/3") {
# fill in KL computation
}
}
# test knowerlevel computation
# test 1: if you don't get anything right, your knower level is 0
assert_that(get_knower_level(c(1,2,3,4,5),c(0,0,0,0,0), technique = "perfect") == 0)
# test 2: if you get up to 3 right, your knower level is 3 (friendly test)
assert_that(get_knower_level(c(1,1,1,2,2,2,3,3,3,4,5),c(1,1,1,2,2,2,3,3,3,10,10)), technique = "perfect") == 3)
# make up unfriendly cases
knower_level_sim <- tibble(sim_num = 1:1000) |>
mutate(data = shuffle_data(libertus_data)) |>
unnest(cols = c(data)) |>
group_by(sim_num, participant_id) |>
summarise(knower_level_perfect = get_knower_level(quantity, response,
technique = "perfect"),
knower_level_23 = get_knower_level(quantity, response,
technique = "2/3")) |>
group_by(sim_num, knower_level) |>
count()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment