Wednesday, October 26, 2011
Plotting mathematical functions with curve
Simple mathematical functions can be plotted quickly with curve() to show their shape. Multiple curves can be overlain by including "add = TRUE" in the call to subsequent curves.
Example 1:
#Negative exponential, a common survival function
curve(exp(-0.5*x),xlim = c(0,10) , ylim = c(0,2), col = 4, lwd = 6, lty = 4)
#Ricker model, use in fisheries modeling
curve(2*x*exp(-0.5*x), add = TRUE, col = 2, lwd = 5, lty = 3)
#A legend with the appropriate colors, line types. "cex" increases the font size.
legend("topright", c("Neg exponential", "Ricker"), lty=c(4,3),col=c(4,2), bty="n", lwd = 5, cex =2)
Example 2:
#The logistic function
curve( exp(1*+ 1*x) / ( 1 + exp(1 + 1*x) ), xlim = c(-10,10) , ylim = c(0,2))
#Overlaying a Gompertz function
curve(1*exp(-1*exp(-2*x)), add = TRUE)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment