Extract latent factor posteriors from fit
Usage
latent_factors(fit, ...)
# Default S3 method
latent_factors(fit, summary = TRUE, probs = c(0.025, 0.5, 0.975), ...)Arguments
- fit
A fit sampled with latent factors: its draw matrix (
$drawsor$samples) holds columns namedfactor[observation,factor]and$.internal$latent_inforecords the layout. The default method reads any fit, of any class, that stores them this way.- ...
Passed to methods.
- summary
Logical; if TRUE, return summary statistics. If FALSE, return full posterior draws.
- probs
Quantiles for summary. Default is c(0.025, 0.5, 0.975).
Value
If summary = TRUE, a data frame with columns for observation,
factor, and summary statistics. If summary = FALSE, a matrix of
posterior draws.
Examples
# A fit sampled with latent factors comes from a model package (tulpaRatio
# reads the latent_factor() spec). The accessor reads two things off it:
# draw columns named factor[observation,factor] and the latent layout. Here
# both are simulated for three observations on two factors.
set.seed(1)
cols <- sprintf("factor[%d,%d]", rep(1:3, 2), rep(1:2, each = 3))
draws <- matrix(rnorm(200 * 6, mean = rep(c(-1, 0, 1), 2), sd = 0.3),
200, 6, byrow = TRUE, dimnames = list(NULL, cols))
fit <- structure(
list(draws = draws,
.internal = list(latent_info = list(type = "latent", n_factors = 2L,
n_obs = 3L))),
class = "tulpa_fit")
latent_factors(fit)
dim(latent_factors(fit, summary = FALSE))