
Last chance! 50% off unlimited learning
Sale ends in
Function that draws samples from the LM model for continuous outcomes with individual covariates with specific parameters. The function is no longer maintained. Please look at drawLMlatentcont
function.
draw_lm_cov_latent_cont(X1, X2, param = "multilogit", Mu, Si, Be, Ga, fort = TRUE)
desing matrix for the covariates on the initial probabilities (n x nc1)
desing matrix for the covariates on the transition probabilities (n x TT-1 x nc2)
type of parametrization for the transition probabilities ("multilogit" = standard multinomial logit for every row of the transition matrix, "difflogit" = multinomial logit based on the difference between two sets of parameters)
array of conditional means for the response variables (r x k)
var-cov matrix common to all states (r x r)
parameters affecting the logit for the initial probabilities
parametes affecting the logit for the transition probabilities
to use fortran routine when possible (FALSE for not use fortran)
array of continuous outcomes (n x TT x r)
matrix containing the sequence of latent states (n x TT)
# NOT RUN {
# draw a sample for 1000 units, 10 response variable and 2 covariates
n <- 1000
TT <- 5
k <- 2
nc <- 2 #number of covariates
r <- 3 #number of response variables
fort <- TRUE
Mu <- matrix(c(-2,-2,0,0,2,2), r, k)
Si <- diag(r)
Ga <- matrix(c(-log(0.9/0.1),0.5,1), (nc+1)*(k-1), k)
Be <- array(c(0,0.5,1), (nc+1)*(k-1))
#Simulate covariates
X1 <- matrix(0, n, nc)
for(j in 1:nc) X1[,j] <- rnorm(n)
X2 <- array(0, c(n,TT-1,nc))
for (t in 1:(TT-1)) for(j in 1:nc){
if(t==1){
X2[,t,j] <- 0.5*X1[,j] + rnorm(n)
}else{
X2[,t,j] <- 0.5*X2[,t-1,j] + rnorm(n)
}
}
out <- draw_lm_cov_latent_cont(X1, X2, param = "multilogit", Mu, Si, Be, Ga, fort = fort)
# }
Run the code above in your browser using DataLab