R Under development (unstable) (2024-07-15 r86902 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 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("cotram") Loading required package: tram Loading required package: mlt Loading required package: basefun Loading required package: variables Loading required package: mvtnorm > options(digits = 2) > > set.seed(25) > > ## dgp > n <- 200 > x <- runif(n, 0, 20) > y <- as.integer(rnbinom(n, mu = exp(.2 + .1 * x), size = 3)) > d <- data.frame(y = y, x = x) > > m <- cotram(y ~ x, data = d) Model was fitted to log(y + 1). > > nd <- model.frame(m)[3,] > > ## Confband for grid of counts > confband(m, type = "distribution", newdata = nd) q Estimate lwr upr 3 0 0.25 0.16 0.38 3.1 1 0.57 0.44 0.69 3.2 2 0.72 0.59 0.81 3.3 3 0.83 0.73 0.90 3.4 4 0.90 0.83 0.94 3.5 5 0.94 0.88 0.97 3.6 6 0.96 0.92 0.98 3.7 7 0.97 0.94 0.99 3.8 8 0.98 0.96 0.99 3.9 9 0.99 0.97 0.99 3.10 10 0.99 0.98 1.00 3.11 11 0.99 0.98 1.00 3.12 12 1.00 0.98 1.00 3.13 13 1.00 0.99 1.00 3.14 14 1.00 0.99 1.00 3.15 15 1.00 0.99 1.00 3.16 16 1.00 0.99 1.00 3.17 17 1.00 0.99 1.00 3.18 18 1.00 0.99 1.00 3.19 19 1.00 0.99 1.00 3.20 20 1.00 0.99 1.00 3.21 21 1.00 0.99 1.00 3.22 22 1.00 1.00 1.00 3.23 23 1.00 1.00 1.00 3.24 24 1.00 1.00 1.00 3.25 25 1.00 1.00 1.00 3.26 26 1.00 1.00 1.00 3.27 27 1.00 1.00 1.00 3.28 28 1.00 1.00 1.00 3.29 29 1.00 1.00 1.00 3.30 30 1.00 1.00 1.00 3.31 31 1.00 1.00 1.00 > > ## Confband for K grid points > confband(m, type = "distribution", newdata = nd, smooth = TRUE, K = 40) q Estimate lwr upr 3 0.00 0.25 0.16 0.38 3.1 0.79 0.53 0.36 0.70 3.2 1.59 0.66 0.52 0.77 3.3 2.38 0.77 0.65 0.85 3.4 3.18 0.85 0.75 0.91 3.5 3.97 0.90 0.82 0.94 3.6 4.77 0.93 0.87 0.96 3.7 5.56 0.95 0.90 0.98 3.8 6.36 0.97 0.93 0.98 3.9 7.15 0.97 0.94 0.99 3.10 7.95 0.98 0.96 0.99 3.11 8.74 0.99 0.97 0.99 3.12 9.54 0.99 0.97 1.00 3.13 10.33 0.99 0.98 1.00 3.14 11.13 0.99 0.98 1.00 3.15 11.92 1.00 0.98 1.00 3.16 12.72 1.00 0.99 1.00 3.17 13.51 1.00 0.99 1.00 3.18 14.31 1.00 0.99 1.00 3.19 15.10 1.00 0.99 1.00 3.20 15.90 1.00 0.99 1.00 3.21 16.69 1.00 0.99 1.00 3.22 17.49 1.00 0.99 1.00 3.23 18.28 1.00 0.99 1.00 3.24 19.08 1.00 0.99 1.00 3.25 19.87 1.00 0.99 1.00 3.26 20.67 1.00 0.99 1.00 3.27 21.46 1.00 0.99 1.00 3.28 22.26 1.00 0.99 1.00 3.29 23.05 1.00 1.00 1.00 3.30 23.85 1.00 1.00 1.00 3.31 24.64 1.00 1.00 1.00 3.32 25.44 1.00 1.00 1.00 3.33 26.23 1.00 1.00 1.00 3.34 27.03 1.00 1.00 1.00 3.35 27.82 1.00 1.00 1.00 3.36 28.62 1.00 1.00 1.00 3.37 29.41 1.00 1.00 1.00 3.38 30.21 1.00 1.00 1.00 3.39 31.00 1.00 1.00 1.00 > > > if (FALSE){ + layout(matrix(1:2, nrow = 1)) + type = "trafo" + + cb <- confband(m, type = type, newdata = nd) + plot(m, type = type, newdata = nd, + confidence = "band", col = "red", ylim = c(-2, 15)) + lines(x = cb[, "q"], y = cb[, "lwr"], type = "s") + lines(x = cb[, "q"], y = cb[, "upr"], type = "s") + + cb.s <- confband(m, type = type, newdata = nd, smooth = TRUE) + plot(m, type = type, newdata = nd, smooth = TRUE, + confidence = "band", col = "red", ylim = c(-2, 15)) + lines(x = cb.s[, "q"], y = cb.s[, "lwr"], type = "l") + lines(x = cb.s[, "q"], y = cb.s[, "upr"], type = "l") + } > > > proc.time() user system elapsed 3.09 0.23 3.32