Running ‘testthat.R’ [36s/48s]
Running the tests in ‘tests/testthat.R’ failed.
Complete output:
  > library(testthat)
  > library(PlackettLuce)
  > 
  > test_check("PlackettLuce")
  ── 1. Error: plfit and bt model agree [Topmodel2007] (@test-psycho.R#22)  ──────
  no applicable method for 'estfun' applied to an object of class "btmodel"
  1: estfun(btmod) at testthat/test-psycho.R:22
  
  
  beans> # Consider the best and worst rankings. These give the variety the
  beans> # farmer thought was best or worst, coded as A, B or C for the
  beans> # first, second or third variety assigned to the farmer
  beans> # respectively.
  beans> data(beans)
  
  beans> head(beans[c("best", "worst")], 2)
  # A tibble: 2 x 2
    best  worst
    <chr> <chr>
  1 C     A    
  2 B     A    
  
  beans> # Convert these to numeric values, allowing us to impute the
  beans> # middle-ranked variety (a strict ranking is assumed here, so the
  beans> # sum of each row should be 6)
  beans> beans <- within(beans, {
  beans+    best <- match(best, c("A", "B", "C"))
  beans+    worst <- match(worst, c("A", "B", "C"))
  beans+    middle <- 6 - best - worst
  beans+ })
  
  beans> head(beans[c("best", "middle", "worst")], 2)
  # A tibble: 2 x 3
     best middle worst
    <int>  <dbl> <int>
  1     3     2.     1
  2     2     3.     1
  
  beans> # This gives an ordering of the three varieties the farmer was
  beans> # given. The names of these varieties are stored in separate
  beans> # columns
  beans> varieties <- as.matrix(beans[c("variety_a", "variety_b", "variety_c")])
  
  beans> head(varieties, 2)
       variety_a     variety_b         variety_c    
  [1,] "BRT 103-182" "SJC 730-79"      "PM2 Don Rey"
  [2,] "INTA Rojo"   "INTA Centro Sur" "INTA Sequia"
  
  beans> # So we can convert the variety IDs to the variety names
  beans> n <- nrow(beans)
  
  beans> beans <- within(beans, {
  beans+     best <- varieties[cbind(seq_len(n), best)]
  beans+     worst <- varieties[cbind(seq_len(n), worst)]
  beans+     middle <- varieties[cbind(seq_len(n), middle)]
  beans+ })
  
  beans> head(beans[c("best", "middle", "worst")], 2)
  # A tibble: 2 x 3
    best            middle      worst      
    <chr>           <chr>       <chr>      
  1 PM2 Don Rey     SJC 730-79  BRT 103-182
  2 INTA Centro Sur INTA Sequia INTA Rojo  
  
  beans> # Create a rankings object from the rankings of order three
  beans> ## each ranking is a sub-ranking of three varieties from the full set
  beans> lab <- c("Local", sort(unique(as.vector(varieties))))
  
  beans> R <- as.rankings(beans[c("best", "middle", "worst")],
  beans+                  input = "ordering", labels = lab)
  
  beans> head(R)
  [1] "PM2 Don Rey > SJC 730-79 > BRT 103-182"  
  [2] "INTA Centro Sur > INTA Sequia > INTA ..."
  [3] "INTA Ferroso > INTA Matagalpa > BRT  ..."
  [4] "INTA Rojo > INTA Centro Sur > ALS 0532-6"
  [5] "PM2 Don Rey > INTA Sequia > SJC 730-79"  
  [6] "ALS 0532-6 > INTA Matagalpa > INTA Rojo" 
  
  beans> # Convert worse/better columns to ordered pairs
  beans> head(beans[c("var_a", "var_b", "var_c")], 2)
  # A tibble: 2 x 3
    var_a var_b  var_c 
    <chr> <chr>  <chr> 
  1 Worse Worse  Better
  2 Worse Better Better
  
  beans> paired <- list()
  
  beans> for (id in c("a", "b", "c")){
  beans+     ordering <- matrix("Local", nrow = n, ncol = 2)
  beans+     worse <- beans[[paste0("var_", id)]] == "Worse"
  beans+     ## put trial variety in column 1 when it is not worse than local
  beans+     ordering[!worse, 1] <- beans[[paste0("variety_", id)]][!worse]
  beans+     ## put trial variety in column 2 when it is worse than local
  beans+     ordering[worse, 2] <- beans[[paste0("variety_", id)]][worse]
  beans+     paired[[id]] <- ordering
  beans+ }
  
  beans> head(paired[["a"]])
       [,1]              [,2]         
  [1,] "Local"           "BRT 103-182"
  [2,] "Local"           "INTA Rojo"  
  [3,] "INTA Ferroso"    "Local"      
  [4,] "INTA Centro Sur" "Local"      
  [5,] "INTA Sequia"     "Local"      
  [6,] "ALS 0532-6"      "Local"      
  
  beans> # Convert orderings to sub-rankings of full set and combine all rankings
  beans> paired <- lapply(paired, as.rankings, input = "ordering", labels = lab)
  
  beans> R <- rbind(R, paired[["a"]], paired[["b"]], paired[["c"]])
  
  beans> head(R)
  [1] "PM2 Don Rey > SJC 730-79 > BRT 103-182"  
  [2] "INTA Centro Sur > INTA Sequia > INTA ..."
  [3] "INTA Ferroso > INTA Matagalpa > BRT  ..."
  [4] "INTA Rojo > INTA Centro Sur > ALS 0532-6"
  [5] "PM2 Don Rey > INTA Sequia > SJC 730-79"  
  [6] "ALS 0532-6 > INTA Matagalpa > INTA Rojo" 
  
  beans> tail(R)
  [1] "INTA Sequia > Local"    "INTA Sequia > Local"    "BRT 103-182 > Local"   
  [4] "Local > INTA Matagalpa" "Local > INTA Rojo"      "Local > SJC 730-79"    
  ══ testthat results  ═══════════════════════════════════════════════════════════
  OK: 100 SKIPPED: 0 FAILED: 1
  1. Error: plfit and bt model agree [Topmodel2007] (@test-psycho.R#22) 
  
  Error: testthat unit tests failed
  Execution halted