Zhiyong Zhang's Psychometric Website
 
Home Control Panel Login Register Search Submit Logout About me Contact me
My Research
Google
Web
This Site
Home > Codes for WinBUGS using Bayesian method to estimate Dynamic factor models
Codes for WinBUGS using Bayesian method to estimate Dynamic factor models
2006-11-17    Zhang, Z.       Read: 12871 times
Cite this page: Zhang, Z. (2006). Codes for WinBUGS using Bayesian method to estimate Dynamic factor models. Retrieved November 23, 2024, from https://www.psychstat.org/us/article.php/69.htm.
Codes for WinBUGS using Bayesian method to estimate Dynamic factor models

## Dynamic Factor Model
## Simulated 6v2f data with ar(1) factors
# DAFS model with AR(1)
model{
     # Model-relationship between observed variables and factors
     for (t in 1:T){
           for (p in 1:P){
                 y[t,p]~dnorm(mu[t,p],pre_e[p])
                }
           for (p in 1:3){
                 mu[t,p]<-lam[p]*f[t,1]
                 }
            for (p in 4:6){
                 mu[t,p]<-lam[p]*f[t,2]
                 }
           }

      ## Autoregression of factors
      for (t in 2:T){
           f[t,1:2]~dmnorm(muf[t,1:2],pre_v[1:2,1:2])
            muf[t,1]<-b[1]*f[t-1,1]+b[2]*f[t-1,2]
            muf[t,2]<-b[3]*f[t-1,1]+b[4]*f[t-1,2]
            }
        f[1,1:2]~dmnorm(muf[1,1:2], pre_v[1:2,1:2])
        muf[1,1]<-b[1]*f0[1]+b[2]*f0[2]
        muf[1,2]<-b[3]*f0[1]+b[4]*f0[2]
        f0[1]~dnorm(0,.0001)
        f0[2]~dnorm(0,.0001)
       
        pre_v[1:2,1:2]<-inverse(cov_v[1:2,1:2])
        cov_v[1,1]<-.36
        cov_v[2,2]<-.36
        cov_v[1,2]<-cov_v[2,1]
        cov_v[2,1]~dunif(0,1)
            
       ##Prior distribution
       for (p in 1:P){
           pre_e[p]~dgamma(.001,.001)

           }
       for (p in 1:6){
           lam[p]~dnorm(0,.001)}
       
        for (i in 1:4){
            b[i]~dnorm(0,.001)
            }
         
        for (p in 1:6){
           Par[p]<-lam[p]
           Par[6+p]<-1/pre_e[p]
          }
        for (i in 1:4){
           Par[12+i]<-b[i]
           }
        Par[17]<-cov_v[2,1]
}

starting values
list(b=c(.8,0,0,.8), pre_e=c(10,10,10,10,10,10), lam=c(1,1,1,1,1,1))

list( T=150, P=6, list(y = structure(.Data = c(
0.1748170693,0.6367873144,0.0248632848,-..., -1.867119034,-1.206459092,-0.615199296),
.Dim = c(150, 6)))

Submitted by: johnny
Add a comment View comment Add to my favorite Email to a friend Print
If you want to rate, please login first, or click here to register. Or you can use USERNAME: guest and PASSWORD: guest to log in.
Average score 0, based on 0 comments
1 2 3 4 5 6 7 8 9 10
Copyright © 2003-13 Zhiyong Zhang \'s Psychometric Website
Maintained by Zhiyong Zhang