Description Usage Arguments Value Examples
This function prepares data for analysis using Stan factor analysis code.
1 |
data |
N by P data matrix. |
nfactors |
Number of factors to extract. |
Prior |
Prior loading matrix. |
Returns a formatted data file for use with Stan MCMC sampler.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.