On 28-Jul-09 08:28:22, Inchallah Yarab wrote: > How I can vary the parameters for a function? > > I have a function with 5 parameters I want to turn the function for a > range of numbers for one of these parameters!! i want to have in the > end the value of the function in the different cas of one of the > paramter (the others paramters are fixes!!) thank you for your help
It depends on the internals of the function. In R, most functions (including what you write yourself, if written in the right way) allow you to give a vector of numbers to a numerical parameter. The calculations are then "vectorised" in a single pass, and the results for each value are returned as a vector. For example, the pnorm() function for several different standard deviations: SD = c(1,1.5,2,2.5,3) cbind(SD,pnorm(q=0.5, mean=0, sd=SD)) # [1,] 1.0 0.6914625 # [2,] 1.5 0.6305587 # [3,] 2.0 0.5987063 # [4,] 2.5 0.5792597 # [5,] 3.0 0.5661838 Likewise, if your function is my.fun <- function(par1,par2,par3,par4,par5){ (par1 + par2*par3 + (par3^2)*(par4 + par5)) } then you could have par1 <- 1.1 ; par2 <- 1.2 ; par4 <- 1.4; par5 <- 1.5 par3 <- SD # (as above) cbind(SD,my.fun(par1,par2,par3,par4,par5)) # SD # [1,] 1.0 5.200 # [2,] 1.5 9.425 # [3,] 2.0 15.100 # [4,] 2.5 22.225 # [5,] 3.0 30.800 Hoping this helps! Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.hard...@manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 28-Jul-09 Time: 15:39:27 ------------------------------ XFMail ------------------------------ ______________________________________________ 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.