-
Notifications
You must be signed in to change notification settings - Fork 0
/
sat_curve.R
36 lines (28 loc) · 988 Bytes
/
sat_curve.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#Function to predice Michaelis-Menten Kinetics
library(tidyverse)
library(broom)
MM_simplefit <- function(df, plot = TRUE){
#df should be a two column data frame with columns names 'rate' and 'conc'
df <- df
#Establish some values for fitting
Kstart <- max(df$conc)/2
Vstart <- max(df$rate)
#Fit the data
fit <- nls(rate ~ (V * conc)/(K + conc), data = df, start = list(K = Kstart, V = Vstart))
#Tidy the table
fitstats <- tidy(fit)
#make the fit data
mmfitdata <- data.frame(conc = seq(0, max(df$conc)*1.2, length.out = 200))
mmfitdata$rate <- predict(fit, newdata = mmfitdata)
if(plot == TRUE){
#make a plot
ggplot() +
geom_point(data = df, aes(x = conc, y = rate), color = "red") +
geom_line(data = mmfitdata, aes(x = conc, y = rate), colour = "black")
} else
{
return(fitstats)
}
}
df <- data_frame(conc = seq(0, 100, by = 10),
rate = c(0, 3, 6, 9, 12, 14, 15, 16, 17, 17.5, 18))