[R] Odp: error statement: missing value where TRUE/FALSE needed
Petr PIKAL
petr.pikal at precheza.cz
Tue Mar 24 15:52:15 CET 2009
Hi
r-help-bounces at r-project.org napsal dne 23.03.2009 15:38:49:
> Hi list,
>
> I want to try Gibbs sampling as a method of estimating a
markov-switching
> model of a mean-deviating, pth-order autoregressive process with time
> varying transition probabilities via R and am using a code originally
> written by another person; I attach the useful pdf document explaining
the
> code. When I run the code, I get an error message:
>
> Error in if (r < vQ[i]) { : missing value where TRUE/FALSE needed
>
> I am using R.2.6.0 on Windows XP. Can anyone tell me what the error
message
> means?
The error message means that there is missing value instead of logical
when you are calling if
> a<-NA
> b<-1
> a<b
[1] NA
> if(a<b) print("No.way")
Error in if (a < b) print("No.way") :
missing value where TRUE/FALSE needed
> a<-0
> if(a<b) print("No.way")
[1] "No.way"
So test r and vQ if they contain missing values or change your code
Besides, it looks like code written in Basic not in R
Few other comments
* read.table() already produce data frame
* This is really strange, I did not see such construction yet
> mG0 <-rbind(cbind(100,0,0,0), cbind(0,100,0,0), cbind(0,0,100,0),
cbind(0,0,0,100))
what about
> x<-matrix(0, 4,4)
> diag(x)<-100
> x
[,1] [,2] [,3] [,4]
[1,] 100 0 0 0
[2,] 0 100 0 0
[3,] 0 0 100 0
[4,] 0 0 0 100
* Better upgrade to 2.8.1, or maybe wait about a month for 2.9.0
* I do not think that somebody will go through whole your code, it is
terribly complicated.
Regards
Petr
>
>
> The specific line in the code is:
>
> if (r<vQ[i]){ vS[i]=0 } else vS[i]=1
>
> The code is available at:
> http://www.michael-curran.com/gibbs.html
> and the two data sets are available at:
> http://www.geocities.jp/atsmatsumoto/ci.txt
> and
> http://www.geocities.jp/atsmatsumoto/callrate.txt
>
> Note: I saved the first data set as ci.txt and the second as boj.txt and
so
> these are the file names that the code loads. If anyone uses the code
and
> the data and manages to get it to work, I would gratefully appreciate if
> they could tell me what adjustments they made to the code in order to do
> so.
>
> Kind regards,
>
> Michael
> --
> Michael Curran
> Candidate for the MPhil in Economics
> Cambridge University
> http://www.michael-curran.com/
>
>
>
> [příloha gibbsms-1.pdf odstraněna uživatelem Petr PIKAL/CTCAP]
> ______________________________________________
> R-help at 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.
More information about the R-help
mailing list