Hello all R users, My simulation function works correctly, but I have problems with plot function. You will find the following code using it. Thank you for your help ##################################################" simulation <- function(k, n){ conc <- seq(0,10,by=0.5) #choixg <- seq(1, length(conc)) choixg <- rep(0,length(conc)) for (i in 1:length(conc)){ choixg[i] <- (k + conc[i])^2/((k+conc[i])^n + (k+1)^n) } return(choixg) } simulation(5,1) plot(conc, choixg, main ="fonction de choix", col= "blue", pch=20, xlab = " concentration", ylab="proba de choisir la gauche") ########################################################## Lassana KOITA Service Technique de l'Aviation Civile (STAC) Direction G??n??rale de l'Aviation Civile (DGAC) Tel: 01 49 56 80 60 Fax: 01 49 56 82 14 http://www.stac.aviation-civile.gouv.fr
KOITA Lassana - STAC/ACE wrote:> > > > Hello all R users, > My simulation function works correctly, but I have problems with plot > function. You will find the following code using it. > Thank you for your help > ##################################################" > > simulation <- function(k, n){ > > conc <- seq(0,10,by=0.5) > #choixg <- seq(1, length(conc)) > choixg <- rep(0,length(conc)) > for (i in 1:length(conc)){ > choixg[i] <- (k + conc[i])^2/((k+conc[i])^n + (k+1)^n) > > } > return(choixg) > > } > simulation(5,1)Please read the manuals! The objects "conc" and "choixg" ar local to your function "simulation"... If you return return(list(choixg=choixg, conc=conc)) from your function, then you can plot as follows: simResult <- simulation(5,1) with(simResult, plot(conc, choixg, main ="fonction de choix", col= "blue", pch=20, xlab = " concentration", ylab="proba de choisir la gauche")) Uwe Ligges> plot(conc, choixg, main ="fonction de choix", col= "blue", pch=20, > xlab = " concentration", ylab="proba de choisir la gauche") > ########################################################## > > Lassana KOITA > Service Technique de l'Aviation Civile (STAC) > Direction G??n??rale de l'Aviation Civile (DGAC) > Tel: 01 49 56 80 60 > Fax: 01 49 56 82 14 > http://www.stac.aviation-civile.gouv.fr > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Hi Just a small modification. You has to return also conc. simulation <- function(k, n){ conc <- seq(0,10,by=0.5) #choixg <- seq(1, length(conc)) choixg <- rep(0,length(conc)) for (i in 1:length(conc)){ choixg[i] <- (k + conc[i])^2/((k+conc[i])^n + (k+1)^n) } return(data.frame(choixg, conc)) } mydf<-simulation(5,1) plot(mydf$conc, mydf$choixg, main ="fonction de choix", col= "blue", pch=20, xlab = " concentration", ylab="proba de choisir la gauche") HTH Petr On 11 Oct 2005 at 18:54, KOITA Lassana - STAC/ACE wrote: To: r-help at stat.math.ethz.ch From: "KOITA Lassana - STAC/ACE" <lassana.koita at aviation-civile.gouv.fr> Date sent: Tue, 11 Oct 2005 18:54:18 +0200 Subject: [R] Problems with plot function> > > > > Hello all R users, > My simulation function works correctly, but I have problems with plot > function. You will find the following code using it. Thank you for > your help ##################################################" > > simulation <- function(k, n){ > > conc <- seq(0,10,by=0.5) > #choixg <- seq(1, length(conc)) > choixg <- rep(0,length(conc)) > for (i in 1:length(conc)){ > choixg[i] <- (k + conc[i])^2/((k+conc[i])^n + (k+1)^n) > > } > return(choixg) > > } > simulation(5,1) > > plot(conc, choixg, main ="fonction de choix", col= "blue", pch=20, > xlab = " concentration", ylab="proba de choisir la gauche") > ########################################################## > > Lassana KOITA > Service Technique de l'Aviation Civile (STAC) > Direction G??n??rale de l'Aviation Civile (DGAC) > Tel: 01 49 56 80 60 > Fax: 01 49 56 82 14 > http://www.stac.aviation-civile.gouv.fr > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlPetr Pikal petr.pikal at precheza.cz