Skip to content

error statement: missing value where TRUE/FALSE needed

3 messages · Michael Curran, jim holtman, PIKAL Petr

#
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 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
#
I would assume the expression in the 'if' is giving an NA as a result:
Error in if (NA) 1 else 2 : missing value where TRUE/FALSE needed

        
On Mon, Mar 23, 2009 at 10:38 AM, Michael Curran <mpc46 at cam.ac.uk> wrote:

  
    
#
Hi


r-help-bounces at r-project.org napsal dne 23.03.2009 15:38:49:
markov-switching
the
message
The error message means that there is missing value instead of logical 
when you are calling if
[1] NA
Error in if (a < b) print("No.way") : 
  missing value where TRUE/FALSE needed
[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
cbind(0,0,0,100))

what about
[,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
so
and
http://www.R-project.org/posting-guide.html