[R] Help for a function

Jim Lemon jim at bitwrit.com.au
Wed Dec 5 05:20:58 CET 2012


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




More information about the R-help mailing list