Running 'test_checks.R' [165s]
  Running 'test_donothing.R' [163s]
  Running 'test_estim.R' [152s]
  Running 'test_factor.R' [1s]
  Running 'test_factors.R' [1s]
  Running 'test_prior_ff.R' [1s]
  Running 'test_split.R' [168s]
  Running 'test_transprobs.R' [2s]
Running the tests in 'tests/test_checks.R' failed.
Complete output:
  > library(efdm)
  > library(testthat)
  > statespace <- expand.grid(a=1:2, b=1:2, vol=1:5)
  > state0 <- statespace
  > actprob <- statespace
  > actprob$test <- 1
  > state0$area <- 0
  > state0$area[1] <- 1
  > 
  > 
  > act3 <- define_activity("test", c("vol"))
  > transprobs(act3) <- data.frame(vol0 = 1:4, vol1=2:5, prob=1)
  > expect_error(runEFDM(state0, actprob, list(act3), 5), "States with no activity (in list of activities)", fixed=TRUE)
  [1] "States with no activity (in list of activities):"
     vol a b test check___
  17   5 1 1    1        0
  18   5 2 1    1        0
  19   5 1 2    1        0
  20   5 2 2    1        0
  > expect_error(runEFDM(state0, data.frame(test=1), list(act3), 5), "No state variables in actprob")
  > 
  > 
  > 
  > transprobs(act3) <- data.frame(vol0 = 1:5, vol1=c(2:6), prob=1)
  > expect_error(runEFDM(state0, actprob, list(act3), 3), "Activity transitions to state not in actprob")
  [1] "Activity 'test' caused transitions to state not in actprob:"
     vol  a  b test check___ check_1__
  21   6 NA NA   NA       NA        NA
  > 
  > 
  > expect_error(runEFDM(state0, actprob, list(act3, act3), 3), "States with multiple activities")
  [1] "States with multiple activities:"
    vol a b test check___ check_1__
  1   1 1 1    1        2         1
  2   1 2 1    1        2         1
  3   1 1 2    1        2         1
  4   1 2 2    1        2         1
  5   2 1 1    1        2         1
  6   2 2 1    1        2         1
  > 
  > 
  > act4 <- define_activity("test2", c("vol"))
  > transprobs(act4) <- data.frame(vol0 = 1:5, vol1=c(2:5,5), prob=1)
  > expect_error(runEFDM(state0, actprob, list(act4), 5), "Activity probabilities for test2 not given.")
  > 
  > act5 <- define_activity("test", c("vol"))
  > transprobs(act5) <- data.frame(vol0 = 1:6, vol1=2, prob=1)
  > expect_error(runEFDM(state0, actprob, list(act5), 5), "Activity transitions from state not in actprob")
  [1] "Activity transitions from state not in actprob:"
     vol  a  b test check___
  21   6 NA NA   NA       NA
  > 
  > act6 <- define_activity("test", c("vol"))
  > expect_error(runEFDM(state0, actprob, list(act6), 1), "Activity 'test' has no transprobs.")
  > transprobs(act6) <- data.frame(vol0 = 1:5, vol1=2, c=1, prob=1)
  > expect_error(runEFDM(state0, actprob, list(act6), 1), "Activity 'test' has variable c not in actprob.")
  > 
  > actprob$test[3] <- NA
  > expect_error(runEFDM(state0, actprob, list(act3), 5), "Actprob should not have NAs.")
  > 
  > actprob$test2 <- actprob$test <- 0.5
  > expect_error(runEFDM(state0, actprob, list(act3), 5), "Activity probabilities for test2 given, but activities not.")
  > 
  > proc.time()
     user  system elapsed 
     1.56    0.20    1.75 
