title: Removing Outliers 3SDs from the mean of a monoexponetial function in R
body: <p>I have a large data set that analyzes exercising subjects' oxygen consumption over time (x= Time, y = VO2). This data fits a monoexponential function.</p>
  <p>Here is a brief, sample data frame:</p>
  <p>'''</p>
  <pre><code> VO2 &lt;- c(11.71,9.84,17.96,18.87,14.58,13.38,5.89,20.28,20.03,31.17,22.07,30.29,29.08,32.89,29.01,29.21,32.42,25.47,30.51,37.86,23.48,40.27,36.25,19.34,36.53,35.19,22.45,30.23,3,19.48,25.35,22.74)
   Time &lt;- c(0,2,27,29,31,33,39,77,80,94,99,131,133,134,135,149,167,170,177,178,183,184,192,222,239,241,244,245,250,251,255,256)
   DF &lt;- data.frame(VO2,Time)
  </code></pre>
  <p>'''
  <a href="https://i.stack.imgur.com/JybFu.png" rel="nofollow noreferrer">visual representation of the data -- * note that this data set is much smaller (and therefore might not fit a function as well) as the full data set.</a></p>
  <p>I am somewhat new to R and very much not a mathematical expert. I would appreciate your help with the two goals of this data set.
  Based on typical conventions of the laboratory I work in, this data should be fit to a monoexponential function</p>
  <ol>
  <li><p>I would love some insight into fitting data to a function such as this. Note that I have many similar data sets (for different subjects) and need to fit a monoexponential function to each of them. It would be best if fit could be applied generically across my data sets.</p>
  </li>
  <li><p>Based on this monoexponential function, I would like to identify and remove any outlying points. Here I will define an outlier as any point &gt;3 standard deviations from the mean of the monoexponential function.</p>
  </li>
  </ol>
  <p>So far, I have this (unsuccessful) code to fit a function to the above data. Not only does it not fit well, but I am also unable to create a smooth function.</p>
  <p>'''</p>
  <pre><code> fit &lt;- lm(VO2~poly(Time,2,raw=TRUE))
   xx &lt;- seq(1,250, length=32)
   plot(Time,VO2,pch=19,ylim=c(0,50))+
   lines(xx, predict(fit, data.frame(DF=xx)), col=&quot;red&quot;)
  </code></pre>
  <p>'''</p>
  <p>Thank you to all the individuals who have commented and provided their valuable feedback. As I continue to learn and research, I will add to this post with successful/less successful attempts at the code for this process. Thank you for your knowledge, assistance and understanding.</p>