[R] 回复: Bayesian Hidden Markov Models

2012-03-02 Thread monkeylan
Dear Oscar,
 
Thanks for your help.It's so nice of you to explain this package to me.
 
Best Regards,
 
James LAN

发件人: Oscar Rueda [via R] 
收件人: monkeylan  
发送日期: 2012年2月29日, 星期三, 下午 9:21
主题: Re: Bayesian Hidden Markov Models


Dear James, 

The distances are normalized between zero and 1, so in your case all of them 
will be zero. You can check that with 

> res$Dist.for.model 

And do 

> Q.NH(summary(res)[[1]]$beta, x=0) 

To obtain the common transition matrix. 

Cheers, 
Oscar 


On 29/2/12 03:59, "monkeylan" <[hidden email]> wrote: 


> Dear Oscar, 
>   
> I am extremely grateful to your help and detailed explanation of the use of 
> RJaCGH package. 
> But, when runing the sample codes you listed, another issue I am a little 
> confused is as following: 
> After runing summary(res), I have got the estimation of the random matrix 
> Beta: 
> 
> Parameters of the transition functions: 
>        Normal  Gain 
> Normal  0.000 4.258 
> Gain    2.001 0.000 
>   
> But, the transition probabilty matrix Q based on the aboving Beta is more 
> concerned in my modeling. 
> Here, I am not sure how can I get the  matrix Q. I did try the Q.NH 
> functions.However, Shoud I set the distance parameter x be 1 or 0? I am not 
> sure. 
>   
>  If 1( according to my own understanding), the following result seems not 
> reseanable. 
>   
> tran<-matrix(c(0,2.001,4.528,0),2,2) 
> Q.NH(beta=tran, x=1) 
>      [,1] [,2] 
> [1,]  0.5  0.5 
> [2,]  0.5  0.5 
>   
> Many thanks for your further help and time. 
>   
> James Allan 
> 
> --- 12年2月28日,周二, Oscar Rueda [via R] 
> <[hidden email]> 写道: 
> 
> 
> 发件人: Oscar Rueda [via R] <[hidden email]> 
> 主题: Re: Bayesian Hidden Markov Models 
> 收件人: "monkeylan" <[hidden email]> 
> 日期: 2012年2月28日,周二,下午7:02 
> 
> 
> Dear James, 
> 
> Basically you just need the values (y) and the positions (in your case it 
> would be the index of the times series). The chromosome argument does not 
> apply to your case so it can be a vector of ones. 
> If the positions are at the same distance between (equally spaced) then the 
> model will be homogeneous. 
> 
> So for example something like this would be enough: 
>> library(RJaCGH) 
>> y <- c(rnorm(100,0,1), rnorm(20, 2, 1), rnorm(50, 0, 1)) 
>> Pos <- 1:length(y) 
>> Chrom <- rep(1, length(y)) 
>> res <- RJaCGH(y=y, Pos=Pos, Chrom=Chrom) 
>> summary(res) 
> 
> However, it uses a Reversible Jump algorithm and therefore jumps between 
> models with different hidden states. I would suggest you take a look at the 
> vignette that comes with the package or the paper that is referenced there 
> for specific details of the model it fits. 
> 
> 
> Hope it helps, 
> Oscar 
>   
> 
> 
> On 28/2/12 04:52, "monkeylan" <[hidden email]> wrote: 
> 
> 
>> Dear Doctor Oscar, 
>>   
>> Sorry for not noticing that you are the author of the RJaCGH package. 
>> 
>> But I noticed that hidden Markov model in your package is with 
>> non-homogeneous 
>> transition probabilities. Here in my work, the HMM is just a first-order 
>> homogeneous Markov chain, i.e. the  transition  matrix is constant. 
>>   
>> So, Could you please tell me how can I adjust the R functions in your 
>> package 
>> to implement my analysis? 
>>   
>> Best Regards, 
>>   
>> James Allan 
>> 
>> 
>> --- 12年2月27日,周一, Oscar Rueda [via R] 
>> <[hidden email]> 写道: 
>> 
>> 
>> 发件人: Oscar Rueda [via R] <[hidden email]> 
>> 主题: Re: Bayesian Hidden Markov Models 
>> 收件人: "monkeylan" <[hidden email]> 
>> 日期: 2012年2月27日,周一,下午6:05 
>> 
>> 
>> Dear James, 
>> Although designed for the analysis of copy number CGH microarrays, RJaCGH 
>> uses a Bayesian HMM model. 
>> 
>> Cheers, 
>> Oscar 
>> 
>> 
>> On 27/2/12 08:32, "monkeylan" <[hidden email]> wrote: 
>> 
>> 
>>> Dear R buddies, 
>>> 
>>> Recently, I attempt to model the US/RMB Exchange rate log-return time 
>>> series 
>>> with a *Hidden Markov model (first order Markov Chain & mixed Normal 
>>> distributions). * 
>>> 
>>> I have applied the RHmm package to accomplish this task, but the results 
>>> are 
>>> not so satisfying. 
>>> So, I would like to try a *Bayesian method *for the p

