Given an input dataset, predict the output composition. Specifically, this outputs \(\phi^{-1}(Bx)\), for the inverse log ratio transformation \(\phi^{-1}\) and fitted covariate matrix \(B\).
Usage
# S4 method for class 'lnm'
predict(object, newdata = NULL, ...)
Arguments
- object
An object of class lnm with fitted parameters \(\hat{B}\) and which we want to use to form predictions on new samples.
- newdata
New samples on which to form predictions. Defaults to NULL, in which case predictions are made at the same design points as those used during the original training.
- ...
Additional keyword arguments, for consistency with R's predict generic (never used).
Examples
example_data <- lnm_data(N = 50, K = 10)
xy <- dplyr::bind_cols(example_data[c("X", "y")])
fit <- lnm(
starts_with("y") ~ starts_with("x"), xy,
iter = 25, output_samples = 25
)
#> 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 0.001753 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 17.53 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: Informational Message: The maximum number of iterations is reached! The algorithm may not have converged.
#> Chain 1: This variational approximation is not guaranteed to be meaningful.
#> Chain 1:
#> Chain 1: Drawing a sample of size 25 from the approximate posterior...
#> Chain 1: COMPLETED.
#> Warning: Pareto k diagnostic value is Inf. Resampling is disabled. Decreasing tol_rel_obj may help if variational algorithm has terminated prematurely. Otherwise consider using sampling instead.
head(predict(fit))
#> y1 y2 y3 y4 y5 y6
#> [1,] 0.02209271 0.7526938 0.04958053 0.07840177 0.021488031 0.0005108251
#> [2,] 0.08749094 0.3422915 0.13687421 0.14526691 0.129758491 0.0039208372
#> [3,] 0.04519725 0.3734171 0.06224853 0.24606256 0.019395818 0.0054161591
#> [4,] 0.01129906 0.7291611 0.02781850 0.10258837 0.008036911 0.0008782158
#> [5,] 0.01830196 0.7021003 0.04368681 0.11683142 0.021409102 0.0002946521
#> [6,] 0.06195914 0.3846427 0.10070916 0.17125503 0.072838410 0.0072916754
#> y7 y8 y9 y10
#> [1,] 0.004255046 0.02411289 0.04590836 0.0009559920
#> [2,] 0.014047821 0.08003213 0.05645340 0.0038637567
#> [3,] 0.028365344 0.05987917 0.14388271 0.0161353146
#> [4,] 0.005076642 0.01153915 0.10200563 0.0015963995
#> [5,] 0.003955742 0.01658411 0.07636082 0.0004750287
#> [6,] 0.022042855 0.05576874 0.11578690 0.0077053727