View source: R/MeasurementYCat.R
MeasurementYCat | R Documentation |
Estimates a partial mediation model with multiple categorical indicator for the dependent variable
MeasurementYCat(Data,Prior,R)
Data |
list(X, M, y_star) |
Prior |
list(A_M,A_Y) |
R |
number of MCMC iterations, default = 10000 |
M = \beta_{0M} + X\beta_1 + U_M
(eq.1)
Y = \beta_{0Y} + M\beta_2 + X\beta_3 + U_Y
(eq.2)
y^*_1 = Y + U_{y^*_1}
\tilde{y}_1 = OrdProbit(y^*_1 ,C_{y_1})
y^*_2 = \tau_{20} + Y + U_{y^*_2}
\tilde{y}_2 = OrdProbit(y^*_2 ,C_{y_2})
...
y^*_L = \tau_{L0} + Y + U_{y^*_L}
\tilde{y}_L = OrdProbit(y^*_L ,C_{y_L})
\beta_{0M}
\sim
N(0,100), \beta_{0Y}
\sim
N(0,100)
\beta_1
\sim
N(0,100), \beta_2
\sim
N(0,100), \beta_3
\sim
N(0,1)
\sigma^2_M
\sim
Inv\chi^2(\nu,\nu S)
, where \nu=1
and S=3.
\tau_{20}, ..., \tau_{L0}
\sim
N(0,100)
\sigma^2_{y*_1}, ..., \sigma^2_{y*_L}
\sim
Inv\chi^2(\nu,\nu S)
C*_{y_1}, ..., C*_{y_L}
\sim
N(0,I)
Note: C*_{y_1}, ..., C*_{y_L}
are untransformed
cutoffs, which are then exponentially transformed to impose sign and order constraint on them. Subjective prior values for the error variances are \nu=1
, S=3.
Data = list(X, M, y_star)
treatment variable vector
mediator vector
dependent variable indicators' matrix
Prior = list(A_M,A_Y)
[optional]vector of coefficients' prior variances of eq.1, default = rep(100,2)
vector of coefficients' prior variances of eq.2, default = c(100,100,1)
matrix of eq.1 coefficients' draws
matrix of eq.2 coefficients' draws
array of indicator coefficients' draws. Each slice is one draw, where rows represent the indicator equation and columns the coefficients. All Slope coefficients as well as intercept of the first equation are fixed to 1 and 0 respectively.
Matrix of indicator equations' coefficients' error variance draws
vector of eq.1 error variance draws
array of discretized dependent variable indicators' cutoff values.
Matrix of the augmented latent dependent variable
vector of means indexing MCMC draws of the direct effect (used in BFSD to compute Bayes factor)
vector of variance indexing MCMC draws of the direct effect (used in BFSD to compute Bayes factor)
set.seed(60)
SimMeasurementYCat = function(X, beta_M, beta_Y, sigma_M, cutoff_Y, Y_ind, tau, ssq_y_star){
nobs = dim(X)[1]
y_tilde = y_star = matrix(double(nobs*Y_ind), ncol = Y_ind)
M = beta_M[1] + beta_M[2] * X + rnorm(nobs) * sigma_M
Y = beta_Y[1] + beta_Y[2] * M + beta_Y[3] * X + rnorm(nobs)
for(i in 1: Y_ind){
y_star[,i] = tau[i] + Y + sqrt(ssq_y_star[i])*rnorm(nobs);
y_tilde[,i] = cut(y_star[,i], br = cutoff_Y[i,], right=TRUE, include.lowest = TRUE, labels = FALSE)
}
return(list(Y = Y, M = M, y_tilde = y_tilde, X = X,
beta_M = beta_M,
k_Y=dim(cutoff_Y)[2]-1, beta_Y = beta_Y, tau = tau,
ssq_y_star = ssq_y_star, y_star = y_star, cutoff_Y = cutoff_Y,
Y_ind=Y_ind))
}
Y_ind = 2
Ycut = 8
nobs = 1000
X=as.matrix(runif(nobs,min=0, max=1))
beta_M = c(.5,1)
beta_Y = c(1, 4, 2)
sigma_M = 1^.5
ssq_y_star = c(.5,.7)
tau = c(0,-.5) #first intercept should always be 0
cutoff_Y = matrix(c(-100, 0, 1.6, 2, 2.2, 3.3, 6, 100,
-100, 0, 1, 2, 3, 4, 5, 100) ,ncol= Ycut, byrow = TRUE)
DataYCat = SimMeasurementYCat(X, beta_M, beta_Y, sigma_M, cutoff_Y, Y_ind, tau, ssq_y_star)
#estimation
A_M = c(100,100); #Prior variance for beta_0M, beta_1
A_Y = c(100,100,1) #Prior variance for beta_0Y, beta_2, beta_3
Prior = list(A_M = A_M, A_Y = A_Y)
Ycut = max(as.matrix(DataYCat$y_tilde)[,1]) +1
Data = list(X=cbind(rep(1,length(DataYCat$X)),DataYCat$M,DataYCat$X), y = as.matrix(DataYCat$y_tilde),
k=Ycut-1, Y_ind=dim(as.matrix(DataYCat$y_tilde))[2])
out = MeasurementYCat(Data=Data, Prior=Prior, R=10000)
#results
colMeans(out$beta_M)
colMeans(out$beta_Y)
apply(out$cutoff_Y,c(1,2),FUN = mean)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.