This samples from the posterior predictive of a fitted logistic-normal multinomial model.
Arguments
- fit
The fitted LNM model from which to draw posterior predictive samples.
- newdata
A data.frame containing new inputs from which to sample responses. If NULL, defaults to the data used to estimate fit.
- indices
The coordinates of the response from which to draw samples.
- ...
Additional parameters passed to sample.
Examples
m <- lnm_model()
mat <- data.frame(matrix(rpois(250, 10), 25, 10))
colnames(mat) <- paste0("y", 1:6)
fit <- estimator(m)(y1 + y2 + y3 + y4 ~ y5 + y6, mat)
#> Chain 1: ------------------------------------------------------------
#> Chain 1: EXPERIMENTAL ALGORITHM:
#> Chain 1: This procedure has not been thoroughly tested and may be unstable
#> Chain 1: or buggy. The interface is subject to change.
#> Chain 1: ------------------------------------------------------------
#> Chain 1:
#> Chain 1:
#> Chain 1:
#> Chain 1: Gradient evaluation took 3.9e-05 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.39 seconds.
#> Chain 1: Adjust your expectations accordingly!
#> Chain 1:
#> Chain 1:
#> Chain 1: Begin eta adaptation.
#> Chain 1: Iteration: 1 / 250 [ 0%] (Adaptation)
#> Chain 1: Iteration: 50 / 250 [ 20%] (Adaptation)
#> Chain 1: Iteration: 100 / 250 [ 40%] (Adaptation)
#> Chain 1: Iteration: 150 / 250 [ 60%] (Adaptation)
#> Chain 1: Iteration: 200 / 250 [ 80%] (Adaptation)
#> Chain 1: Success! Found best value [eta = 1] earlier than expected.
#> Chain 1:
#> Chain 1: Begin stochastic gradient ascent.
#> Chain 1: iter ELBO delta_ELBO_mean delta_ELBO_med notes
#> Chain 1: 100 -511.480 1.000 1.000
#> Chain 1: 200 -340.013 0.752 1.000
#> Chain 1: 300 -263.320 0.599 0.504
#> Chain 1: 400 -280.601 0.464 0.504
#> Chain 1: 500 -266.805 0.382 0.291
#> Chain 1: 600 -248.127 0.331 0.291
#> Chain 1: 700 -250.466 0.285 0.075
#> Chain 1: 800 -251.766 0.250 0.075
#> Chain 1: 900 -248.461 0.224 0.062
#> Chain 1: 1000 -240.720 0.204 0.062
#> Chain 1: 1100 -239.577 0.105 0.052
#> Chain 1: 1200 -248.111 0.058 0.034
#> Chain 1: 1300 -244.463 0.030 0.032
#> Chain 1: 1400 -252.400 0.027 0.031
#> Chain 1: 1500 -245.420 0.025 0.028
#> Chain 1: 1600 -251.093 0.020 0.023
#> Chain 1: 1700 -248.919 0.020 0.023
#> Chain 1: 1800 -248.266 0.019 0.023
#> Chain 1: 1900 -247.179 0.018 0.023
#> Chain 1: 2000 -248.216 0.016 0.015
#> Chain 1: 2100 -244.814 0.017 0.015
#> Chain 1: 2200 -245.288 0.013 0.014
#> Chain 1: 2300 -236.743 0.015 0.014
#> Chain 1: 2400 -238.289 0.013 0.009 MEDIAN ELBO CONVERGED
#> Chain 1:
#> Chain 1: Drawing a sample of size 1000 from the approximate posterior...
#> Chain 1: COMPLETED.
#> Warning: Pareto k diagnostic value is 2.02. Resampling is disabled. Decreasing tol_rel_obj may help if variational algorithm has terminated prematurely. Otherwise consider using sampling instead.
lnm_sampler(fit, depth = 10)
#> y1 y2 y3 y4
#> [1,] 2 3 2 3
#> [2,] 3 1 1 5
#> [3,] 3 1 3 3
#> [4,] 1 3 5 1
#> [5,] 2 1 2 5
#> [6,] 3 3 2 2
#> [7,] 2 2 4 2
#> [8,] 2 3 1 4
#> [9,] 3 4 2 1
#> [10,] 2 7 1 0
#> [11,] 3 3 1 3
#> [12,] 3 2 4 1
#> [13,] 2 4 1 3
#> [14,] 2 1 4 3
#> [15,] 0 4 4 2
#> [16,] 3 2 1 4
#> [17,] 0 5 1 4
#> [18,] 1 5 0 4
#> [19,] 4 3 0 3
#> [20,] 2 3 1 4
#> [21,] 1 4 5 0
#> [22,] 0 5 5 0
#> [23,] 3 3 1 3
#> [24,] 1 3 3 3
#> [25,] 1 4 1 4
lnm_sampler(fit, depth = 100)
#> y1 y2 y3 y4
#> [1,] 33 25 17 25
#> [2,] 23 33 17 27
#> [3,] 36 29 12 23
#> [4,] 24 29 17 30
#> [5,] 27 27 13 33
#> [6,] 26 29 19 26
#> [7,] 21 17 17 45
#> [8,] 27 24 27 22
#> [9,] 24 39 17 20
#> [10,] 26 29 17 28
#> [11,] 22 24 18 36
#> [12,] 35 27 14 24
#> [13,] 24 24 20 32
#> [14,] 27 33 11 29
#> [15,] 15 32 26 27
#> [16,] 24 37 19 20
#> [17,] 22 33 7 38
#> [18,] 27 36 19 18
#> [19,] 23 28 24 25
#> [20,] 25 27 15 33
#> [21,] 24 34 21 21
#> [22,] 30 23 22 25
#> [23,] 31 18 29 22
#> [24,] 22 22 29 27
#> [25,] 33 19 18 30