tests/testthat/test_get_pwe_S.R

context("Must calculate the survivor function estimated in piecewise-constant NMA model contained in `rjags` object")

test_that("`get_pwe_S`", {
  # load rjags fit list object from tests/data
  # for details on how this object was generated refer to the generation script:
  # tests/data/rjags_generation.R
  rjags_list_ex <- readRDS(system.file("tests",
                                       "data",
                                       "rjags_output_list.RDS",
                                       package = "gemtcPlus"))

  treatments <- unique(rjags_list_ex[[1]]$data.arms$treatment[order(rjags_list_ex[[1]]$data.arms$treatmentn)])

output <- get_pwe_S(fit = rjags_list_ex[[1]]$fit,
                    cut.pts = rjags_list_ex[[1]]$model.pars$cut.pts,
                    ref.arm = 1,
                    ref.std = 1,
                    treatments = treatments,
                    time = 1:50)

  # check class
  expect_is(output, "data.frame")
  # check names
  expect_named(output, c("time", "S", "lCrI", "uCrI", "treatment"))
  # check values
  expect_equal(output$time, rep(1:50, times = 6))
  expect_equal(output$S[1:100], c(0.975007732340411, 0.950640078123591, 0.926881426843194, 0.904633852012445,
                                  0.882921917317292, 0.861727884647881, 0.841040704452697, 0.820856908602063,
                                  0.80115419909621, 0.781925858687736, 0.764292388439399, 0.74705882580046,
                                  0.730209735370434, 0.713727669979965, 0.697648769790928, 0.681913162907891,
                                  0.666531675691682, 0.651502555815483, 0.636812258891289, 0.622452310945091,
                                  0.60841007513705, 0.594694734515725, 0.581281864926829, 0.568176687437487,
                                  0.555360451001484, 0.542838627576872, 0.530594810027564, 0.518619981157869,
                                  0.506943974383481, 0.495504126032139, 0.484328553036601, 0.47340614004257,
                                  0.462731403886254, 0.452292781766419, 0.442096831079664, 0.432124647305108,
                                  0.422298240963801, 0.412855790595615, 0.403560297901175, 0.394445585152674,
                                  0.385549066529204, 0.376857449973516, 0.368355925690171, 0.360050327863138,
                                  0.351933351832538, 0.343993266980534, 0.336238618779694, 0.328655291890419,
                                  0.321246839427083, 0.313996964382699, 0.980373092878404, 0.961131401239967,
                                  0.94226736449618, 0.924732708396488, 0.90752607932242, 0.890636231431157,
                                  0.874058700485793, 0.857796949902833, 0.841834203991588, 0.826170078825016,
                                  0.807527935994145, 0.789302269835858, 0.771503219315286, 0.754079747196427,
                                  0.737042928366008, 0.720431645629696, 0.704173132014077, 0.688284221818218,
                                  0.672608773701215, 0.657571582081826, 0.642732536105607, 0.628229732972177,
                                  0.614046528374456, 0.600193987613896, 0.586649470374032, 0.57342072950757,
                                  0.56046305963247, 0.5478228528688, 0.535463814344203, 0.523363154889466,
                                  0.511572666312526, 0.500023596899338, 0.488739171709749, 0.477710213109092,
                                  0.466929293032484, 0.456392943138709, 0.44609644444144, 0.435949040988382,
                                  0.426185374352035, 0.416572104574993, 0.407181086314615, 0.397983246732448,
                                  0.389006257285678, 0.38022472097299, 0.371643124633985, 0.363254079818776,
                                  0.355062719601702, 0.34704693911331, 0.339212411474452, 0.331558278547635
                                  ))

  expect_equal(output$lCrI[1:100], c(0.960950580682783, 0.923426018514577, 0.887366768709173, 0.857742921324373,
                                     0.829108036299697, 0.801429098121087, 0.774671884850256, 0.748812474399057,
                                     0.723814122822627, 0.699648433279512, 0.679533007777703, 0.660012190025932,
                                     0.641041007296125, 0.622619730130156, 0.604735877058197, 0.587345709981685,
                                     0.570465561792109, 0.554069024174205, 0.538151888847835, 0.522678307915042,
                                     0.507662563545982, 0.49306097329126, 0.478893578662888, 0.465133360613044,
                                     0.451761657467859, 0.438778901064388, 0.426162968491025, 0.413922785145379,
                                     0.402032659441264, 0.390472322597273, 0.379247798831101, 0.368350427147803,
                                     0.357766245754891, 0.347481965725388, 0.33749938287119, 0.327796000688596,
                                     0.318375357245849, 0.309223502099116, 0.300360586744191, 0.291707419306873,
                                     0.283324207582159, 0.275181871906563, 0.267268964896832, 0.259587531007908,
                                     0.252134876806061, 0.244880733783981, 0.237839485737157, 0.231008816228861,
                                     0.224386098525551, 0.21791939996194, 0.962787488398015, 0.926959747815758,
                                     0.892465247445591, 0.868138894464962, 0.844475616546395, 0.821457339935132,
                                     0.799073600960339, 0.777285945412204, 0.756099089868979, 0.735489734601499,
                                     0.71345640528374, 0.692366419832947, 0.671757960049084, 0.65177151598455,
                                     0.63237554560669, 0.613556776989985, 0.595293529711161, 0.577587641301325,
                                     0.560411144730966, 0.543717759566051, 0.527536987469724, 0.511734632905927,
                                     0.496605905933427, 0.48182827271151, 0.467453276545844, 0.453574672231558,
                                     0.44007775878857, 0.426983449224551, 0.414273062798359, 0.401948508809172,
                                     0.389989808715322, 0.378381419765407, 0.36712060461784, 0.356193424167235,
                                     0.345596209713529, 0.335314487354382, 0.325332479487086, 0.315662130708065,
                                     0.306251194234409, 0.297142846752112, 0.288302528533668, 0.279722923335647,
                                     0.271395747368232, 0.263267953082971, 0.255483206622748, 0.247881866322166,
                                     0.240325813127946, 0.233348410763332, 0.226421187245068, 0.219650341609896
                                     ))

  expect_equal(output$uCrI[1:100], c(0.985127546020477, 0.970476281928327, 0.956042918087129, 0.939983795014919,
                                     0.924191114660797, 0.908670276661017, 0.893413406578526, 0.878399900153708,
                                     0.863644985038172, 0.849134874054895, 0.834432000142954, 0.819983461810471,
                                     0.805783863935604, 0.791822831461716, 0.778101113420233, 0.764635894085914,
                                     0.751390841955348, 0.73838326352038, 0.72559188357019, 0.713023905693819,
                                     0.700673903350101, 0.688543059662858, 0.676619885996474, 0.664902535130701,
                                     0.653388238181002, 0.642072697685389, 0.630945403171087, 0.620020998650075,
                                     0.609280466989354, 0.598731289735376, 0.588353299503938, 0.578173978728267,
                                     0.568162093571796, 0.558319118504929, 0.548650928096681, 0.539151959132901,
                                     0.529814307571486, 0.52063636704759, 0.511625650370472, 0.502757915344146,
                                     0.494056864957965, 0.485493600637222, 0.477090604688029, 0.468825703186409,
                                     0.460702645891242, 0.452729657319017, 0.444891179431246, 0.43718351753789,
                                     0.429603801991226, 0.422172407263234, 0.989977661575504, 0.980055770418503,
                                     0.970233319812489, 0.958079210460959, 0.946072966973703, 0.934225847920555,
                                     0.922522804041536, 0.910966364151627, 0.899554691743175, 0.888281852774072,
                                     0.873218312626771, 0.858397239119608, 0.843826472987254, 0.829517151321545,
                                     0.815432477072682, 0.801602988640218, 0.788004526143027, 0.774631754640194,
                                     0.761487501347475, 0.748562951278698, 0.735860261577751, 0.723382715921467,
                                     0.711107470896445, 0.699038924035444, 0.687180149386974, 0.675522160854357,
                                     0.664055495126017, 0.652786085789519, 0.641711744673593, 0.630815784373408,
                                     0.620118950456596, 0.609597798712741, 0.599257115969728, 0.589088477746532,
                                     0.579086492847971, 0.569265502414469, 0.559604869569563, 0.550110714143845,
                                     0.540732413849506, 0.531598083616184, 0.522577541048996, 0.513710192159907,
                                     0.504998793190778, 0.496430794248807, 0.487999494685662, 0.479726358088546,
                                     0.471591692383953, 0.463582947495981, 0.455716793164321, 0.447985523595653
  ))

  expect_equal(output$treatment[1:100], factor(c("B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B",
                                                 "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B",
                                                 "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B",
                                                 "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "A",
                                                 "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
                                                 "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
                                                 "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
                                                 "A", "A", "A", "A", "A", "A", "A", "A", "A", "A"),
                                               levels = LETTERS[1:6]))
})
bashlee/test documentation built on June 22, 2019, 12:42 a.m.