ultimate R recursion


 p=length(y)/n #acceptance probability


10 Responses to “ultimate R recursion”

  1. This would work in Prolog language which is VERY real language.

  2. As stated above, you could make declarative languages work that way, with one example being Prolog (http://en.wikipedia.org/wiki/Prolog ). Another example, which isn’t a language, but might be closer to what you are asking for, are propagation of constraint solvers, where you put in quantity relationships, and the variables won’t resolve to numbers until you put in enough points to determine the system (http://en.wikipedia.org/wiki/Propagation_constraint , and http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-22.html#%_sec_3.3.5 ). But both of these are no substitute for just plain declaring constants up front when you have enough information to do so… these systems would allow you to cheat that, but it is not their main utility.

  3. Moyenne Armorique Says:

    I don’t know if this answer your question, but in R you can define and initialize variables outside a function before calling it, thanks to scoping. In this case, since accept-reject does not need C, you could do the following:

    > C=1
    > fAR1(10^4)

    C and fAR1() belong to the same environment, so there won’t be any problem.

    If you want to change the value of C from within fAR1() you can substitute the line



    C <<- M/3

    It goes without saying that you have to be extremely careful in handling local and global variables.

    • anyway, initializing the variable C outside the function does not make a lot of sense to me…

      as Christian said there are two mistakes here:
      1) the pupil does not seem to understand the importance of initialization.. this is a general coding error
      2) the pupil does not understand that he needs just the kernel of the distribution.. that’s one of the beauties of the AR algorithm.. and this is a statistical error

    • Thanks! Actually, I was not really asking a question, more wondering about the state of mind of my student who could handle an unknown constant as if it has a fixed if unknown value and then later find its value… All this done without the slightest idea of what this kind of programming would involve!

  4. Simon Byrne Says:

    This would work for a declarative language, the example most statisticians would be familiar with is WinBUGS.

    • Thanks. I had not thought of Bugs! What I had in mind was more in line with a recursion where you would introduce a constant later to be solved.

Leave a Reply


WordPress.com Logo


Twitter picture


Facebook photo


Google+ photo


Connecting to %s


Get every new post delivered to your Inbox.

Join 644 other followers