# functional forms for non-linear modeling # exponential functions a <- 1 b <- 1/10 curve( a*exp(b*x) , from=0 , to=20 , xlab="x" , ylab="y" ) a <- 2 curve( a*exp(b*x) , from=0 , to=20 , xlab="x" , ylab="y" , add=TRUE , col="red" ) a <- 1 b <- 1/20 curve( a*exp(b*x) , from=0 , to=20 , xlab="x" , ylab="y" , add=TRUE , col="blue" ) # negative exponential a <- 2 b <- 1/10 curve( a*(1-exp(-b*x)) , from=0 , to=20 , xlab="x" , ylab="y" ) a <- 1 curve( a*(1-exp(-b*x)) , from=0 , to=20 , xlab="x" , ylab="y" , add=TRUE , col="red" ) a <- 2 b <- 1/20 curve( a*(1-exp(-b*x)) , from=0 , to=20 , xlab="x" , ylab="y" , add=TRUE , col="blue" ) # grid of exponential functions a <- 2 b <- 1/10 par(mfrow=c(2,2)) curve( a*exp(b*x) , from=0 , to=20 , xlab="x" , ylab="y" , main="a*exp(b*x)" ) curve( a*(1-exp(-b*x)) , from=0 , to=20 , xlab="x" , ylab="y" , main="a*(1-exp(-b*x))" ) curve( a*exp(-b*x) , from=0 , to=20 , xlab="x" , ylab="y" , main="a*exp(-b*x)" ) curve( a*(1-exp(b*x)) , from=0 , to=20 , xlab="x" , ylab="y" , main="a*(1-exp(b*x))" ) # michaelis menten a <- 2 b <- 5 curve( a*x/(b+x) , from=0 , to=20 , xlab="x" , ylab="y" ) a <- 1 curve( a*x/(b+x) , from=0 , to=20 , xlab="x" , ylab="y" , add=TRUE , col="red" ) a <- 2 b <- 10 curve( a*x/(b+x) , from=0 , to=20 , xlab="x" , ylab="y" , add=TRUE , col="blue" ) # power law a <- 1 b <- 2 curve( a*x^b , from=0 , to=20, xlab="x" , ylab="y" ) a <- 2 curve( a*x^b , from=0 , to=20, xlab="x" , ylab="y" , col="red" , add=TRUE ) a <- 1 b <- 3 curve( a*x^b , from=0 , to=20, xlab="x" , ylab="y" , col="blue" , add=TRUE ) a <- 1 b <- 2 curve( a*x^b , from=0.1 , to=20, xlab="x" , ylab="y" , log="xy" ) a <- 2 curve( a*x^b , from=0.1 , to=20, xlab="x" , ylab="y" , col="red" , add=TRUE , log="xy" ) a <- 1 b <- 3 curve( a*x^b , from=0.1 , to=20, xlab="x" , ylab="y" , col="blue" , add=TRUE , log="xy" ) # ricker a <- 1 b <- -1/3 curve( a*x*exp(b*x) , from=0 , to=20 , xlab="x" , ylab="y" , ylim=c(0,2.5) ) a <- 2 b <- -1/3 curve( a*x*exp(b*x) , from=0 , to=20 , xlab="x" , ylab="y" , col="red" , add=TRUE ) a <- 1 b <- -1/5 curve( a*x*exp(b*x) , from=0 , to=20 , xlab="x" , ylab="y" , col="blue" , add=TRUE ) # tadpole predation exercise library(bbmle) library(emdbook) data(ReedfrogFuncresp) d <- ReedfrogFuncresp plot(d$Killed ~ d$Initial) d$freqkilled <- d$Killed/d$Initial plot(d$freqkilled ~ d$Initial) init <- c(5,10,15,20,30,50,75,100) mfk <- sapply( init , function(z) mean(d$freqkilled[d$Initial==z]) ) plot(mfk ~ init , ylim=c(0,1) , xlab="Initial number" , ylab="Average freq killed" )