David Afshartous
2008-Feb-07 20:35 UTC
[R] Extending curve() function; 2D function plot with arguments
All, I have a simple function below that defines a 2-dimensional curve: n.j = 4; sigma.y = 1.2; sigma.a = 2.2; y.bar.j = 8.1; mu.a = 4.4 alpha.j.fun <- function(sigma.a) { alpha.j = ((n.j/sigma.y^2)*y.bar.j + (1/sigma.a^2)*mu.a)/(n.j/sigma.y^2 + 1/sigma.a^2 ) alpha.j} The parameters to the function are hard coded. I plot the function via curve(): curve(alpha.j.fun, 2, 4, ylim = c(0,10), xlab="sigma.a values", ylab="alpha.j.hat") Is there a way to supply the function parameters parameter as arguments, viz., to graph alpha.j versus sigma.a for a different value of sigma.y? Below is an attempted solution, but this is very clunky and also doesn't work since the embedded function isn't using the new value for the parameter to be changed (sigma.y). (Also, this solution wouldn't be useful for the goal of adding several curves on one plot via add=TRUE.) alpha.j.fun.general <- function(sigma.y.value) { sigma.y = sigma.y.value curve(alpha.j.fun, 2, 4, ylim = c(0,10), xlab="sigma.a values", ylab="alpha.j.hat") } Any suggestions much appreciated. David