Skip to content

Instantly share code, notes, and snippets.

@jebyrnes
Created August 18, 2013 21:59
Show Gist options
  • Select an option

  • Save jebyrnes/6264240 to your computer and use it in GitHub Desktop.

Select an option

Save jebyrnes/6264240 to your computer and use it in GitHub Desktop.
Multifunc Michaelis-Menten
library(multifunc)
#A function to get mm coefs
mmCoef <- function(adf){
options(warn=2)
mod <- try(nls(funcMaxed~Vm*Diversity/(K+Diversity), start=list(Vm=1, K=5),
data=adf))
options(warn=0)
#if there was a problem, catch it and just return NAs for this coefficient
if("try-error" %in% class(mod)) return(rep(NA, 4))
out <- c(coef(mod), coef(summary(mod))[,2])
names(out) <- c("Vm", "K", "se.Vm", "se.K")
out
}
#see ?getFuncsMaxed for code to generate germanyThresh
mmGermany <- ddply(germanyThresh, "thresh", mmCoef)
ggplot(mmGermany, aes(x=thresh, y=K, ymin=K-1.96*se.K, ymax=K+1.96*se.K)) +
geom_ribbon(fill="grey50", alpha=0.8) +
geom_point() +
theme_bw() +
stat_hline(yintercept=0, lwd=2, lty=2)
ggplot(mmGermany, aes(x=thresh, y=Vm, ymin=Vm-1.96*se.Vm, ymax=Vm+1.96*se.Vm)) +
geom_ribbon(fill="grey50", alpha=0.8) +
geom_point() +
theme_bw() +
stat_hline(yintercept=0, lwd=2, lty=2)
#see the vignette on how to generate bdThreshes
mmBD <- ddply(bdThreshes,c("location", "thresholds"), mmCoef)
ggplot(mmBD, aes(x=thresholds, y=K, ymin=K-1.96*se.K, ymax=K+1.96*se.K)) +
#geom_ribbon(fill="grey50", alpha=0.8) +
geom_point() +
theme_bw() +
stat_hline(yintercept=0, lwd=2, lty=2) +
facet_wrap(~location) +
ylim(c(-1,16))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment