View source: R/dirichlet.simul.R
dirichlet.simul | R Documentation |
This function makes random draws from a Dirichlet distribution.
dirichlet.simul(alpha)
alpha |
A matrix with |
A data frame with Dirichlet distributed responses
#############################################################################
# EXAMPLE 1: Simulation with two components
#############################################################################
set.seed(789)
N <- 2000
probs <- c(.7, .3) # define (extremal) class probabilities
#*** alpha0=.2 -> nearly crisp latent classes
alpha0 <- .2
alpha <- alpha0*probs
alpha <- matrix( alpha, nrow=N, ncol=length(alpha), byrow=TRUE )
x <- sirt::dirichlet.simul( alpha )
htitle <- expression(paste( alpha[0], "=.2, ", p[1], "=.7" ) )
hist( x[,1], breaks=seq(0,1,len=20), main=htitle)
#*** alpha0=3 -> strong deviation from crisp membership
alpha0 <- 3
alpha <- alpha0*probs
alpha <- matrix( alpha, nrow=N, ncol=length(alpha), byrow=TRUE )
x <- sirt::dirichlet.simul( alpha )
htitle <- expression(paste( alpha[0], "=3, ", p[1], "=.7" ) )
hist( x[,1], breaks=seq(0,1,len=20), main=htitle)
## Not run:
#############################################################################
# EXAMPLE 2: Simulation with three components
#############################################################################
set.seed(986)
N <- 2000
probs <- c( .5, .35, .15 )
#*** alpha0=.2
alpha0 <- .2
alpha <- alpha0*probs
alpha <- matrix( alpha, nrow=N, ncol=length(alpha), byrow=TRUE )
x <- sirt::dirichlet.simul( alpha )
htitle <- expression(paste( alpha[0], "=.2, ", p[1], "=.7" ) )
miceadds::library_install("ade4")
ade4::triangle.plot(x, label=NULL, clabel=1)
#*** alpha0=3
alpha0 <- 3
alpha <- alpha0*probs
alpha <- matrix( alpha, nrow=N, ncol=length(alpha), byrow=TRUE )
x <- sirt::dirichlet.simul( alpha )
htitle <- expression(paste( alpha[0], "=3, ", p[1], "=.7" ) )
ade4::triangle.plot(x, label=NULL, clabel=1)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.