tests/testthat/testthat.R

# # #####################################################################################################################
context("testing column existence")
test_that("testing column existence", {
  x <- c(0,NA,"dd",160)
  y <- c(1,2,3,4)
  tempdata = as.data.frame(cbind(y,x))
  colnames(tempdata)<-c("name","age")
  expect_equal(checkColumnExist("age",tempdata),0)

})
context("testing column existence")
test_that("testing column existence", {
  x <- c(0,NA,"dd",160)
  y <- c(1,2,3,4)
  tempdata = as.data.frame(cbind(y,x))
  colnames(tempdata)<-c("name","num")
  expect_equal(checkColumnExist("age",tempdata),-1)

})
# # #####################################################################################################################
# # #####################################################################################################################
context("testing file existence")
test_that("test for file existence and access", {
  thisdir=getwd()
  expect_identical(testFileExistRead(thisdir),0)
  nodir="/Users/SheejaMK/Desktop/Model/filecheck/test"
  expect_identical(testFileExistRead(nodir),-1)
})

# # #####################################################################################################################

context("testing mode function")
test_that("testing mode function", {
  x <- c(0,11,78,160)
  expect_equal(getModeForVec(x),0)

})
context("testing mode function")
test_that("testing mode function", {
  x <- c(0,"f",78,160)
  expect_equal(getModeForVec(x),-1)

})

context("testing mode function")
test_that("testing mode function", {
  x <- c(78,NA,78,78)
  expect_equal(getModeForVec(x),78)

})
context("testing mode function")
test_that("testing mode function", {
  x <- c(78,"NA",78,78)
  expect_equal(getModeForVec(x),-1)

})
# # #####################################################################################################################
context("testing subsetGenderAgeToGroup")
test_that("testing subsetGenderAgeToGroup", {
  set.seed(20)
  sampledata <- data.frame(age=abs(rnorm(10, 60, 20)),
                           sex=factor(sample(c("M", "F"), 10, replace=T)),
                           arm=factor(sample(c("Control", "Intervention"), 10, replace=T)),
                           eq5d3L.q1=(sample(c(1,2,3), 10, replace=T)),
                           eq5d3L.q2=(sample(c(1,2,3), 10, replace=T)),
                           eq5d3L.q3=(sample(c(1,2,3), 10, replace=T)),
                           eq5d3L.q4=(sample(c(1,2,3), 10, replace=T)),
                           eq5d3L.q5=(sample(c(1,2,3), 10, replace=T)))



  expect_equal(getColNumExistingColNames("sex",sampledata),2)
  expect_equal(getColNumExistingColNames("age",sampledata),1)
  expect_equal(getColNumExistingColNames(c("sex","gender","male","female","f","m"),sampledata),2)
  expect_equal(getColNumExistingColNames(c("gender","male","female","f","m"),sampledata),-1)
  expect_equal(getColNumExistingColNames("",sampledata),-1)

})
# # #####################################################################################################################
context("testing subsetGenderAgeToGroup")
test_that("testing subsetGenderAgeToGroup", {
  set.seed(17)
  sampledata <- data.frame(age=abs(rnorm(10, 60, 20)),
                           sex=factor(sample(c("M", "F"), 10, replace=T)),
                           arm=factor(sample(c("Control", "Intervention"), 10, replace=T)),
                           eq5d3L.q1=(sample(c(1,2,3), 10, replace=T)),
                           eq5d3L.q2=(sample(c(1,2,3), 10, replace=T)),
                           eq5d3L.q3=(sample(c(1,2,3), 10, replace=T)),
                           eq5d3L.q4=(sample(c(1,2,3), 10, replace=T)),
                           eq5d3L.q5=(sample(c(1,2,3), 10, replace=T)))
  one<-subset(sampledata,sex=="F")
  two<-subset(one,one$age>=10 & one$age<= 70)
  expect_equal(subsetGenderAgeToGroup(sampledata,"female",c(10,70)),two)
  one<-subset(sampledata,sex=="M")
  two<-subset(one,one$age>=10 & one$age<= 70)
  expect_equal(subsetGenderAgeToGroup(sampledata,"male",c(10,70)),two)

  one<-subset(sampledata,sex=="F")
  two<-subset(one,one$age>=0 & one$age<= 10)
  expect_equal(subsetGenderAgeToGroup(sampledata,"female",c(0,10)),two)
  expect_identical(subsetGenderAgeToGroup(sampledata,"bh",c(10,70)),-1)
  expect_identical(subsetGenderAgeToGroup(sampledata,"bh",NULL),-1)

  one<-subset(sampledata,sex=="M")
  expect_identical(subsetGenderAgeToGroup(sampledata,"male",NULL),one)

})

