blavPredict | R Documentation |
The purpose of the blavPredict()
function is to compute various
types of model predictions, conditioned on observed data. This differs
somewhat from lavPredict()
in lavaan.
blavPredict(object, newdata = NULL, type = "lv", level = 1L)
object |
An object of class |
newdata |
An optional data.frame, containing the same variables as the data.frame used when fitting the model in object. |
type |
A character string. If |
level |
For |
The predict()
function calls the blavPredict()
function
with its default options.
Below, we provide more information about each type
option. Most
options only work for target="stan", and "number of samples" is defined
as the number of posterior samples across all chains.
type="lv"
: The posterior distribution of latent variables
conditioned on observed variables. Returns a list with
"number of samples" entries, where each entry is a matrix where rows
are observations and columns are latent variables.
type="yhat"
: The posterior expected value of observed variables
conditioned on the sampled latent variables. Returns a list with
"number of samples" entries, where each entry is a matrix where rows
are observations and columns are observed variables.
type="ypred"
: The posterior predictive distribution of observed
variables conditioned on the sampled latent variables (including
residual variability). Returns a list with "number of samples" entries,
where each entry is a data frame where rows are observations and columns
are observed variables.
type="ymis"
: The posterior predictive distribution of missing
values conditioned on observed variables. Returns a matrix with
"number of samples" rows and "number of missing variables" columns.
Users may also wish to generate the posterior predictive distribution of
observed data, not conditioned on the latent variables. This
would often be viewed as data from new clusters (people) that were not
observed in the original dataset. For that, see sampleData()
.
## Not run:
data(HolzingerSwineford1939, package = "lavaan")
## fit model
HS.model <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 '
fit <- bcfa(HS.model, data = HolzingerSwineford1939, save.lvs = TRUE)
lapply(blavPredict(fit)[1:2], head) # first 6 rows of first 10 posterior samples
head(blavPredict(fit, type = "yhat")[[1]]) # top of first posterior sample
## multigroup models return a list of factor scores (one per group)
mgfit <- bcfa(HS.model, data = HolzingerSwineford1939, group = "school",
group.equal = c("loadings","intercepts"), save.lvs = TRUE)
lapply(blavPredict(fit)[1:2], head)
head(blavPredict(fit, type = "ypred")[[1]])
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.