[R] 回复: Bayesian Hidden Markov Models

2012-03-02 Thread monkeylan
Dear Oscar,
 
I have used the the following codes to perform a Bayesian HMM for the exchange 
rate data.
But, one intresting result is that the model fits a 6-state HMM with a common 
variance.
This is very hard to understand. Because, from the plot graph, we could see 
there are obviously differents with high and low volatility.
 
So, could you please help me to take a look at this? Attached is the exchange 
rate data.
I am really grateful for your help and time.
 
Best Regards,
 
James LAN
 
 
#input exchange rate data
exrt<-read.table(file="exrt.txt",header=F)
plot(exrt$V2)
library(RJaCGH) 
y<-exrt$V2
Pos<- 1:length(y) 
Chrom <- rep(1, length(y)) 
res<-RJaCGH(y=y, Pos=Pos, Chrom=Chrom)
summary(res)
Q.NH(summary(res)[[1]]$beta, x=0)
Summary for ARRAY  array1:
Distribution of the number of hidden states:
1 2 3 4 5 6 
0 0 0 0 0 1 
Model with  6  states:
Distribution of the posterior means of hidden states:
            10%    25%    50%    75%    90%
Loss-1   -0.298 -0.284 -0.284 -0.279 -0.279
Loss-2   -0.144 -0.142 -0.142 -0.135 -0.135
Normal-1 -0.045 -0.043 -0.043 -0.040 -0.040
Normal-2 -0.004 -0.003 -0.003  0.000  0.000
Normal-3  0.047  0.056  0.056  0.059  0.059
Gain      0.177  0.197  0.197  0.198  0.198
Distribution of the posterior variances of hidden states:
           10%   25%   50%   75%   90%
Loss-1   0.001 0.001 0.001 0.001 0.001
Loss-2   0.001 0.001 0.001 0.001 0.001
Normal-1 0.001 0.001 0.001 0.001 0.001
Normal-2 0.001 0.001 0.001 0.001 0.001
Normal-3 0.001 0.001 0.001 0.001 0.001
Gain     0.001 0.001 0.001 0.001 0.001
Parameters of the transition functions:
         Loss-1 Loss-2 Normal-1 Normal-2 Normal-3  Gain
Loss-1    0.000  0.217    0.192    1.229    0.185 0.857
Loss-2    2.104  0.000    0.305    2.190    0.132 1.424
Normal-1  2.728  1.472    0.000    4.606    0.293 2.423
Normal-2  5.919  4.746    5.518    0.000    5.067 5.834
Normal-3  2.295  0.537    0.115    4.329    0.000 2.514
Gain      1.519  0.247    0.036    1.263    0.132 0.000

> Q.NH(summary(res)[[1]]$beta, x=0)
              Loss-1      Loss-2    Normal-1    
Normal-2    Normal-3
Loss-1   0.239381248 0.192598942 0.197535790 0.070058386 0.198853168
Loss-2   0.039503637 0.323847484 0.238632024 0.036241348 0.283843424
Normal-1 0.030559504 0.107234801 0.467453369 0.004669696 0.348627295
Normal-2 0.002624349 0.008474303 0.003915585 0.975979222 0.006151494
Normal-3 0.037727330 0.218834862 0.333794793 0.004936521 0.374412381
Gain     0.053064705 0.189481114 0.233947328 0.068592117 0.212423356
                Gain
Loss-1   0.101572465
Loss-2   0.077932083
Normal-1 0.041455335
Normal-2 0.002855048
Normal-3 0.030294113
Gain     0.242491380


发件人: Oscar Rueda [via R] 
收件人: monkeylan  
发送日期: 2012年2月29日, 星期三, 下午 9:21
主题: Re: Bayesian Hidden Markov Models


