Michael Curran
2009-Mar-23 14:38 UTC
[R] error statement: missing value where TRUE/FALSE needed
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 -- Michael Curran Candidate for the MPhil in Economics Cambridge University http://www.michael-curran.com/ -------------- next part -------------- A non-text attachment was scrubbed... Name: gibbsms-1.pdf Type: application/pdf Size: 175239 bytes Desc: gibbsms-1.pdf URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090323/5cc81676/attachment-0003.pdf>
jim holtman
2009-Mar-24 00:30 UTC
[R] error statement: missing value where TRUE/FALSE needed
I would assume the expression in the 'if' is giving an NA as a result:> if (NA) 1 else 2Error 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 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 > -- > Michael Curran > Candidate for the MPhil in Economics > Cambridge University > http://www.michael-curran.com/ > > > > > ______________________________________________ > 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. > >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Petr PIKAL
2009-Mar-24 14:52 UTC
[R] Odp: error statement: missing value where TRUE/FALSE needed
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 amarkov-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 explainingthe> 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 errormessage> 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 andso> these are the file names that the code loads. If anyone uses the codeand> 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 guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Seemingly Similar Threads
- determine the number of digits printed into graph with "text(...)"
- stripchart ignores main title option (PR#12202)
- grouping dataframe entries using a categorical variable
- Patch with modified commit message
- Fit indexes in SEM with categorical data + ML estimation