Question

Let's say I want to plot some values of the Michaelis-Menten (or any other) function. Yet, not exactly the values but the values with a normally distributed error.

I have come up with the following code. Is there anything more direct?

f<-function(x,a,b){a*x/(1+b*x)}
datax<-seq(1:10)
datay<-f(datax,2,3)
errors<-rnorm(10,0,0.01)
datayerrors<-datay+errors
plot(datax,datayerrors) 
Was it helpful?

Solution

You could build the errors into the function and really should not use seq(1:10) ... either seq(1,10) or 1:10 .... I once had a nasty bug from that one.

 f<-function(x,a,b){a*x/(1+b*x) + rnorm(length(x), 0, .01) }
 plot( 1:10, f(1:10) )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top