Dear James, 

The distances are normalized between zero and 1, so in your case all of them 
will be zero. You can check that with 

> res$Dist.for.model 

And do 

> Q.NH(summary(res)[[1]]$beta, x=0) 

To obtain the common transition matrix. 

Cheers, 
Oscar 


On 29/2/12 03:59, "monkeylan" <[hidden email]> wrote: 


> Dear Oscar, 
>   
> I am extremely grateful to your help and detailed explanation of the use of 
> RJaCGH package. 
> But, when runing the sample codes you listed, another issue I am a little 
> confused is as following: 
> After runing summary(res), I have got the estimation of the random matrix 
> Beta: 
> 
> Parameters of the transition functions: 
>        Normal  Gain 
> Normal  0.000 4.258 
> Gain    2.001 0.000 
>   
> But, the transition probabilty matrix Q based on the aboving Beta is more 
> concerned in my modeling. 
> Here, I am not sure how can I get the  matrix Q. I did try the Q.NH 
> functions.However, Shoud I set the distance parameter x be 1 or 0? I am not 
> sure. 
>   
>  If 1( according to my own understanding), the following result seems not 
> reseanable. 
>   
> tran<-matrix(c(0,2.001,4.528,0),2,2) 
> Q.NH(beta=tran, x=1) 
>      [,1] [,2] 
> [1,]  0.5  0.5 
> [2,]  0.5  0.5 
>   
> Many thanks for your further help and time. 
>   
> James Allan 
> 
> --- 12年2月28日,周二, Oscar Rueda [via R] 
> <[hidden email]> 写道: 
> 
> 
> 发件人: Oscar Rueda [via R] <[hidden email]> 
> 主题: Re: Bayesian Hidden Markov Models 
> 收件人: "monkeylan" <[hidden email]> 
> 日期: 2012年2月28日,周二,下午7:02 
> 
> 
> Dear James, 
> 
> Basically you just need the values (y) and the positions (i

[R] Bayesian Hidden Markov Models

2012-02-27 Thread monkeylan
Dear R buddies,

Recently, I attempt to model the US/RMB Exchange rate log-return time series
with a *Hidden Markov model (first order Markov Chain & mixed Normal
distributions). *

I have applied the RHmm package to accomplish this task, but the results are
not so satisfying.
So, I would like to try a *Bayesian method *for the parameter estimation of
the Hidden Markov model.

Could anyone kindly tell me which R package can perform Bayesian estimation
of the model?

Many thanks for your help and time.

Best Regards,
James Allan 


--
View this message in context: 
http://r.789695.n4.nabble.com/Bayesian-Hidden-Markov-Models-tp4423946p4423946.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Bayesian Hidden Markov Models

2012-02-27 Thread monkeylan
Dear Oscar,
 
I really appreciate your help for my problem. I have taken a look at the R 
package RJaCGH you mentioned roughly, but I am really a little confused by the 
CGH microarrays background of the package. Actually, I am a graduate student, 
majoring Mathematical Statistics. So, I know nothing about the CGH microarrays. 
 
Have you ever used the RJaCGH package before? If so, could you please briefly 
tell me how to use RJaCGH to implement a Bayesian Hidden Markov Models for my 
univariate time series? 
 
Thanks again for your patience and time.
 
Best Regards,
 
James Allan
 

--- 12年2月27日,周一, Oscar Rueda [via R] 
 写道:


发件人: Oscar Rueda [via R] 
主题: Re: Bayesian Hidden Markov Models
收件人: "monkeylan" 
日期: 2012年2月27日,周一,下午6:05


Dear James, 
Although designed for the analysis of copy number CGH microarrays, RJaCGH 
uses a Bayesian HMM model. 

Cheers, 
Oscar 


On 27/2/12 08:32, "monkeylan" <[hidden email]> wrote: 


> Dear R buddies, 
> 
> Recently, I attempt to model the US/RMB Exchange rate log-return time series 
> with a *Hidden Markov model (first order Markov Chain & mixed Normal 
> distributions). * 
> 
> I have applied the RHmm package to accomplish this task, but the results are 
> not so satisfying. 
> So, I would like to try a *Bayesian method *for the parameter estimation of 
> the Hidden Markov model. 
> 
> Could anyone kindly tell me which R package can perform Bayesian estimation 
> of the model? 
> 
> Many thanks for your help and time. 
> 
> Best Regards, 
> James Allan 
> 
> 
> -- 
> View this message in context: 
> http://r.789695.n4.nabble.com/Bayesian-Hidden-Markov-Models-tp4423946p4423946.
>  
> html 
> Sent from the R help mailing list archive at Nabble.com. 
> 
> __ 
> [hidden email] mailing list 
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code. 
Oscar M. Rueda, PhD. 
Postdoctoral Research Fellow, Breast Cancer Functional Genomics. 
Cancer Research UK Cambridge Research Institute. 
Li Ka Shing Centre, Robinson Way. 
Cambridge CB2 0RE 
England 




NOTICE AND DISCLAIMER 
This e-mail (including any attachments) is intended for ...{{dropped:16}} 

__ 
[hidden email] mailing list 
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code. 






If you reply to this email, your message will be added to the discussion 
below:http://r.789695.n4.nabble.com/Bayesian-Hidden-Markov-Models-tp4423946p4424152.html
 
To unsubscribe from Bayesian Hidden Markov Models, click here.
NAML

--
View this message in context: 
http://r.789695.n4.nabble.com/Bayesian-Hidden-Markov-Models-tp4423946p4426601.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Bayesian Hidden Markov Models

2012-02-27 Thread monkeylan
Dear Doctor Oscar,
 
Sorry for not noticing that you are the author of the RJaCGH package.

But I noticed that hidden Markov model in your package is with non-homogeneous 
transition probabilities. Here in my work, the HMM is just a first-order 
homogeneous Markov chain, i.e. the  transition  matrix is constant. 
 
So, Could you please tell me how can I adjust the R functions in your package 
to implement my analysis?
 
Best Regards,
 
James Allan


--- 12年2月27日,周一, Oscar Rueda [via R] 
 写道:


发件人: Oscar Rueda [via R] 
主题: Re: Bayesian Hidden Markov Models
收件人: "monkeylan" 
日期: 2012年2月27日,周一,下午6:05


Dear James, 
Although designed for the analysis of copy number CGH microarrays, RJaCGH 
uses a Bayesian HMM model. 

Cheers, 
Oscar 


On 27/2/12 08:32, "monkeylan" <[hidden email]> wrote: 


> Dear R buddies, 
> 
> Recently, I attempt to model the US/RMB Exchange rate log-return time series 
> with a *Hidden Markov model (first order Markov Chain & mixed Normal 
> distributions). * 
> 
> I have applied the RHmm package to accomplish this task, but the results are 
> not so satisfying. 
> So, I would like to try a *Bayesian method *for the parameter estimation of 
> the Hidden Markov model. 
> 
> Could anyone kindly tell me which R package can perform Bayesian estimation 
> of the model? 
> 
> Many thanks for your help and time. 
> 
> Best Regards, 
> James Allan 
> 
> 
> -- 
> View this message in context: 
> http://r.789695.n4.nabble.com/Bayesian-Hidden-Markov-Models-tp4423946p4423946.
>  
> html 
> Sent from the R help mailing list archive at Nabble.com. 
> 
> __ 
> [hidden email] mailing list 
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code. 
Oscar M. Rueda, PhD. 
Postdoctoral Research Fellow, Breast Cancer Functional Genomics. 
Cancer Research UK Cambridge Research Institute. 
Li Ka Shing Centre, Robinson Way. 
Cambridge CB2 0RE 
England 




NOTICE AND DISCLAIMER 
This e-mail (including any attachments) is intended for ...{{dropped:16}} 

__ 
[hidden email] mailing list 
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code. 






If you reply to this email, your message will be added to the discussion 
below:http://r.789695.n4.nabble.com/Bayesian-Hidden-Markov-Models-tp4423946p4424152.html
 
To unsubscribe from Bayesian Hidden Markov Models, click here.
NAML

--
View this message in context: 
http://r.789695.n4.nabble.com/Bayesian-Hidden-Markov-Models-tp4423946p4427000.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Bayesian Hidden Markov Models

2012-02-28 Thread monkeylan
Dear Oscar,
 
I am extremely grateful to your help and detailed explanation of the use of 
RJaCGH package.
But, when runing the sample codes you listed, another issue I am a little 
confused is as following:
After runing summary(res), I have got the estimation of the random matrix Beta:

Parameters of the transition functions:
       Normal  Gain
Normal  0.000 4.258
Gain    2.001 0.000
 
But, the transition probabilty matrix Q based on the aboving Beta is more 
concerned in my modeling. 
Here, I am not sure how can I get the  matrix Q. I did try the Q.NH 
functions.However, Shoud I set the distance parameter x be 1 or 0? I am not 
sure.
 
 If 1( according to my own understanding), the following result seems not 
reseanable.
 
tran<-matrix(c(0,2.001,4.528,0),2,2)
Q.NH(beta=tran, x=1)
     [,1] [,2]
[1,]  0.5  0.5
[2,]  0.5  0.5
 
Many thanks for your further help and time.
 
James Allan

--- 12年2月28日,周二, Oscar Rueda [via R] 
 写道:


发件人: Oscar Rueda [via R] 
主题: Re: Bayesian Hidden Markov Models
收件人: "monkeylan" 
日期: 2012年2月28日,周二,下午7:02


Dear James, 

Basically you just need the values (y) and the positions (in your case it 
would be the index of the times series). The chromosome argument does not 
apply to your case so it can be a vector of ones. 
If the positions are at the same distance between (equally spaced) then the 
model will be homogeneous. 

So for example something like this would be enough: 
> library(RJaCGH) 
> y <- c(rnorm(100,0,1), rnorm(20, 2, 1), rnorm(50, 0, 1)) 
> Pos <- 1:length(y) 
> Chrom <- rep(1, length(y)) 
> res <- RJaCGH(y=y, Pos=Pos, Chrom=Chrom) 
> summary(res) 

However, it uses a Reversible Jump algorithm and therefore jumps between 
models with different hidden states. I would suggest you take a look at the 
vignette that comes with the package or the paper that is referenced there 
for specific details of the model it fits. 


Hope it helps, 
Oscar 
  


On 28/2/12 04:52, "monkeylan" <[hidden email]> wrote: 


> Dear Doctor Oscar, 
>   
> Sorry for not noticing that you are the author of the RJaCGH package. 
> 
> But I noticed that hidden Markov model in your package is with 
> non-homogeneous 
> transition probabilities. Here in my work, the HMM is just a first-order 
> homogeneous Markov chain, i.e. the  transition  matrix is constant. 
>   
> So, Could you please tell me how can I adjust the R functions in your package 
> to implement my analysis? 
>   
> Best Regards, 
>   
> James Allan 
> 
> 
> --- 12年2月27日,周一, Oscar Rueda [via R] 
> <[hidden email]> 写道: 
> 
> 
> 发件人: Oscar Rueda [via R] <[hidden email]> 
> 主题: Re: Bayesian Hidden Markov Models 
> 收件人: "monkeylan" <[hidden email]> 
> 日期: 2012年2月27日,周一,下午6:05 
> 
> 
> Dear James, 
> Although designed for the analysis of copy number CGH microarrays, RJaCGH 
> uses a Bayesian HMM model. 
> 
> Cheers, 
> Oscar 
> 
> 
> On 27/2/12 08:32, "monkeylan" <[hidden email]> wrote: 
> 
> 
>> Dear R buddies, 
>> 
>> Recently, I attempt to model the US/RMB Exchange rate log-return time series 
>> with a *Hidden Markov model (first order Markov Chain & mixed Normal 
>> distributions). * 
>> 
>> I have applied the RHmm package to accomplish this task, but the results are 
>> not so satisfying. 
>> So, I would like to try a *Bayesian method *for the parameter estimation of 
>> the Hidden Markov model. 
>> 
>> Could anyone kindly tell me which R package can perform Bayesian estimation 
>> of the model? 
>> 
>> Many thanks for your help and time. 
>> 
>> Best Regards, 
>> James Allan 
>> 
>> 
>> -- 
>> View this message in context: 
>> http://r.789695.n4.nabble.com/Bayesian-Hidden-Markov-Models-tp4423946p4423946>>
>>  
. 

>> html 
>> Sent from the R help mailing list archive at Nabble.com. 
>> 
>> __ 
>> [hidden email] mailing list 
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code. 
> Oscar M. Rueda, PhD. 
> Postdoctoral Research Fellow, Breast Cancer Functional Genomics. 
> Cancer Research UK Cambridge Research Institute. 
> Li Ka Shing Centre, Robinson Way. 
> Cambridge CB2 0RE 
> England 
> 
> 
> 
> 
> NOTICE AND DISCLAIMER 
> This e-mail (including any attachments) is intended for ...{{dropped:16}} 
> 
> __