Hello,

Also, t1 and min(xt) do not vary inside the loop so if it enters the loop it never exits.
And

    res1[j] <-(a*h)
    res2 <-sum( res1[j])

is equivalent to

    res2 <- a*h

so the inner-most loop is not needed at all.

Hope this helps,

Rui Barradas
Em 05-12-2012 04:20, Jim Lemon escreveu:
On 12/05/2012 01:01 AM, anoumou wrote:
Hello all,
I need a help.
I am modeling a disease and a create a R function like that:
...
But i do not get the results,i try by all means but i d'ont understant the
problem.

Hi anoumou,
Your function provides almost no indication of what two of its five arguments are supposed to be. If, with a certain degree of optimistic inference, we suppose "x" to be a data frame organized as shown below the function. "t", "i" and "CONTAGIEUX" must be the appropriately named columns of the data frame. This leaves two columns, "Symptomes" and "Incubation". Say we flip a coin to decide which of these to assign to "r", and with all of our degrees of freedom gone, we assume that the other is "h". We are forced to the conclusion that "a" is a nuisance argument, added to throw us off the scent.

Peering within the function, we notice that the date format is wrong, braces are unmatched and that our data frame is alphabetically ordered by name of country to no purpose whatsoever. The best I can do here is to make the function potentially able to do something if you can work out what to do with it.

Lambda<-function (x,date1,r,h,a) {
 ndate1 <- as.Date(date1, "%Y-%m-%d")
 t1 <- as.numeric(ndate1)
 x[order(x$i),]
 xt <-x[,"t"]
 xi <-x[,"i"]
 CONTAGIEUX <-x[,"CONTAGIEUX"]
 while ( t1 < min(xt) ){
  for (i in 1:length(xi) ){
   for (j in 1:CONTAGIEUX[length(CONTAGIEUX)]){
    res1[j] <-(a*h)
    res2 <-sum( res1[j])
   }
  }
 lambda[i] <- r*res2
 }
 x<-data.frame(x,lambda)
 x
}

Jim

______________________________________________
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.

______________________________________________
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.

Reply via email to