Probability <- function(N, f, m, b, x, t) { #N is the number of lymph nodes #f is the fraction of Dendritic cells (in the correct node) that have the antigen #m is the number of time steps #b is the starting position (somewhere in the node or somewhere in the gap between nodes. It is a number between 1 and (x+t)) #x is the number of time steps it takes to traverse the gap #t is the number of time steps it takes to traverse a node. A <- 1/N B <- 1-A C <- 1-f D <- (((m+b-1)%%(x+t))+1)
if (b<=t) {########starts inside node if (m<=(t-b)){return(B + A*(C^m))} # start & end in first node if (D<=t) { # we finish in a node a <- (B + A*(C^(t-b))) #first node b <- ((B + A*(C^t))^(floor((m+b)/(x+t))-1)) # intermediate nodes (if any) c <- (B + A*(C^D)) # last node d <- (a*b*c) return(d) } else {Probability(N, f, (m-1), b, x, t)} ## finish in a gap } else {###### starts outside node if (m<=(x+t-b)) {return(1)} #also end in the gap if (D<=t) { #end in a node b <- ((B + A*(C^t))^(floor((m/(x+t))))) c <- (B + (A*(C^D))) d <- (b*c) return(d) } else {Probability(N, f, (m-1), b, x, t)} #outside node } } I have the following code and I know it works, but I need to explain what is going on, particularly with the recursion. Is it true that "when each call finishes - it will pass a quantity back to the next generation above until you return to the start of the chain, then outputs the final result."? If so, could someone explain it in a bit more clearly? if not, how does the recursion work - how does it finally output a value? -- View this message in context: http://r.789695.n4.nabble.com/Explain-how-it-gets-back-out-tp3662928p3662928.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.