# # #####################################################################################################################

context("testing descritpvie statistics")
test_that("testing descritpvie statistics", {
  x <- c(0,11,78,160)
  results=matrix(c(249,62.25,73.72189,44.5,0,36.86,0,160,4),nrow=1, byrow=TRUE)
  colnames(results)<-c("Sum","Mean","SD","Median", "Mode","SE","Minimum","Maximum","Count")
  rownames(results)<-"age"
  expect_equal(descriptiveStatDataColumn(x,"age",NA),results,tolerance=0.001)

})

context("testing descriptive statistics")
test_that("testing descriptive statistics", {
  x <- c(0,11,78,160)
  results=matrix(c(249, 83,74.62573, 78,11,43.08519, 11 ,160 ,3),nrow=1, byrow=TRUE)
  colnames(results)<-c("Sum","Mean","SD","Median", "Mode","SE","Minimum","Maximum","Count")
  rownames(results)<-"age"
  expect_equal(descriptiveStatDataColumn(x,"age",0),results,tolerance=0.001)

})

context("testing descriptive statistics")
test_that("testing descriptive statistics", {
  x <- c(0,NA,78,160)
  results=matrix(c(238,79.33333,80.00833,78,0, 46.19283,0 ,160 ,3),nrow=1, byrow=TRUE)
  colnames(results)<-c("Sum","Mean","SD","Median", "Mode","SE","Minimum","Maximum","Count")
  rownames(results)<-"age"
  expect_equal(descriptiveStatDataColumn(x,"age",NA),results,tolerance=0.001)

})

context("testing descriptive statistics")
test_that("testing descriptive statistics", {
  x <- c(0,NA,"dd",160)
  expect_equal(descriptiveStatDataColumn(x,"age",NA),-1)

})
context("testing descriptive statistics")
test_that("testing descriptive statistics", {
  x <- c('',11,78,160)
  expect_equal(descriptiveStatDataColumn(x,"age",NA),-1)

})

## # #####################################################################################################################

context("testing numeric column")
test_that("test for numeric values in a specific column but with no range given", {
  x <- c(0,11,78,120)
  expect_identical(testDataNumNorange(x,0),0)
  x <- c(-8, 99,2,5,-99)
  expect_identical(testDataNumNorange(x,-99),0)
  x <- c("sheeja", 99,2,5,-99)
  expect_identical(testDataNumNorange(x,-99),-1)

})
## # #####################################################################################################################
## # #####################################################################################################################
## # #####################################################################################################################

