prep {brxx} | R Documentation |
prep: Prepare Data File for Bayesian Analysis
Description
This function prepares data for analysis using Stan factor analysis code.
Usage
prep(data, nfactors, Prior)
Arguments
data |
N by P data matrix. |
nfactors |
Number of factors to extract. |
Prior |
Prior loading matrix. |
Value
Returns a formatted data file for use with Stan MCMC sampler.
Examples
set.seed(999)
your_data=data.frame(mvrnorm(n=20,mu=c(0,0,0,0,0),
Sigma=matrix(c(4,2,2,2,2,
2,4,2,2,2,
2,2,4,2,2,
2,2,2,4,2,
2,2,2,2,4),
nrow=5, ncol=5)))
colnames(your_data)=c("x1","x2","x3","x4","x5")
your_data_miss=matrix(ncol=5,nrow=20)
for (i in 1:20){
for (p in 1:5){
your_data_miss[i,p]=ifelse(runif(1,0,1)<0.2,NA,your_data[i,p])
}
}
formatted_data=prep(your_data_miss,nfactors=3)
[Package brxx version 0.1.2 Index]