[R] Summation resulting in a list?

mousy0815 mousy0815 at gmail.com
Mon Jul 11 21:14:02 CEST 2011


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 wanted to get the sum of the probability at  all the values of "b" (ie.
Probability(10, 0.1, 1, 1, 4, 5) + Probability(10, 0.1, 1, 2, 4, 5)... +
Probability(10, 0.1, 1, 9, 4, 5). For that I can just use the sum() function
right? 
But since m is the time steps, is it possible for me to input m and b and
get the sum mentioned before at each value of m?
So like ((Probability(10, 0.1, 1, 1, 4, 5) + Probability(10, 0.1, 1, 2, 4,
5)... + Probability(10, 0.1, 1, 9, 4, 5)), Probability(10, 0.1, 2, 1, 4, 5)
+ Probability(10, 0.1, 2, 2, 4, 5)... + Probability(10, 0.1, 2, 9, 4, 5)...)

This is what I have right now, but it doesn't work:
summing<- function(N,f,m, x, t ){
	B <- c(1:(x+t))
	C <- (sum(Probability(N, f, B, 1, x, t)))
	M = 2
	if (M<=max(m)) {
		B <- c(1:(x+t))
		append(C,sum(Probability(N, f, M, B, x, t)), after=M-1)
		M = M+1} else {return(C)}
		} 

--
View this message in context: http://r.789695.n4.nabble.com/Summation-resulting-in-a-list-tp3660514p3660514.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list