context("testing EQ5D3L valuation using individual responses")
test_that("test for value3L", {


  the.result<-valueEQ5D3L_indscores("UK",1,1,1,1,2)
  expect_equal(the.result,0.848,tolerance=1e-3)

  the.result<-valueEQ5D3L_indscores("UK",11112)
  expect_equal(the.result,0.848,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",11121)
  expect_equal(the.result,0.796,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",11211)
  expect_equal(the.result,0.883,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",12111)
  expect_equal(the.result,0.815,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",21111)
  expect_equal(the.result,0.85,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",33333)
  expect_equal(the.result,-0.594,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",55555)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",111)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",345678)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("NM",-11111)
  expect_equal(the.result,-1,tolerance=1e-3)

  the.result<-valueEQ5D3L_indscores("UK",11112, NA, NA, NA, NA)
  expect_equal(the.result,0.848,tolerance=1e-3)

  the.result<-valueEQ5D3L_indscores("UK",c(1,1,1,1,2), NA, NA, NA, NA)
  expect_equal(the.result,0.848,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",c(1,1,1), NA, NA, NA, NA)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",c(8,1,1,2,1), NA, NA, NA, NA)
  expect_equal(the.result,-1,tolerance=1e-3)

  the.result<-valueEQ5D3L_indscores("UK",c(1,1,1,1,2), NA, NA, NA)
  expect_equal(the.result,0.848,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",11111)
  expect_equal(the.result,1,tolerance=1e-3)
  #
  the.result<-valueEQ5D3L_indscores("UK",c(1,1,1,1,2))
  expect_equal(the.result,0.848,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",c(1,1,1,2,1))
  expect_equal(the.result,0.796,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",c(1,1,2,1,1))
  expect_equal(the.result,0.883,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",c(1,2,1,1,1))
  expect_equal(the.result,0.815,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",c(2,1,1,1,1))
  expect_equal(the.result,0.85,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",c(5,5,5,5,5))
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",c(1,1,1))
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",c(3,4,5,6,7,8))
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",c(-1,1,1,1,1))
  expect_equal(the.result,-1,tolerance=1e-3)
  #
  the.result<-valueEQ5D3L_indscores("UK",NA,1,1,1,2)
  expect_equal(the.result,NA,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",NA,1,1,2,1)
  expect_equal(the.result,NA,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",NA,1,1,1)
  expect_equal(the.result,NA,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",1,1,1,1,NA)
  expect_equal(the.result,NA,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("UK",-1,1,1,1,1)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("DE",1,1,1,1,1)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-valueEQ5D3L_indscores("US",1,1,1,1,1)
  expect_equal(the.result,-1,tolerance=1e-3)

  the.result<-valueEQ5D3L_indscores("UK",4,5,6,5,8)
  expect_equal(the.result,-1)
  the.result<-valueEQ5D3L_indscores("UK",-1,2,3,2,2)
  expect_equal(the.result,-1)
  the.result<-valueEQ5D3L_indscores("UK",123)
  expect_equal(the.result,-1)
  the.result<-valueEQ5D3L_indscores("JP",c(1,2,3,2,3))
  expect_equal(the.result,-1)
  answers =EQ5D3L_indexvalues_TTO_UK.df
  for (i in 1:nrow(answers)){
    the.scores3L=convertNumberToIndividualDigits(answers$TTO[i])
    the.result<-valueEQ5D3L_indscores("UK",answers$TTO[i])
    expect_equal(the.result,answers$UK[i])
  }
})

# #####################################################################################################################
context("testing EQ5D3L valuation using individual responses")
test_that("test for value3L", {
  set.seed(17)
  sampledata <- data.frame(age=abs(rnorm(10, 60, 20)),
                           sex=factor(sample(c("M", "F"), 10, replace=T)),
                           arm=factor(sample(c("Control", "Intervention"), 10, replace=T)),
                           eq5d3L.q1=(sample(c(1,2,3), 10, replace=T)),
                           eq5d3L.q2=(sample(c(1,2,3), 10, replace=T)),
                           eq5d3L.q3=(sample(c(1,2,3), 10, replace=T)),
                           eq5d3L.q4=(sample(c(1,2,3), 10, replace=T)),
                           eq5d3L.q5=(sample(c(1,2,3), 10, replace=T)))
  answer=valueEQ5D3L(sampledata,"eq5d3L.q1","eq5d3L.q2","eq5d3L.q3","eq5d3L.q4","eq5d3L.q5","UK",NA,NULL)
})
# #####################################################################################################################
context("EQ5D5L scoring ")
test_that("EQ5D5L scoring ", {
  the.result<-valueEQ5D5L_indscores("UK",1,1,1,1,2)
  expect_equal(the.result,0.922,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",11112)
  expect_equal(the.result,0.922,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",11121)
  expect_equal(the.result,0.937,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",11211)
  expect_equal(the.result,0.950,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",12111)
  expect_equal(the.result,0.950,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",21111)
  expect_equal(the.result,0.942,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",55555)
  expect_equal(the.result,-0.285,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",111)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",345678)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("NM",-11111)
  expect_equal(the.result,-1,tolerance=1e-3)

  the.result<-valueEQ5D5L_indscores("UK",11112, NA, NA, NA, NA)
  expect_equal(the.result,0.922,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",c(1,1,1,1,2), NA, NA, NA, NA)
  expect_equal(the.result,0.922,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",c(1,1,1), NA, NA, NA, NA)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",c(8,1,1,2,1), NA, NA, NA, NA)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",c(1,1,1,1,2), NA, NA, NA)
  expect_equal(the.result,0.922,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",11111)
  expect_equal(the.result,1,tolerance=1e-3)

  the.result<-valueEQ5D5L_indscores("UK",c(1,1,1,1,2))
  expect_equal(the.result,0.922,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",c(1,1,1,2,1))
  expect_equal(the.result,0.937,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",c(1,1,2,1,1))
  expect_equal(the.result,0.950,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",c(1,2,1,1,1))
  expect_equal(the.result,0.950,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",c(2,1,1,1,1))
  expect_equal(the.result,0.942,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",c(5,5,5,5,5))
  expect_equal(the.result,-0.285,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",c(1,1,1))
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",c(3,4,5,6,7,8))
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",c(-1,1,1,1,1))
  expect_equal(the.result,-1,tolerance=1e-3)

  the.result<-valueEQ5D5L_indscores("UK",NA,1,1,1,2)
  expect_equal(the.result,NA,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",NA,1,1,2,1)
  expect_equal(the.result,NA,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",NA,1,1,1)
  expect_equal(the.result,NA,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",1,1,1,1,NA)
  expect_equal(the.result,NA,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("UK",-1,1,1,1,1)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("DE",1,1,1,1,1)
  expect_equal(the.result,1,tolerance=1e-3)
  the.result<-valueEQ5D5L_indscores("US",1,1,1,1,1)
  expect_equal(the.result,-1,tolerance=1e-3)
})

# #####################################################################################################################
context("Crosswalk EQ5D5L to 3L values for uk using van hout method")
test_that("Crosswalk EQ5D5L to 3L values", {
  the.result<-eq5dmap5Lto3LUKIndscores("van hout",56789)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-eq5dmap5Lto3LUKIndscores("van hout",-12345)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-eq5dmap5Lto3LUKIndscores("van hout",-1111)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-eq5dmap5Lto3LUKIndscores("van hout",-23456)
  expect_equal(the.result,-1,tolerance=1e-3)

  the.result<-eq5dmap5Lto3LUKIndscores("",12345)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-eq5dmap5Lto3LUKIndscores("van hout",c(1,2,3,4,5))
  expect_equal(the.result,0.06333624,tolerance=1e-3)
  the.result<-eq5dmap5Lto3LUKIndscores("van hout",1,2,3,4,5)
  expect_equal(the.result,0.06333624,tolerance=1e-3)
  the.result<-eq5dmap5Lto3LUKIndscores("van hout",8,2,3,4,5)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-eq5dmap5Lto3LUKIndscores("van hout",77777,2,3,4,5)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-eq5dmap5Lto3LUKIndscores("van hout",NA,2,3,4,5)
  expect_equal(the.result,NA,tolerance=1e-3)
  the.result<-eq5dmap5Lto3LUKIndscores("van hout",1,2,3,4,NA)
  expect_equal(the.result,NA,tolerance=1e-3)
})
# # #####################################################################################################################
#
context("Crosswalk EQ5D5L to 3L values for any country ")
test_that("Crosswalk EQ5D5L to 3L values for any country ", {
  the.result<-eq5dmap5Lto3L_indscores("UK",1,1,1,1,2)
  expect_equal(the.result,0.8794038,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",11112)
  expect_equal(the.result,0.8794038,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",11121)
  expect_equal(the.result, 0.8365693,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",11211)
  expect_equal(the.result,0.9061444,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",12111)
  expect_equal(the.result,0.8459592,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",21111)
  expect_equal(the.result,0.8766021,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",55555)
  expect_equal(the.result,-0.594,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",111)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",345678)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("NM",-11111)
  expect_equal(the.result,-1,tolerance=1e-3)

  the.result<-eq5dmap5Lto3L_indscores("UK",11112, NA, NA, NA, NA)
  expect_equal(the.result,0.8794038,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",c(1,1,1,1,2), NA, NA, NA, NA)
  expect_equal(the.result,0.8794038,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",c(1,1,1), NA, NA, NA, NA)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",c(8,1,1,2,1), NA, NA, NA, NA)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",c(1,1,1,1,2), NA, NA, NA)
  expect_equal(the.result,0.8794038,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",11111)
  expect_equal(the.result,1,tolerance=1e-3)

  the.result<-eq5dmap5Lto3L_indscores("UK",c(1,1,1,1,2))
  expect_equal(the.result,0.8794038,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",c(1,1,1,2,1))

  expect_equal(the.result,0.8365693,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",c(1,1,2,1,1))
  expect_equal(the.result,0.9061444,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",c(1,2,1,1,1))
  expect_equal(the.result,0.8459592,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",c(2,1,1,1,1))
  expect_equal(the.result,0.8766021,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",c(5,5,5,5,5))
  expect_equal(the.result,-0.594,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",c(1,1,1))
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",c(3,4,5,6,7,8))
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",c(-1,1,1,1,1))
  expect_equal(the.result,-1,tolerance=1e-3)

  the.result<-eq5dmap5Lto3L_indscores("UK",NA,1,1,1,2)
  expect_equal(the.result,NA,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",NA,1,1,2,1)
  expect_equal(the.result,NA,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",NA,1,1,1)
  expect_equal(the.result,NA,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",1,1,1,1,NA)
  expect_equal(the.result,NA,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",-1,1,1,1,1)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("DE",1,1,1,1,1)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("US",1,1,1,1,1)
  expect_equal(the.result,-1,tolerance=1e-3)
})

# # ########################################
# #############################################################################
context("Crosswalk EQ5D5L to 3L values for any country")
test_that("Crosswalk EQ5D5L to 3L values", {

  the.result<-eq5dmap5Lto3L_indscores("UK",56789)
  expect_equal(the.result,-1,tolerance=1e-3)

  the.result<-eq5dmap5Lto3L_indscores("UK",-12345)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",-1111)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",-23456)
  expect_equal(the.result,-1,tolerance=1e-3)

  the.result<-eq5dmap5Lto3L_indscores("",12345)
  expect_equal(the.result,-1,tolerance=1e-3)

  the.result<-eq5dmap5Lto3L_indscores("UK",c(1,2,3,4,5))
  expect_equal(the.result,0.06333624,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("JP",1,2,3,4,5)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",8,2,3,4,5)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",77777,2,3,4,5)
  expect_equal(the.result,-1,tolerance=1e-3)
  the.result<-eq5dmap5Lto3L_indscores("UK",NA,2,3,4,5)
  expect_equal(the.result,NA,tolerance=1e-3)

  the.result<-eq5dmap5Lto3L_indscores("UK",1,2,3,4,NA)
  expect_equal(the.result,NA,tolerance=1e-3)
})
#
# #################################################################################################################
context("Crosswalk EQ5D5L to 3L values")
test_that("Crosswalk EQ5D5L to 3L values", {
  answers =EQ5D5L_Crosswalk_ValueSets.df
  #Error_ones<-c(91,92,96,97,116,117,122,216,221,222,241,242,246,247,716,721,722,741,742,746,747,846,866,871)
  total_entries=seq(1,nrow(answers))
  correct_ones=total_entries#[!total_entries %in% Error_ones]
  end1=length(correct_ones)
  for (i in 1:end1){
    the.result<-eq5dmap5Lto3L_indscores("UK",answers$X5L.profile[correct_ones[i]])
    expect_equal(the.result,answers$UK[correct_ones[i]],tolerance=1e-3)
  }
})
# #################################################################################################################

#################################################################################################################
context("EQ5D5L scoring")
test_that("EQ5D5L scoring", {
  answers =EQ5d5L_valuesets_13countries.df
  total_entries=seq(1,nrow(answers))
  end1=length(total_entries)
  #total_countries=c("UK","CA","CN","DE","ES","HK","IN","IR","JP","KR", "NL","TH", "UY")
  total_countries=c("UK","CA","CN","DE","ES","HK","IN","IR","JP", "NL","TH", "UY")
  start=which(colnames(answers)=="UK")
  final=start+length(total_countries)-1
  for(j in start:final){
    #print(j)
    this.country=colnames(answers)[j]
    print(this.country)
    if(this.country=="CA" || this.country=="NL"||this.country=="JP"|| this.country=="UY"){
      print("not implemented")
    }else{
      for (i in 1:end1){
        #print(answers$X5Lprofile[total_entries[i]])
        the.result<-valueEQ5D5L_indscores(this.country,answers$X5Lprofile[total_entries[i]])
        this.col<-answers[[this.country]]
        expect_equal(the.result,this.col[total_entries[i]],tolerance=1e-2)
      }
    }

  }
})
#################################################################################################################
sheejamk/eq5dmapR documentation built on July 6, 2019, 11:49 p.m.