楼主: azheforever
9843 37

[问答] 急!!求解关于winbugs软件怎么运用矩阵正态分布的问题 [推广有奖]

21
epoh 发表于 2011-7-11 10:45:21
zhangtao
FGARCHPROC.prg 修改如下即可运行
1. startvalues={0.01,0.01,0.01,0.01};

   /*{b,f,g,vcv,ret,hhat}=FIGARCH11(x,0.2 1 2 3 1 1)*/


   {b,f,g,vcv,ret,hhat}=figarch11(x,startvalues);


2. /* __output=0;*/

   output file = figarch.out reset;


3.你的数据长度是459

   所以proc figarch11_loglike(x,e);


   proc figarch11_hhat(x,e);


   t
必须配合修改为459(原作者数据长度1000)


4.修改后FGARCHPROC.prg,结果figarch.out如下:


   FIGARCH11_proc.rar (2.19 KB)
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
zhangtao + 5 + 5 + 5 致以最最最崇高的敬意和谢意!!!

总评分: 学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

22
zhangtao 发表于 2011-7-11 11:44:35
非常感谢,深切感受到相互帮助的感动!
也感受到Gauss确实是非常好的语言!
数学好就是要天天学

23
epoh 发表于 2011-7-11 15:53:00
刚看了楼主的方程
应该可以考虑用
R Package `bayesm'
function rhierLinearModel()
   implements a Gibbs Sampler for hierarchical linear models
   with a normal prior.

# Model:
# nreg regression equations
#        y_i = X_ibeta_i + epsilon_i  
#        epsilon_i ~ N(0,tau_i)
#             nvar X vars in each equation
#
# Priors:
#        tau_i ~ nu.e*ssq_i/chisq(nu.e)  tau_i is the variance of epsilon_i
#        beta_i ~ N(ZDelta[i,],V_beta)
#               Note:  ZDelta is the matrix Z * Delta; [i,] refers to ith row of this product!
#
#          vec(Delta) | V_beta ~ N(vec(Deltabar),Vbeta (x) A^-1)
#          V_beta ~ IW(nu,V)  or V_beta^-1 ~ W(nu,V^-1)
#              Delta, Deltabar are nz x nvar
#              A is nz x nz
#              Vbeta is nvar x nvar
#        
#          NOTE: if you don't have any z vars, set Z=iota (nreg x 1)


详细数学式子请看
   http://hosho.ees.hokudai.ac.jp/~ ... ierLinearModel.html
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
zhangtao + 5 + 5 + 5 好的意见建议

总评分: 学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

24
zhangtao 发表于 2011-7-11 22:16:57
23# epoh
epoh老师,您的建议很好!但是在您提供的链接上没有
bayesm包?
数学好就是要天天学

25
epoh 发表于 2011-7-12 09:16:04
Package :‘bayesm’
Title :Bayesian Inference for Marketing/Micro-econometrics
Author: Peter Rossi.
下载bayesm_2.2-4.zip 由本机安装
  http://cran.r-project.org/web/packages/bayesm/index.html

要效果加倍,当然是参考Peter Rossi.的书籍
Bayesian Statistics and Marketing
  https://bbs.pinggu.org/thread-824880-1-1.html
已有 2 人评分学术水平 热心指数 信用等级 收起 理由
zhangtao + 5 + 5 + 5 好的意见建议
ywh19860616 + 5 + 5 + 5 呵呵,我现在老师研究贝叶斯的,可惜我不懂

总评分: 学术水平 + 10  热心指数 + 10  信用等级 + 10   查看全部评分

26
zhangtao 发表于 2011-7-12 15:53:51
25# epoh
epoh老师,我这几年对几个概念理解不好,如果您对这方面了解的话,想请教您讲一讲:
1、金融和时间序列计量中的“谱分析”和“谱密度”函数的思想是什么?有什么用?有什么优势?
2、什么是“鞅差分序列”?
3、griddy-gibbs抽样和传统的gibbs抽样有什么区别和联系?
非常感谢!
数学好就是要天天学

27
epoh 发表于 2011-7-12 19:06:17
依题意及数据
应该是nreg=4; nobs=10; nvar=8
不过楼主给的x数据不足
所以我修改数据并改为
nreg=3; nobs=10; nvar=3

#############
library(bayesm)
R=10
nreg=3; nobs=10; nvar=3
Z=cbind(c(rep(1,nreg)),3*runif(nreg)); Z[,2]=Z[,2]-mean(Z[,2])
x = structure(.Data = c(1,2,3,4,5,6,7,8,3,5,4,3,6,7,1,2,2,2,5,2,4,3,2,3,
                        2,7,4,3,2,7,5,2,3,5,2,5,6,5,3,2,1,2,3,4,7,5,4,1,
                        2,3,4,2,2,3,7,1,1,4,2,7,5,4,2,6,2,3,7,5,4,3,2,4,
                        2,1,3,4,2,4,5,2,2,7,4,3,2,7,2,3,4,2),.Dim=c(10,3,3))

y=structure(.Data=c(1,1,1,1,1,2,1,2,2,0,0,1,1,0,0,0,0,2,1,1,2,1,1,0,1,0,1,1,1,1),.Dim = c(10,3))

iota=c(rep(1,nobs))
regdata=NULL
for (reg in 1:3) {
X=cbind(iota,x[,,reg])
Y=y[,reg]
regdata[[reg]]=list(y=Y,X=X) }
Data1=list(regdata=regdata,Z=Z)
Mcmc1=list(R=R,keep=1)
out=rhierLinearModel(Data=Data1,Mcmc=Mcmc1)

##########
out
Starting Gibbs Sampler for Linear Hierarchical Model
    3  Regressions
    2  Variables in Z (if 1, then only intercept)

Prior Parms:
Deltabar
     [,1] [,2] [,3] [,4]
[1,]    0    0    0    0
[2,]    0    0    0    0
A
     [,1] [,2]
[1,] 0.01 0.00
[2,] 0.00 0.01
nu.e (d.f. parm for regression error variances)=  3
Vbeta ~ IW(nu,V)
nu =  7
V
     [,1] [,2] [,3] [,4]
[1,]    7    0    0    0
[2,]    0    7    0    0
[3,]    0    0    7    0
[4,]    0    0    0    7

MCMC parms:
R=  10  keep=  1

MCMC Iteration (est time to end - min)
  Total Time Elapsed:  0

> names(out)
[1] "Vbetadraw" "Deltadraw" "betadraw"  "taudraw"
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
zhangtao + 5 + 5 + 5 精彩帖子

总评分: 学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

28
epoh 发表于 2011-7-12 22:21:03
zhangtao 兄
griddy-gibbs抽样和传统的gibbs抽样有什么区别
这个答案可在Analysis of Financial Time Series_2ed找到

Analysis of Financial Time Series_2ed
chap12 Markov Chain Monte Carlo Methods with Applications
page 577/638
12.4.3 Griddy Gibbs
1. In financial applications, model may contain some nonlinear parameters
      (e.g., the moving-average parameters in an ARMA model or
       the GARCH parameters in a volatility model)
2. nonlinear parameters do not have a closed-form expression,
     implementing a Gibbs sampler in this situation may become complicated
3. Tanner (1996) describes a simple procedure to obtain random
    draws in a Gibbs sampling when the conditional posterior distribution
    is univariate.
4. The method is called the Griddy Gibbs sampler and is widely applicable
5 .However, the method could be inefficient in a real application

详细的 Griddy Gibbs Algorithm
请参考page 553/638
范例请参考 Example 12.3.GARCH(1,1)
ht is drawn by using the Griddy Gibbs with 500 grid points ,
and the range of ht is (0, 1.5s^2),where s^2 is the
sample variance of the log return rt

可惜没有S-PLIU SOURCE CODE
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
zhangtao + 5 + 5 + 5 非常感谢epoh大师的帮助! 这个griddy-gibbs sampler太前

总评分: 学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

29
zhangtao 发表于 2011-7-13 08:50:35
我曾经学习北大何书元教授的《应用时间序列分析》和
华东师大茆师松教授的〈高等数理统计〉等书,就是实在弄不明白
“谱分析”、“谱密度函数”、谱密度核函数、谱密度极大似然估计、最大熵谱估计、还有
Fisher信息阵是怎么来的?有什么用?思想是什么?
在baidu and google上也做过搜索,在人大论坛上也发过帖子,
但是也没人知道,但是这些东西不清楚。
数学好就是要天天学

30
epoh 发表于 2011-7-13 10:25:30
Fisher information matrix
可以利用matlab ecmnfish.m算出

%%%%%%%%%%
ecmnfish
  Fisher information matrix
  Fisher = ecmnfish(Data, Covariance, InvCovariance, MatrixFormat)

Arguments:

  Data: NUMSAMPLES-by-NUMSERIES matrix of observed multivariate normal data
  Covariance :NUMSERIES-by-NUMSERIES matrix with covariance estimate of Data
  InvCovariance:(Optional) Inverse of covariance matrix: inv(Covariance)

%%%%%%%%
matlab Command Window
>> ecmguidemo

这是matlab 自动产生

3 series
60 observations
0% missing data


比较用Hessian 及 Fisher information matrix的结果


   Mean(Hessian)      Std.Dev(Hessian)        Mean(Fisher)       Std.Dev(Fisher)
0.023355856212147877 0.005975609497120777 0.02335585621214785  0.005975609497120777
0.03739210439061549  0.013830706723727054 0.033608644398810866 0.012373501469109024
0.053544968623126306 0.031212803971525954 0.05267961862804869  0.03040015987039729


%%%%%%%%
不知zhangtao兄所谓的谱分析
谈的是否底下的内容
我的理解是假设你的数据属cycle的话
通常会使用Spectral Analysis
这在Time series analysis and its applications with R examples _2ed
chap 4 Spectral Analysis and Filtering
都有详细讨论到
4.3 The Spectral Density
4.4 Periodogramand Discrete Fourier Transform
4.5 Nonparametric Spectral Estimation
4.8 Parametric Spectral Estimation
请先行参考.

############
martingale difference sequence:

个人认为看完底下这份教材
page 1,2 的定义及举例garch(1,1)
应该不难理解.
   http://www.ssc.wisc.edu/~bhansen/718/NonParametrics13.pdf


Simple time series models are built using fundamental "“shocks”et";
typically normalized so that Eet = 0:
(1) The most basic shock et is iid.
(2) Martingale Difference Sequence (MDS). et is a MDS if E (et |et-1,et-2,..) = 0
    it is a serially uncorrelated (but not necessarily an independent) process
(3) White noise. If E(et)(et-h) = 0 for all h>=1

   
     iid > MDS > White noise

An iid shock is a MDS,a MDS is white noise, but the reverse is not true.
An iid shock is unpredictable. A MDS is unpredictable in the mean.


已有 2 人评分学术水平 热心指数 信用等级 收起 理由
southmm + 1 + 1 + 1 精彩帖子
zhangtao + 5 + 5 + 5 看了您推荐的书基本明白了!

总评分: 学术水平 + 6  热心指数 + 6  信用等级 + 6   查看全部评分

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-2-2 02:47