R Under development (unstable) (2023-08-05 r84874 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > 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.54 0.03 0.56