Running the tests in 'tests/test_donothing.R' failed.
Complete output:
  > library(efdm)
  > library(testthat)
  > 
  > statespace <- expand.grid(a=1:2, b=1:2, vol=1:5)
  > state0 <- statespace
  > actprob <- statespace
  > actprob$test <- 1
  > state0$area <- 0
  > state0$area[1] <- 1
  > 
  > 
  > act1 <- define_activity("test", character())
  > expect_error(transprobs(act1) <- data.frame(vol0 = 1:4, vol1=2:5, prob=1))
  > state1 <- runEFDM(state0, actprob, list(act1), 5)
  > expect_equal(state1$vol, rep(1, 6))
  > 
  > act2 <- define_activity("test2", "vol")
  > transprobs(act2) <- data.frame(vol0=1:5, vol1=c(2:5,5), prob=1)
  > actprob$test <- 0.1
  > actprob$test2 <- 0.9
  > expect_known_hash(runEFDM(state0, actprob, list(act1, act2), 5), "1b23f7f782")
  > 
  > 
  > proc.time()
     user  system elapsed 
     1.48    0.18    1.65 
Running the tests in 'tests/test_estim.R' failed.
Complete output:
  > data.table::setDTthreads(1)
  > library(efdm)
  > statespace <- expand.grid(a=1:2, b=1:2, vol=1:5)
  > pairdata <- data.frame(a=c(1,1,2,2), b=c(1,2,1,2), vol0=c(1,1,1,1), vol1=c(2,3,4,5))
  > state0 <- statespace
  > actprob <- statespace
  > actprob$test <- 1
  > state0$area <- 0
  > state0$area[1] <- 1
  > 
  > act1 <- define_activity("test", c("vol"))
  > transprobs(act1) <- estimatetransprobs("vol", pairdata, statespace, by=c("a", "b"), prior="nochange")
  > transprobs(act1)
     vol0 a b vol1 prob
  1     1 1 1    1  0.5
  2     1 1 1    2  0.5
  3     2 1 1    2  1.0
  4     3 1 1    3  1.0
  5     4 1 1    4  1.0
  6     5 1 1    5  1.0
  7     1 2 1    1  0.5
  8     1 2 1    4  0.5
  9     2 2 1    2  1.0
  10    3 2 1    3  1.0
  11    4 2 1    4  1.0
  12    5 2 1    5  1.0
  13    1 1 2    1  0.5
  14    1 1 2    3  0.5
  15    2 1 2    2  1.0
  16    3 1 2    3  1.0
  17    4 1 2    4  1.0
  18    5 1 2    5  1.0
  19    1 2 2    1  0.5
  20    1 2 2    5  0.5
  21    2 2 2    2  1.0
  22    3 2 2    3  1.0
  23    4 2 2    4  1.0
  24    5 2 2    5  1.0
  > runEFDM(state0, actprob, list(act1), 1)
    a b vol area activity time
  1 1 1   1  1.0     test    0
  2 1 1   1  0.5     test    1
  3 1 1   2  0.5     test    1
  > act2 <- define_activity("test", c("vol"))
  > transprobs(act2) <- estimatetransprobs("vol", pairdata, statespace, factors="a", by="b", prior="nochange")
  > transprobs(act2)
     vol0 a b vol1 prob
  1     1 1 1    1 0.25
  2     1 1 1    2 0.50
  3     1 1 1    4 0.25
  4     1 2 1    1 0.25
  5     1 2 1    2 0.25
  6     1 2 1    4 0.50
  7     2 1 1    2 1.00
  8     2 2 1    2 1.00
  9     3 1 1    3 1.00
  10    3 2 1    3 1.00
  11    4 1 1    4 1.00
  12    4 2 1    4 1.00
  13    5 1 1    5 1.00
  14    5 2 1    5 1.00
  15    1 1 2    1 0.25
  16    1 1 2    5 0.25
  17    1 1 2    3 0.50
  18    1 2 2    1 0.25
  19    1 2 2    5 0.50
  20    1 2 2    3 0.25
  21    2 1 2    2 1.00
  22    2 2 2    2 1.00
  23    3 1 2    3 1.00
  24    3 2 2    3 1.00
  25    4 1 2    4 1.00
  26    4 2 2    4 1.00
  27    5 1 2    5 1.00
  28    5 2 2    5 1.00
  > runEFDM(state0, actprob, list(act2), 1)
    a b vol area activity time
  1 1 1   1 1.00     test    0
  2 1 1   1 0.25     test    1
  3 1 1   2 0.50     test    1
  4 1 1   4 0.25     test    1
  > act3 <- define_activity("test", c("vol"))
  > transprobs(act3) <- estimatetransprobs("vol", pairdata, statespace, factors="b", by="a", prior="nochange")
  > transprobs(act3)
     vol0 b a vol1 prob
  1     1 1 1    1 0.25
  2     1 1 1    2 0.50
  3     1 1 1    3 0.25
  4     1 2 1    1 0.25
  5     1 2 1    2 0.25
  6     1 2 1    3 0.50
  7     2 1 1    2 1.00
  8     2 2 1    2 1.00
  9     3 1 1    3 1.00
  10    3 2 1    3 1.00
  11    4 1 1    4 1.00
  12    4 2 1    4 1.00
  13    5 1 1    5 1.00
  14    5 2 1    5 1.00
  15    1 1 2    1 0.25
  16    1 1 2    5 0.25
  17    1 1 2    4 0.50
  18    1 2 2    1 0.25
  19    1 2 2    5 0.50
  20    1 2 2    4 0.25
  21    2 1 2    2 1.00
  22    2 2 2    2 1.00
  23    3 1 2    3 1.00
  24    3 2 2    3 1.00
  25    4 1 2    4 1.00
  26    4 2 2    4 1.00
  27    5 1 2    5 1.00
  28    5 2 2    5 1.00
  > runEFDM(state0, actprob, list(act3), 1)
    b a vol area activity time
  1 1 1   1 1.00     test    0
  2 1 1   1 0.25     test    1
  3 1 1   2 0.50     test    1
  4 1 1   3 0.25     test    1
  > act4 <- define_activity("test", c("vol"))
  > transprobs(act4) <- estimatetransprobs("vol", pairdata, statespace, factors=c("a", "b"), prior="nochange")
  > transprobs(act4)
     vol0 a b vol1  prob
  1     1 1 1    1 0.125
  2     1 1 1    2 0.375
  3     1 1 1    3 0.250
  4     1 1 1    4 0.125
  5     1 1 1    5 0.125
  6     1 1 2    1 0.125
  7     1 1 2    2 0.250
  8     1 1 2    3 0.375
  9     1 1 2    4 0.125
  10    1 1 2    5 0.125
  11    1 2 1    1 0.125
  12    1 2 1    2 0.125
  13    1 2 1    3 0.125
  14    1 2 1    4 0.375
  15    1 2 1    5 0.250
  16    1 2 2    1 0.125
  17    1 2 2    2 0.125
  18    1 2 2    3 0.125
  19    1 2 2    4 0.250
  20    1 2 2    5 0.375
  21    2 1 1    2 1.000
  22    2 1 2    2 1.000
  23    2 2 1    2 1.000
  24    2 2 2    2 1.000
  25    3 1 1    3 1.000
  26    3 1 2    3 1.000
  27    3 2 1    3 1.000
  28    3 2 2    3 1.000
  29    4 1 1    4 1.000
  30    4 1 2    4 1.000
  31    4 2 1    4 1.000
  32    4 2 2    4 1.000
  33    5 1 1    5 1.000
  34    5 1 2    5 1.000
  35    5 2 1    5 1.000
  36    5 2 2    5 1.000
  > runEFDM(state0, actprob, list(act4), 1)
    a b vol  area activity time
  1 1 1   1 1.000     test    0
  2 1 1   1 0.125     test    1
  3 1 1   2 0.375     test    1
  4 1 1   3 0.250     test    1
  5 1 1   4 0.125     test    1
  6 1 1   5 0.125     test    1
  > act5 <- define_activity("test", c("vol"))
  > transprobs(act5) <- estimatetransprobs("vol", pairdata, statespace, factors=c("b", "a"), prior="nochange")
  > transprobs(act5)
     vol0 b a vol1  prob
  1     1 1 1    1 0.125
  2     1 1 1    2 0.375
  3     1 1 1    3 0.125
  4     1 1 1    4 0.250
  5     1 1 1    5 0.125
  6     1 1 2    1 0.125
  7     1 1 2    2 0.250
  8     1 1 2    3 0.125
  9     1 1 2    4 0.375
  10    1 1 2    5 0.125
  11    1 2 1    1 0.125
  12    1 2 1    2 0.125
  13    1 2 1    3 0.375
  14    1 2 1    4 0.125
  15    1 2 1    5 0.250
  16    1 2 2    1 0.125
  17    1 2 2    2 0.125
  18    1 2 2    3 0.250
  19    1 2 2    4 0.125
  20    1 2 2    5 0.375
  21    2 1 1    2 1.000
  22    2 1 2    2 1.000
  23    2 2 1    2 1.000
  24    2 2 2    2 1.000
  25    3 1 1    3 1.000
  26    3 1 2    3 1.000
  27    3 2 1    3 1.000
  28    3 2 2    3 1.000
  29    4 1 1    4 1.000
  30    4 1 2    4 1.000
  31    4 2 1    4 1.000
  32    4 2 2    4 1.000
  33    5 1 1    5 1.000
  34    5 1 2    5 1.000
  35    5 2 1    5 1.000
  36    5 2 2    5 1.000
  > runEFDM(state0, actprob, list(act5), 1)
    b a vol  area activity time
  1 1 1   1 1.000     test    0
  2 1 1   1 0.125     test    1
  3 1 1   2 0.375     test    1
  4 1 1   3 0.125     test    1
  5 1 1   4 0.250     test    1
  6 1 1   5 0.125     test    1
  > 
  > act6 <- define_activity("test", c("vol"))
  > transprobs(act6) <- estimatetransprobs("vol", pairdata[c("vol0", "vol1")], data.frame(vol=1:5), prior="nochange")
  > transprobs(act6)
    vol0 vol1 prob
  1    1    1  0.2
  2    1    2  0.2
  3    1    3  0.2
  4    1    4  0.2
  5    1    5  0.2
  6    2    2  1.0
  7    3    3  1.0
  8    4    4  1.0
  9    5    5  1.0
  > runEFDM(state0, actprob, list(act6), 1)
    vol a b area activity time
  1   1 1 1  1.0     test    0
  2   1 1 1  0.2     test    1
  3   2 1 1  0.2     test    1
  4   3 1 1  0.2     test    1
  5   4 1 1  0.2     test    1
  6   5 1 1  0.2     test    1
  > 
  > try(estimatetransprobs("vol", pairdata[c("vol0", "vol1")], data.frame(vol=1:4), prior="nochange"))
  [1] "Pairdata has transitions resulting in states that are not in statespace."
    vol1 vol0 check_missing_combinations
  4    5    1                         NA
  Error in estimatetransprobs("vol", pairdata[c("vol0", "vol1")], data.frame(vol = 1:4),  : 
    Pairdata has transitions resulting in states that are not in statespace.
  > 
  > try(estimatetransprobs("Vol", pairdata[c("vol0", "vol1")], data.frame(vol=1:4), prior="nochange"))
  Error in build_complex_statespace(act, statespace0, statespace1, factors,  : 
    Variables 'vol' in statespace not used by activity.
  > 
  > try(estimatetransprobs("Vol", pairdata[c("vol0", "vol1")], data.frame(Vol=1:4), prior="nochange"))
  Error in estimatetransprobs("Vol", pairdata[c("vol0", "vol1")], data.frame(Vol = 1:4),  : 
    Variable(s) 'c("Vol0", "Vol1")' not present in pairdata.
  > 
  > 
  > ## TODO: add the above tests for these too
  > 
  > statespace <- expand.grid(a=c("pine", "spruce"), b=1:2, vol=1:5)
  > pairdata <- data.frame(a=c("pine", "pine", "spruce", "spruce"), b=c(1,2,1,2), vol0=c(1,1,1,1), vol1=c(2,3,4,5))
  > state0 <- statespace
  > actprob <- statespace
  > actprob$test <- 1
  > state0$area <- 0
  > state0$area[1] <- 1
  > 
  > 
  > statespace <- expand.grid(a=as.factor(c("pine", "spruce")), b=1:2, vol=1:5)
  > pairdata <- data.frame(a=as.factor(c("pine", "pine", "spruce", "spruce")), b=c(1,2,1,2), vol0=c(1,1,1,1), vol1=c(2,3,4,5))
  > state0 <- statespace
  > actprob <- statespace
  > actprob$test <- 1
  > state0$area <- 0
  > state0$area[1] <- 1
  > 
  > proc.time()
     user  system elapsed 
     0.60    0.06    0.65 
Running the tests in 'tests/test_split.R' failed.
Complete output:
  > data.table::setDTthreads(1)
  > library(testthat)
  > library(efdm)
  > statespace <- expand.grid(ds=c("sp", "pi"), region=c("n", "s"), vol=1:3, stringsAsFactors=FALSE)
  > pairdata <- data.frame(ds=c("sp", "pi"), vol0=c(1,1), vol1=c(2,3), region=c("n", "s"))
  > actprob <- state0 <- statespace
  > actprob$test <- 1
  > state0$area <- c(1,1,1,1, 0,0,0,0, 0,0,0,0)
  > orderresult <- function(res) {
  +   res <- res[do.call(order, res[c("time", "region", "ds", "vol")]),c("time", "region", "ds", "vol", "activity", "area")]
  +   row.names(res) <- NULL
  +   res
  + }
  > 
  > act1 <- define_activity("test", c("vol"))
  > transprobs(act1) <- estimatetransprobs("vol", NULL, subset(statespace, ds=="sp"&region=="n"), factors=c("ds", "region"), prior="nochange")
  > act2 <- define_activity("test", c("vol"))
  > transprobs(act2) <- estimatetransprobs("vol", NULL, subset(statespace, !(ds=="sp"&region=="n")), factors=c("ds", "region"), prior="nochange")
  > orderresult(runEFDM(state0, actprob, list(act1, act2), 1))
    time region ds vol activity area
  1    0      n pi   1     test    1
  2    0      n sp   1     test    1
  3    0      s pi   1     test    1
  4    0      s sp   1     test    1
  5    1      n pi   1     test    1
  6    1      n sp   1     test    1
  7    1      s pi   1     test    1
  8    1      s sp   1     test    1
  > 
  > act1 <- define_activity("test", c("vol"))
  > transprobs(act1) <- estimatetransprobs("vol", subset(pairdata, ds=="sp"&region=="n"), subset(statespace, ds=="sp"&region=="n"), factors=c("ds", "region"), prior="nochange")
  > act2 <- define_activity("test", c("vol"))
  > transprobs(act2) <- estimatetransprobs("vol", subset(pairdata, !(ds=="sp"&region=="n")), subset(statespace, !(ds=="sp"&region=="n")), factors=c("ds", "region"), prior="nochange")
  > orderresult(runEFDM(state0, actprob, list(act1, act2), 10))
     time region ds vol activity         area
  1     0      n pi   1     test 1.000000e+00
  2     0      n sp   1     test 1.000000e+00
  3     0      s pi   1     test 1.000000e+00
  4     0      s sp   1     test 1.000000e+00
  5     1      n pi   1     test 3.333333e-01
  6     1      n pi   3     test 6.666667e-01
  7     1      n sp   1     test 2.500000e-01
  8     1      n sp   2     test 7.500000e-01
  9     1      s pi   1     test 2.500000e-01
  10    1      s pi   3     test 7.500000e-01
  11    1      s sp   1     test 5.000000e-01
  12    1      s sp   3     test 5.000000e-01
  13    2      n pi   1     test 1.111111e-01
  14    2      n pi   3     test 8.888889e-01
  15    2      n sp   1     test 6.250000e-02
  16    2      n sp   2     test 9.375000e-01
  17    2      s pi   1     test 6.250000e-02
  18    2      s pi   3     test 9.375000e-01
  19    2      s sp   1     test 2.500000e-01
  20    2      s sp   3     test 7.500000e-01
  21    3      n pi   1     test 3.703704e-02
  22    3      n pi   3     test 9.629630e-01
  23    3      n sp   1     test 1.562500e-02
  24    3      n sp   2     test 9.843750e-01
  25    3      s pi   1     test 1.562500e-02
  26    3      s pi   3     test 9.843750e-01
  27    3      s sp   1     test 1.250000e-01
  28    3      s sp   3     test 8.750000e-01
  29    4      n pi   1     test 1.234568e-02
  30    4      n pi   3     test 9.876543e-01
  31    4      n sp   1     test 3.906250e-03
  32    4      n sp   2     test 9.960938e-01
  33    4      s pi   1     test 3.906250e-03
  34    4      s pi   3     test 9.960938e-01
  35    4      s sp   1     test 6.250000e-02
  36    4      s sp   3     test 9.375000e-01
  37    5      n pi   1     test 4.115226e-03
  38    5      n pi   3     test 9.958848e-01
  39    5      n sp   1     test 9.765625e-04
  40    5      n sp   2     test 9.990234e-01
  41    5      s pi   1     test 9.765625e-04
  42    5      s pi   3     test 9.990234e-01
  43    5      s sp   1     test 3.125000e-02
  44    5      s sp   3     test 9.687500e-01
  45    6      n pi   1     test 1.371742e-03
  46    6      n pi   3     test 9.986283e-01
  47    6      n sp   1     test 2.441406e-04
  48    6      n sp   2     test 9.997559e-01
  49    6      s pi   1     test 2.441406e-04
  50    6      s pi   3     test 9.997559e-01
  51    6      s sp   1     test 1.562500e-02
  52    6      s sp   3     test 9.843750e-01
  53    7      n pi   1     test 4.572474e-04
  54    7      n pi   3     test 9.995428e-01
  55    7      n sp   1     test 6.103516e-05
  56    7      n sp   2     test 9.999390e-01
  57    7      s pi   1     test 6.103516e-05
  58    7      s pi   3     test 9.999390e-01
  59    7      s sp   1     test 7.812500e-03
  60    7      s sp   3     test 9.921875e-01
  61    8      n pi   1     test 1.524158e-04
  62    8      n pi   3     test 9.998476e-01
  63    8      n sp   1     test 1.525879e-05
  64    8      n sp   2     test 9.999847e-01
  65    8      s pi   1     test 1.525879e-05
  66    8      s pi   3     test 9.999847e-01
  67    8      s sp   1     test 3.906250e-03
  68    8      s sp   3     test 9.960938e-01
  69    9      n pi   1     test 5.080526e-05
  70    9      n pi   3     test 9.999492e-01
  71    9      n sp   1     test 3.814697e-06
  72    9      n sp   2     test 9.999962e-01
  73    9      s pi   1     test 3.814697e-06
  74    9      s pi   3     test 9.999962e-01
  75    9      s sp   1     test 1.953125e-03
  76    9      s sp   3     test 9.980469e-01
  77   10      n pi   1     test 1.693509e-05
  78   10      n pi   3     test 9.999831e-01
  79   10      n sp   1     test 9.536743e-07
  80   10      n sp   2     test 9.999990e-01
  81   10      s pi   1     test 9.536743e-07
  82   10      s pi   3     test 9.999990e-01
  83   10      s sp   1     test 9.765625e-04
  84   10      s sp   3     test 9.990234e-01
  > 
  > 
  > statespace <- expand.grid(ds=c("sp", "pi"), region=c("n", "s"), vol=1:3, stringsAsFactors=FALSE)
  > act <- define_activity("test", c("vol"))
  > statespace1 <- subset(statespace, !(ds=="sp"&region=="n"))
  > act <- efdm:::build_complex_statespace(act, statespace1, statespace1, factors=c("ds", "region"))
  > stopifnot(nrow(act$statespace[[1]])==3)
  > 
  > statespace <- expand.grid(a=1:2, b=c("f", "g"), c=c(4,9), vol=1:3, stringsAsFactors=FALSE)
  > ii <- sample(nrow(statespace), sample(nrow(statespace), 1))
  > act <- define_activity("test", c("vol"))
  > act <- efdm:::build_complex_statespace(act, statespace[ii,], statespace[ii,], factors=c("a", "b"), by="c")
  > expect_identical(sum(sapply(act$statespace, function(x) nrow(x$statespace0))), length(ii))
  > 
  > proc.time()
     user  system elapsed 
     1.37    0.21    1.57