I have a set of functions:
Probability <- function(N, f, w, b, l, n, q) {
#N is the number of lymph nodes
#f is the fraction of Dendritic cells (in the correct node) that have the
antigen
#w is time in terms of hours
#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))
#q is the length of the time step
#l is the LN transit time in hours
#n is the gap transit time in hours
y <- n/q #y is the number of time steps it takes to traverse the gap
t <- l/q #t is the number of time steps it takes to traverse a node.
m <-(w%/%q)
A <- 1/N
B <- 1-A
C <- 1-f
D <- (((m+b-1)%%(y+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)/(y+t))-1)) # intermediate nodes (if
any)
c <- (B + A*(C^D)) # last node
return(a*b*c)
} else {return(Probability(N, f, ((m*q)-q), b, l, n, q))} ## finish in a
gap
} else {###### starts outside node
if (m<=(y+t-b)) {return(1)} #also end in the gap
if (D<=t) { #end in a node
b <- ((B + A*(C^t))^(floor((m/(y+t)))))
c <- (B + (A*(C^D)))
return(b*c)
} else {return(Probability(N, f, ((m*q)-q), b, l, n, q))} #outside node
}
}
step.2 <- function(N, f, w, l, n, q) {##the sum of all the possible position
(times the probability)
y <- n/q
t <- l/q
A <- sapply(1:(y+t), function(x) Probability(N=N, f=f, w=w, b=x, l=l, n=n,
q=q))
B <- sum(A)
C <- 1/(y+t)
return(B*C)
}
step.3 <- function(N, f, w, l, n, q, X) { #X is the number of cells
return((1-((step.2(N, f, w, l, n, q))^X)))}
when I graph the Probability as a function of the transit time I get the
following graph:
tmax = 30
tlist <- seq(from=0, to=tmax, by=1)
cells = 1000
plot(tlist, sapply(tlist, function(x) step.3(N=500, f=0.001, w=24, l=x,
n=10, q=0.1, X=cells)), type='l', xlab="LN Transit Time
(hours)",
ylab="Probability after 24 hours", main ="The Effect of DC
frequency on the
Dip - 1000 cells", ylim = c(0,1))
lines(tlist, sapply(tlist, function(x) step.3(N=500, f=0.005, w=24, l=x,
n=10, q=0.1, X=cells)), col="coral")
lines(tlist, sapply(tlist, function(x) step.3(N=500, f=0.01, w=24, l=x,
n=10, q=0.1, X=cells)), col="turquoise")
lines(tlist, sapply(tlist, function(x) step.3(N=500, f=0.05, w=24, l=x,
n=10, q=0.1, X=cells)), col="blue")
lines(tlist, sapply(tlist, function(x) step.3(N=500, f=0.1, w=24, l=x, n=10,
q=0.1, X=cells)), col="red")
lines(tlist, sapply(tlist, function(x) step.3(N=500, f=0.5, w=24, l=x, n=10,
q=0.1, X=cells)), col="green", type = 'l')
legend((tmax*0.75), 0.5, c("f=0.001", "f=0.005",
"f=0.01", "f=0.05",
"f=0.1", "f=0.5"), fill = c("black",
"coral", "turquoise", "blue", "red",
"green"))
http://r.789695.n4.nabble.com/file/n3748957/Picture_2.png
Why do the top three lines converge? Is it some bug in my function?
--
View this message in context:
http://r.789695.n4.nabble.com/Why-does-the-graph-converge-tp3748957p3748957.html
Sent from the R help mailing list archive at Nabble.com.