tests/testthat/test-MetaculR_aggregated_forecasts.R

json_test_page1 <- jsonlite::fromJSON('{"next":"https://www.metaculus.com/api2/questions/?limit=20&offset=20","previous":null,"results":[{"id":10204, "number_of_predictions":3, "community_prediction":{"full":{"y":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.1,0.0,0.0,0.0,0.0,0.1,0.0,0.0,0.0,0.0,0.1,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"q1":0.1,"q2":0.15,"q3":0.2}, "unweighted":{"y":[0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"q1":0.1,"q2":0.15,"q3":0.2}}}, {"id":222, "number_of_predictions":3, "community_prediction":{"full":{"y":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.1,0.0,0.0,0.0,0.0,0.1,0.0,0.0,0.0,0.0,0.1,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"q1":0.1,"q2":0.15,"q3":0.2}, "unweighted":{"y":[0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"q1":0.1,"q2":0.15,"q3":0.2}}}]}')

json_test_page2 <- jsonlite::fromJSON('{"next":"https://www.metaculus.com/api2/questions/?limit=20&offset=20","previous":null,"results":[{"id":333, "number_of_predictions":3, "community_prediction":{"full":{"y":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.1,0.0,0.0,0.0,0.0,0.1,0.0,0.0,0.0,0.0,0.1,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"q1":0.1,"q2":0.15,"q3":0.2}, "unweighted":{"y":[0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"q1":0.1,"q2":0.15,"q3":0.2}}}, {"id":444, "number_of_predictions":3, "community_prediction":{"full":{"y":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.1,0.0,0.0,0.0,0.0,0.1,0.0,0.0,0.0,0.0,0.1,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"q1":0.1,"q2":0.15,"q3":0.2}, "unweighted":{"y":[0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"q1":0.1,"q2":0.15,"q3":0.2}}}]}')

json_test <-
  list(json_test_page1,
       json_test_page2)

test_that("multiplication works", {
  expect_equal(2 * 2, 4)
})

test_that("mean logodds works", {
  expect_equal(
    round(MetaculR_aggregated_forecasts(
      MetaculR_questions = json_test,
      Metaculus_id = 10204)$community_mean_logodds, 7),
    0.1452061)
})

test_that("mean logodds extremized works", {
  expect_equal(
    round(MetaculR_aggregated_forecasts(
      MetaculR_questions = json_test,
      Metaculus_id = 10204)$community_mean_logodds_extremized_baseline, 7),
    0.0752309)
  expect_equal(
    round(MetaculR_aggregated_forecasts(
      MetaculR_questions = json_test,
      Metaculus_id = 10204,
      baseline = 0.25)$community_mean_logodds_extremized_baseline, 7),
    0.1137814)
  expect_equal(
    round(MetaculR_aggregated_forecasts(
      MetaculR_questions = json_test,
      Metaculus_id = 10204,
      baseline = 0.05)$community_mean_logodds_extremized_baseline, 7),
    0.2165238)
})

Try the MetaculR package in your browser

Any scripts or data that you put into this service are public.

MetaculR documentation built on April 26, 2022, 1:07 a.m.