Hello all, I need a help. I am modeling a disease and a create a R function like that: Lambda<-function (x,date1,r,h,a){ ndate1 <- as.Date(date1, "%d/%m/%Y") t1 <- as.numeric(ndate1) x[order(x$i),] t <-x[,"t"] i <-x[,"i"] CONTAGIEUX <-x[,"CONTAGIEUX"] while ( t1 < min(t) ){ for (i in 1:length(i) ){ {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 } on such data : DATE i Symptomes t Incubation CONTAGIEUX 1 2009-04-29 Canada 13 14363 13 13 2 2009-05-01 Israel 2 14365 2 2 3 2009-05-09 argentina 1 14373 1 1 5 2009-05-09 australia 1 14373 1 1 6 2009-05-10 australia 1 14374 2 2 7 2009-04-29 Austria 1 14363 1 1 8 2009-04-30 Austria 1 14364 2 2 9 2009-05-01 Austria 1 14365 2 3 10 2009-05-02 Austria 1 14366 2 4 11 2009-05-03 Austria 1 14367 2 5 17 2009-05-09 Austria 1 14373 2 7 18 2009-05-10 Austria 1 14374 2 7 19 2009-05-08 brasil 4 14372 4 4 20 2009-05-09 brazil 6 14373 6 6 21 2009-05-10 brazil 6 14374 12 12 22 2009-05-02 canada 51 14366 51 51 23 2009-05-03 canada 85 14367 136 136 24 2009-05-04 canada 101 14368 186 237 31 2009-04-27 Canada 6 14361 6 6 32 2009-04-28 Canada 6 14362 6 6 33 2009-04-30 Canada 19 14364 25 25 34 2009-05-01 Canada 34 14365 53 59 35 2009-05-01 China,HongKong, SAR 1 14365 1 1 36 2009-05-02 China,HongKong, SAR 1 14366 2 2 37 2009-05-03 China,HongKong, SAR 1 14367 2 3 38 2009-05-04 China,HongKong, SAR 1 14368 2 4 44 2009-05-10 China,HongKong, SAR 1 14374 2 7 45 2009-05-04 colombia 1 14368 1 1 46 2009-05-05 colombia 1 14369 2 2 47 2009-05-06 colombia But i do not get the results,i try by all means but i d'ont understant the problem. Thanks for your help. -- View this message in context: http://r.789695.n4.nabble.com/Help-for-a-function-tp4652054.html Sent from the R help mailing list archive at Nabble.com.
I am running a random intercept random slope regression: fitRIRT <- lme(echogen~time,random=~ 1+time|subject,data=repeatdata,na.action=na.omit) summary(fitRIRT) I would like to get the subject-specific slopes, i.e. the slope that the model computes for each subject. If I have 10-subjects I should have 10-slopes. I don't see the slope when I look at the items listed in names(summary(fitRIRT) nor when I look at the items listed in names(fitRIRT) Thanks John John David Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) Confidentiality Statement: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
Ken, Thank you for your help. ranef(fitRIRT) does not give me what I expect. The subject-specific slopes, and subject-specific intercepts are not anywhere close to what I would expect them to be; the mean of the subject-specfic values should be close to those reported by summary(fitRIRT) and they are not. As you will see by examining the material below, the subject-specific slopes are off by many order of magnitude. The intercepts are also far from the value reported in summary(fitRIRT). Do you have any thoughts? Thanks, John> fitRIRT <- lme(echogen~time,random=~ 1+time|subject,data=repeatdata,na.action=na.omit)> summary(fitRIRT)Linear mixed-effects model fit by REMLData: repeatdata AIC BIC logLik 495.097 507.2491 -241.5485 Random effects: Formula: ~1 + time | subject Structure: General positive-definite, Log-Cholesky parametrization StdDev Corr (Intercept) 1.917511e+01 (Intr) time 2.032276e-04 0 Residual 1.044601e+01 Fixed effects: echogen ~ time Value Std.Error DF t-value p-value (Intercept) 64.54864 4.258235 32 15.158543 0.0000 time 0.35795 0.227080 32 1.576307 0.1248 Correlation: (Intr) time -0.242 Standardized Within-Group Residuals: Min Q1 Med Q3 Max -1.61362755 -0.52710871 0.02948008 0.41793322 1.77340082 Number of Observations: 58 Number of Groups: 25 > ranef(fitRIRT) (Intercept) time 1 -3.278112 2.221016e-09 2 -35.400618 4.314995e-08 3 11.493110 -6.797543e-09 4 -16.209586 -7.070834e-08 5 3.585227 -2.389705e-08 6 1.614320 -1.967700e-09 7 8.346905 5.827094e-08 8 30.917812 -3.768584e-08 9 -0.394101 -9.158251e-09 10 4.437509 -4.057971e-08 11 31.956597 -2.126275e-08 12 41.567402 -4.853942e-08 13 -10.723993 1.307152e-08 14 -4.554837 5.551908e-09 15 -4.554501 4.815086e-08 16 13.296985 -3.743967e-08 17 -8.255439 1.733238e-08 18 -21.317239 2.203885e-08 19 -13.480159 2.194016e-08 20 -13.044766 2.269168e-08 21 11.639198 -1.418706e-08 22 -27.457388 -1.154099e-08 23 2.194001 -5.509119e-09 24 -3.992646 7.682188e-08 25 1.614320 -1.967700e-09 John David Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing)>>> Kenneth Frost <kfrost at wisc.edu> 12/4/2012 10:44 AM >>> I think this might be close to what you want. ranef(fitRIRT) On 12/04/12, John Sorkin wrote:> I am running a random intercept random slope regression: > > fitRIRT <- lme(echogen~time,random=~ 1+time|subject,data=repeatdata,na.action=na.omit) > summary(fitRIRT) > > I would like to get the subject-specific slopes, i.e. the slope that the model computes for each subject. If I have 10-subjects I should have 10-slopes. I don't see the slope when I look at the items listed in > names(summary(fitRIRT) > nor when I look at the items listed in > names(fitRIRT) > > Thanks > John > > > > > > > John David Sorkin M.D., Ph.D. > Chief, Biostatistics and Informatics > University of Maryland School of Medicine Division of Gerontology > Baltimore VA Medical Center > 10 North Greene Street > GRECC (BT/18/GR) > Baltimore, MD 21201-1524 > (Phone) 410-605-7119 > (Fax) 410-605-7913 (Please call phone number above prior to faxing) > Confidentiality Statement: > This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. > > > ______________________________________________ > R-help at 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.-- Kenneth Frost Graduate Research Assistant - Dept. of Plant Pathology University of Wisconsin - Madison Lab: (608) 262-9914 Mobile: (608) 556-9637 kfrost at wisc.edu Confidentiality Statement: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
I think the random effects represent the subject adjustments to the population averages. You may have to do the addition yourself to get the subject specific slopes and intercepts. Someone will hopefully correct me if I'm wrong. On 12/04/12, John Sorkin wrote:> > > > Ken, > Thank you for your help. ranef(fitRIRT) does not give me what I expect. The subject-specific slopes, and subject-specific intercepts are not anywhere close to what I would expect them to be; the mean of the subject-specfic values should be close to those reported by > summary(fitRIRT) and they are not. As you will see by examining the material below, the subject-specific slopes are off by many order of magnitude. The intercepts are also far from the value reported in summary(fitRIRT). Do you have any thoughts? > Thanks, > John > > > > fitRIRT <- lme(echogen~time,random=~ 1+time|subject,data=repeatdata,na.action=na.omit) > summary(fitRIRT) Linear mixed-effects model fit by REML Data: repeatdata AIC BIC logLik 495.097 507.2491 -241.5485 Random effects: Formula: ~1 + time | subject Structure: General positive-definite, Log-Cholesky parametrization StdDev Corr (Intercept) 1.917511e+01 (Intr) time 2.032276e-04 0 Residual 1.044601e+01 Fixed effects: echogen ~ time Value Std.Error DF t-value p-value (Intercept) 64.54864 4.258235 32 15.158543 0.0000 time 0.35795 0.227080 32 1.576307 0.1248 Correlation: (Intr) time -0.242 Standardized Within-Group Residuals: Min Q1 Med Q3 Max -1.61362755 -0.52710871 0.02948008 0.41793322 1.77340082 Number of Observations: 58 Number of Groups: 25 > ranef(fitRIRT) (Intercept) time 1 -3.278112 2.221016e-09 2 -35.400618 4.314995e-08 3 11.493110 -6.797543e-09 4 -16.209586 -7.070834e-08 5 3.585227 -2.389705e-08 6 1.614320 -1.967700e-09 7 8.346905 5.827094e-08 8 30.917812 -3.768584e-08 9 -0.394101 -9.158251e-09 10 4.437509 -4.057971e-08 11 31.956597 -2.126275e-08 12 41.567402 -4.853942e-08 13 -10.723993 1.307152e-08 14 -4.554837 5.551908e-09 15 -4.554501 4.815086e-08 16 13.296985 -3.743967e-08 17 -8.255439 1.733238e-08 18 -21.317239 2.203885e-08 19 -13.480159 2.194016e-08 20 -13.044766 2.269168e-08 21 11.639198 -1.418706e-08 22 -27.457388 -1.154099e-08 23 2.194001 -5.509119e-09 24 -3.992646 7.682188e-08 25 1.614320 -1.967700e-09 > > > > > > > > John David Sorkin M.D., Ph.D. > Chief, Biostatistics and Informatics > University of Maryland School of Medicine Division of Gerontology > Baltimore VA Medical Center > 10 North Greene Street > GRECC (BT/18/GR) > Baltimore, MD 21201-1524 > (Phone) 410-605-7119 > (Fax) 410-605-7913 (Please call phone number above prior to faxing)>>> Kenneth Frost <kfrost at wisc.edu> 12/4/2012 10:44 AM >>> > I think this might be close to what you want. ranef(fitRIRT) > > On 12/04/12, John Sorkin wrote: > > I am running a random intercept random slope regression: > > > > fitRIRT <- lme(echogen~time,random=~ 1+time|subject,data=repeatdata,na.action=na.omit) > > summary(fitRIRT) > > > > I would like to get the subject-specific slopes, i.e. the slope that the model computes for each subject. If I have 10-subjects I should have 10-slopes. I don't see the slope when I look at the items listed in > > names(summary(fitRIRT) > > nor when I look at the items listed in > > names(fitRIRT) > > > > Thanks > > John > > > > > > > > > > > > > > John David Sorkin M.D., Ph.D. > > Chief, Biostatistics and Informatics > > University of Maryland School of Medicine Division of Gerontology > > Baltimore VA Medical Center > > 10 North Greene Street > > GRECC (BT/18/GR) > > Baltimore, MD 21201-1524 > > (Phone) 410-605-7119 > > (Fax) 410-605-7913 (Please call phone number above prior to faxing) > > Confidentiality Statement: > > This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. > > > > > > ______________________________________________ > > R-help at 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. > > -- > Kenneth Frost > Graduate Research Assistant - Dept. of Plant Pathology > University of Wisconsin - Madison > Lab: (608) 262-9914 > Mobile: (608) 556-9637 > kfrost at wisc.edu > > > > > Confidentiality Statement: > > This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.-- Kenneth Frost Graduate Research Assistant -?Dept. of Plant Pathology University of Wisconsin - Madison Lab: (608) 262-9914 Mobile: (608) 556-9637 kfrost at wisc.edu
What are you expecting? What do you get? What is the problem? J On 4 December 2012 06:01, anoumou <teko_maurice at yahoo.fr> wrote:> Hello all, > I need a help. > I am modeling a disease and a create a R function like that: > > Lambda<-function (x,date1,r,h,a){ > ndate1 <- as.Date(date1, "%d/%m/%Y") > t1 <- as.numeric(ndate1) > x[order(x$i),] > t <-x[,"t"] > i <-x[,"i"] > CONTAGIEUX <-x[,"CONTAGIEUX"] > while ( t1 < min(t) ){ > for (i in 1:length(i) ){ > {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 > } > > on such data : > > DATE i Symptomes t Incubation CONTAGIEUX > 1 2009-04-29 Canada 13 14363 13 13 > 2 2009-05-01 Israel 2 14365 2 2 > 3 2009-05-09 argentina 1 14373 1 1 > 5 2009-05-09 australia 1 14373 1 1 > 6 2009-05-10 australia 1 14374 2 2 > 7 2009-04-29 Austria 1 14363 1 1 > 8 2009-04-30 Austria 1 14364 2 2 > 9 2009-05-01 Austria 1 14365 2 3 > 10 2009-05-02 Austria 1 14366 2 4 > 11 2009-05-03 Austria 1 14367 2 5 > 17 2009-05-09 Austria 1 14373 2 7 > 18 2009-05-10 Austria 1 14374 2 7 > 19 2009-05-08 brasil 4 14372 4 4 > 20 2009-05-09 brazil 6 14373 6 6 > 21 2009-05-10 brazil 6 14374 12 12 > 22 2009-05-02 canada 51 14366 51 51 > 23 2009-05-03 canada 85 14367 136 136 > 24 2009-05-04 canada 101 14368 186 237 > 31 2009-04-27 Canada 6 14361 6 6 > 32 2009-04-28 Canada 6 14362 6 6 > 33 2009-04-30 Canada 19 14364 25 25 > 34 2009-05-01 Canada 34 14365 53 59 > 35 2009-05-01 China,HongKong, SAR 1 14365 1 1 > 36 2009-05-02 China,HongKong, SAR 1 14366 2 2 > 37 2009-05-03 China,HongKong, SAR 1 14367 2 3 > 38 2009-05-04 China,HongKong, SAR 1 14368 2 4 > 44 2009-05-10 China,HongKong, SAR 1 14374 2 7 > 45 2009-05-04 colombia 1 14368 1 1 > 46 2009-05-05 colombia 1 14369 2 2 > 47 2009-05-06 colombia > > But i do not get the results,i try by all means but i d'ont understant the > problem. > Thanks for your help. > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Help-for-a-function-tp4652054.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.
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
Hello, You should post your questions to r-help at r-project.org, the odds of getting more and better answers are greater. As for the question, try the following. Note that the functions now have an extra argument. incub <- function(x, n = 2){ x$Incubation <- 0 x$Incubation[1] <- x$Symptomes[1] if(nrow(x) >= n) x$Incubation[2] <- sum(x$Symptomes[seq_len(n)]) for(i in seq_len(nrow(x))[-seq_len(n)]) x$Incubation[i] <- sum(x$Symptomes[i - (seq_len(n) - 1)]) x } contag <- function(x, n = 7){ x$CONTAGIEUX <- 0 for(i in 1:min(nrow(x), n)) x$CONTAGIEUX[i] <- sum(x$Symptomes[1:i], na.rm = TRUE) for (i in seq_len(nrow(x))[-seq_len(n)]) { x$CONTAGIEUX[i] <- x$Symptomes[i] + x$CONTAGIEUX[i-1] - x$Symptomes[i-n] } x } incub_ARGENTINA <-incub(ARGENTINA, 2) incub_ARGENTINA contag_ARGENTINA <-contag(ARGENTINA, 7) contag_ARGENTINA derdata_ARGENTINA <-merge(contag_ARGENTINA, incub_ARGENTINA) derdata_ARGENTINA Hope this helps, Rui Barradas Em 29-08-2013 08:31, teko maurice escreveu:> > > Dear Rui, > Long time!!!!! > I came to ask for advice and help if you have time. > I am on my PHD developping all to model pandemic. > I have post on R help but nobody answer me,maybe it's so specific. > So i back to you if you can help me. > Hello all, > I have such a datasets for a pandemic virus. > DATE Algeria Antigua.and.Barbuda ARGENTINA AUSTRALIA AUSTRIA Bahamas > 1 2009-04-24 0 0 0 0 0 0 > 2 2009-04-26 0 0 0 0 0 0 > 3 2009-04-27 0 0 0 0 0 0 > 4 2009-04-28 0 0 0 0 0 0 > 5 2009-04-29 0 0 0 1 0 0 > 6 2009-04-30 0 0 0 1 0 0 > 7 2009-05-01 0 0 0 1 0 0 > 8 2009-05-02 0 0 0 1 0 0 > 9 2009-05-03 0 0 0 1 0 0 > 10 2009-05-04 0 0 0 1 0 0 > 11 2009-05-05 0 0 0 1 0 0 > 12 2009-05-06 0 0 0 1 0 0 > 13 2009-05-07 0 0 0 1 0 0 > 14 2009-05-08 0 0 0 1 0 0 > 15 2009-05-09 0 0 1 2 0 0 > 16 2009-05-10 0 0 1 2 0 0 > 17 2009-05-11 0 0 1 1 1 0 > 18 2009-05-12 0 0 1 1 1 0 > 19 2009-05-13 0 0 1 1 1 0 > 20 2009-05-14 0 0 1 1 1 0 > 21 2009-05-15 0 0 1 1 1 0 > 22 2009-05-16 0 0 1 1 1 0 > 23 2009-05-17 0 0 1 1 1 0 > 24 2009-05-18 0 0 1 1 1 0 > 25 2009-05-19 0 0 1 1 1 0 > 26 2009-05-20 0 0 1 1 1 0 > 27 2009-05-21 0 0 1 3 1 0 > 28 2009-05-22 0 0 1 7 1 0 > 29 2009-05-23 0 0 1 12 1 0 > 30 2009-05-25 0 0 2 16 1 0 > 31 2009-05-26 0 0 5 19 1 0 > 32 2009-05-27 0 0 19 39 1 0 > 33 2009-05-29 0 0 37 147 1 0 > 34 2009-06-01 0 0 100 297 1 1 > 35 2009-06-03 0 0 131 501 1 1 > 36 2009-06-05 0 0 147 876 2 1 > 37 2009-06-08 0 0 202 1051 5 1 > 38 2009-06-10 0 0 235 1224 5 2 > 39 2009-06-11 0 0 256 1307 7 1 > 40 2009-06-12 0 0 343 1307 7 1 > 41 2009-06-15 0 0 343 1823 7 1 > 42 2009-06-17 0 0 733 2112 7 2 > 43 2009-06-19 0 0 918 2199 8 2 > 44 2009-06-22 1 0 1010 2436 9 2 > 45 2009-06-24 3 2 1213 2857 12 6 > 46 2009-06-26 2 2 1391 3280 12 4 > 47 2009-06-29 2 2 1488 4038 12 4 > 48 2009-07-01 2 2 1587 4090 15 6 > 49 2009-07-03 5 2 1587 4568 15 6 > 50 2009-07-06 5 2 2485 5298 19 7 > > ... > # I transform the date in numeric > t1<-derdata[["DATE"]] > t <- as.numeric(t1) > t > #i add the numeric date to the dataset > Mydata<-data.frame(derdata,t) > Mydata > # I select each country > ARGENTINA<- subset(Mydata,select = c(DATE,t,Canada)) > names(ARGENTINA)[3] <- "Symptomes" > ARGENTINA > > ##### I create two functions because i want to create two variables by country :Incubation and CONTAGIEUX > > ##### 1. Here is the incubation function (a person getting a virus ,incub the virus for a certain time : 2 days) > incub <- function(x){ > x$Incubation <- 0 > x[order(x$t),] > x$Incubation[1] <- x$Symptomes[1] > if(nrow(x) > 1) > x$Incubation[2] <- sum(x$Symptomes[1:2]) > for(i in seq_len(nrow(x))[-(1:2)]) > x$Incubation[i] <- sum(x$Symptomes[i - (0:1)]) > x > } > > 2. Contagion function (after incubing the virus, the subject can spread now the virus for the 7 coming days) > > contag <- function(x){ > x$CONTAGIEUX <- 0 > for(i in 1:min(nrow(x), 7)) > x$CONTAGIEUX[i] <- sum(x$Symptomes[1:i], na.rm = TRUE) > for (i in seq_len(nrow(x))[-(1:7)]) { > x$CONTAGIEUX[i] <- x$Symptomes[i] + x$CONTAGIEUX[i-1] - > x$Symptomes[i-7] > } > x > } > > # and So i obtain by country what i need. > incub_ARGENTINA <-incub(ARGENTINA) > incub_ARGENTINA > contag_ARGENTINA <-contag(ARGENTINA) > contag_ARGENTINA > derdata_ARGENTINA <-merge(contag_ARGENTINA, incub_ARGENTINA) > derdata_ARGENTINA > > > > Now my problem is that i want to update those functions incub and contag so that i can easily change the incubation and contagion period. > they will not be fixe. > the incubation period can be 2 or 1 or 3 or 4 or 5 and so. > also the contagion period can be 4 or 5 or 6 or 8 or 9,...... > And i want to not select the country before launch the the two funcions (incub and contag) > so that i have all the datasets for all country in the same dataset > > Maurice > > > > > > > > > > ________________________________ > De : Rui Barradas <ruipbarradas at sapo.pt> > ? : Jim Lemon <jim at bitwrit.com.au> > Cc : anoumou <teko_maurice at yahoo.fr>; r-help at r-project.org > Envoy? le : Mercredi 5 d?cembre 2012 16h26 > Objet : Re: [R] Help for a function > > > 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 at 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.