Easy error propagation in R

[This article was first published on Odd Hypothesis, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

In a previous post I demonstrated how to use R’s simple built-in symbolic engine to generate Jacobian and (pseudo)-Hessian matrices that make non-linear optimization perform much more efficiently. Another related application is Gaussian error propagation.

Say you have data from a set of measurements in variables x and y where you know the corresponding measurement errors (dx and dy, typically the standard deviation or error from a set of replicates or a calibration curve). Next you want to create a derived value defined by an arbitrary function z = f(x,y). What would the corresponding error in value of z, i.e. dz = df, be?

If the function f(x,y) is a simple sum or product, their are simple equations for determining df. However, if f(x,y) is something more complex, like:

z=f(x,y)=xy(x+y)2

you’ll need to use a bit of calculus, specifically the chain rule:

df=(dxfx)2+(dyfy)2+...

Applying the above equation allows for the derivation of Gaussian error propagation for any arbitrary function. So how does one do this in R? Again, the D() function and R expression() objects come to our rescue.

Say the definition of z (ergo f(x,y)) is defined in an R formula:

<span class="pun">></span><span class="pln"> f </span><span class="pun">=</span><span class="pln"> z </span><span class="pun">~</span><span class="pln"> </span><span class="pun">(</span><span class="pln">x</span><span class="pun">-</span><span class="pln">y</span><span class="pun">)/(</span><span class="pln">x</span><span class="pun">+</span><span class="pln">y</span><span class="pun">)^</span><span class="lit">2</span>

If you probe the structure of a formula object you get:

<span class="pun">></span><span class="pln"> str</span><span class="pun">(</span><span class="pln">f</span><span class="pun">)</span><span class="pln"><br /></span><span class="typ">Class</span><span class="pln"> </span><span class="str">'formula'</span><span class="pln"> length </span><span class="lit">3</span><span class="pln"> z </span><span class="pun">~</span><span class="pln"> </span><span class="pun">(</span><span class="pln">x </span><span class="pun">-</span><span class="pln"> y</span><span class="pun">)/(</span><span class="pln">x </span><span class="pun">+</span><span class="pln"> y</span><span class="pun">)^</span><span class="lit">2</span><span class="pln"><br />  </span><span class="pun">..-</span><span class="pln"> attr</span><span class="pun">(*,</span><span class="pln"> </span><span class="str">".Environment"</span><span class="pun">)=<</span><span class="pln">environment</span><span class="pun">:</span><span class="pln"> R_GlobalEnv</span><span class="pun">></span>

What’s key is the “length 3” bit:

<span class="pun">></span><span class="pln"> f</span><span class="pun">[[</span><span class="lit">1</span><span class="pun">]];</span><span class="pln"> f</span><span class="pun">[[</span><span class="lit">2</span><span class="pun">]];</span><span class="pln"> f</span><span class="pun">[[</span><span class="lit">3</span><span class="pun">]]</span><span class="pln"><br /></span><span class="str">`~`</span><span class="pln"><br />z<br /></span><span class="pun">(</span><span class="pln">x </span><span class="pun">-</span><span class="pln"> y</span><span class="pun">)/(</span><span class="pln">x </span><span class="pun">+</span><span class="pln"> y</span><span class="pun">)^</span><span class="lit">2</span>

The code above shows us that a formula object can be subsetted into its constituent parts:

  1. the formula operator: ~
  2. the left-hand side (LHS) of the formula: z
  3. the right-hand side (RHS) of the formula: (x - y)/(x + y)^2

The class() of the RHS is a call, which is close enough to an R expression that both all.vars() and D() work as expected to generate the mathematical expressions for the partial derivatives with respect to each variable:

<span class="pun">></span><span class="pln"> all</span><span class="pun">.</span><span class="pln">vars</span><span class="pun">(</span><span class="pln">f</span><span class="pun">[[</span><span class="lit">3</span><span class="pun">]])</span><span class="pln"><br /></span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="str">"x"</span><span class="pln"> </span><span class="str">"y"</span><span class="pln"><br /><br /></span><span class="pun">></span><span class="pln"> lapply</span><span class="pun">(</span><span class="pln">all</span><span class="pun">.</span><span class="pln">vars</span><span class="pun">(</span><span class="pln">f</span><span class="pun">[[</span><span class="lit">3</span><span class="pun">]]),</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">(</span><span class="pln">v</span><span class="pun">)</span><span class="pln"> D</span><span class="pun">(</span><span class="pln">f</span><span class="pun">[[</span><span class="lit">3</span><span class="pun">]],</span><span class="pln"> v</span><span class="pun">))</span><span class="pln"><br /></span><span class="pun">[[</span><span class="lit">1</span><span class="pun">]]</span><span class="pln"><br /></span><span class="lit">1</span><span class="pun">/(</span><span class="pln">x </span><span class="pun">+</span><span class="pln"> y</span><span class="pun">)^</span><span class="lit">2</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> </span><span class="pun">(</span><span class="pln">x </span><span class="pun">-</span><span class="pln"> y</span><span class="pun">)</span><span class="pln"> </span><span class="pun">*</span><span class="pln"> </span><span class="pun">(</span><span class="lit">2</span><span class="pln"> </span><span class="pun">*</span><span class="pln"> </span><span class="pun">(</span><span class="pln">x </span><span class="pun">+</span><span class="pln"> y</span><span class="pun">))/((</span><span class="pln">x </span><span class="pun">+</span><span class="pln"> y</span><span class="pun">)^</span><span class="lit">2</span><span class="pun">)^</span><span class="lit">2</span><span class="pln"><br /><br /></span><span class="pun">[[</span><span class="lit">2</span><span class="pun">]]</span><span class="pln"><br /></span><span class="pun">-(</span><span class="lit">1</span><span class="pun">/(</span><span class="pln">x </span><span class="pun">+</span><span class="pln"> y</span><span class="pun">)^</span><span class="lit">2</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> </span><span class="pun">(</span><span class="pln">x </span><span class="pun">-</span><span class="pln"> y</span><span class="pun">)</span><span class="pln"> </span><span class="pun">*</span><span class="pln"> </span><span class="pun">(</span><span class="lit">2</span><span class="pln"> </span><span class="pun">*</span><span class="pln"> </span><span class="pun">(</span><span class="pln">x </span><span class="pun">+</span><span class="pln"> y</span><span class="pun">))/((</span><span class="pln">x </span><span class="pun">+</span><span class="pln"> y</span><span class="pun">)^</span><span class="lit">2</span><span class="pun">)^</span><span class="lit">2</span><span class="pun">)</span>

These expressions need to be modified a bit – i.e. in this case they need to be multiplied by dx and dy, respectively and then squared. What’s returned from D() is a call object, so the elements above need to be converted to character to manipulate them accordingly. This is done with deparse().

<span class="pun">></span><span class="pln"> lapply</span><span class="pun">(</span><span class="pln">all</span><span class="pun">.</span><span class="pln">vars</span><span class="pun">(</span><span class="pln">f</span><span class="pun">[[</span><span class="lit">3</span><span class="pun">]]),</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">(</span><span class="pln">v</span><span class="pun">)</span><span class="pln"> deparse</span><span class="pun">(</span><span class="pln">D</span><span class="pun">(</span><span class="pln">f</span><span class="pun">[[</span><span class="lit">3</span><span class="pun">]],</span><span class="pln"> v</span><span class="pun">)))</span><span class="pln"><br /></span><span class="pun">[[</span><span class="lit">1</span><span class="pun">]]</span><span class="pln"><br /></span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="str">"1/(x + y)^2 - (x - y) * (2 * (x + y))/((x + y)^2)^2"</span><span class="pln"><br /><br /></span><span class="pun">[[</span><span class="lit">2</span><span class="pun">]]</span><span class="pln"><br /></span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="str">"-(1/(x + y)^2 + (x - y) * (2 * (x + y))/((x + y)^2)^2)"</span>

The final error propagation expression is created with a bit of string manipulation:

<span class="pun">></span><span class="pln"> sprintf</span><span class="pun">(</span><span class="str">'sqrt(%s)'</span><span class="pun">,</span><span class="pln"> <br />    paste</span><span class="pun">(</span><span class="pln"><br />        sapply</span><span class="pun">(</span><span class="pln">all</span><span class="pun">.</span><span class="pln">vars</span><span class="pun">(</span><span class="pln">f</span><span class="pun">[[</span><span class="lit">3</span><span class="pun">]]),</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">(</span><span class="pln">v</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br />            sprintf</span><span class="pun">(</span><span class="str">'(d%s*(%s))^2'</span><span class="pun">,</span><span class="pln"> v</span><span class="pun">,</span><span class="pln"> deparse</span><span class="pun">(</span><span class="pln">D</span><span class="pun">(</span><span class="pln">f</span><span class="pun">[[</span><span class="lit">3</span><span class="pun">]],</span><span class="pln"> v</span><span class="pun">)))</span><span class="pln"><br />        </span><span class="pun">}),</span><span class="pln"> <br />        collapse</span><span class="pun">=</span><span class="str">'+'</span><span class="pln"><br />    </span><span class="pun">)</span><span class="pln"><br />  </span><span class="pun">)</span><span class="pln"><br /></span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="str">"sqrt((dx*(1/(x + y)^2 - (x - y) * (2 * (x + y))/((x + y)^2)^2))^2+(dy*(-(1/(x + y)^2 + (x - y) * (2 * (x + y))/((x + y)^2)^2)))^2)"</span>

Now that we’ve got the basics down, let’s test this out with some data …

<span class="pun">></span><span class="pln"> </span><span class="kwd">set</span><span class="pun">.</span><span class="pln">seed</span><span class="pun">(</span><span class="lit">0</span><span class="pun">)</span><span class="pln"><br /></span><span class="pun">></span><span class="pln"> data </span><span class="pun">=</span><span class="pln"> data</span><span class="pun">.</span><span class="pln">frame</span><span class="pun">(</span><span class="pln"><br />    x  </span><span class="pun">=</span><span class="pln"> runif</span><span class="pun">(</span><span class="lit">5</span><span class="pun">),</span><span class="pln"> <br />    y  </span><span class="pun">=</span><span class="pln"> runif</span><span class="pun">(</span><span class="lit">5</span><span class="pun">),</span><span class="pln"> <br />    dx </span><span class="pun">=</span><span class="pln"> runif</span><span class="pun">(</span><span class="lit">5</span><span class="pun">)/</span><span class="lit">10</span><span class="pun">,</span><span class="pln"> <br />    dy </span><span class="pun">=</span><span class="pln"> runif</span><span class="pun">(</span><span class="lit">5</span><span class="pun">)/</span><span class="lit">10</span><span class="pln"><br />  </span><span class="pun">)</span><span class="pln"><br /></span><span class="pun">></span><span class="pln"> data<br />          x         y          dx         dy<br /></span><span class="lit">1</span><span class="pln"> </span><span class="lit">0.8966972</span><span class="pln"> </span><span class="lit">0.2016819</span><span class="pln"> </span><span class="lit">0.006178627</span><span class="pln"> </span><span class="lit">0.07698414</span><span class="pln"><br /></span><span class="lit">2</span><span class="pln"> </span><span class="lit">0.2655087</span><span class="pln"> </span><span class="lit">0.8983897</span><span class="pln"> </span><span class="lit">0.020597457</span><span class="pln"> </span><span class="lit">0.04976992</span><span class="pln"><br /></span><span class="lit">3</span><span class="pln"> </span><span class="lit">0.3721239</span><span class="pln"> </span><span class="lit">0.9446753</span><span class="pln"> </span><span class="lit">0.017655675</span><span class="pln"> </span><span class="lit">0.07176185</span><span class="pln"><br /></span><span class="lit">4</span><span class="pln"> </span><span class="lit">0.5728534</span><span class="pln"> </span><span class="lit">0.6607978</span><span class="pln"> </span><span class="lit">0.068702285</span><span class="pln"> </span><span class="lit">0.09919061</span><span class="pln"><br /></span><span class="lit">5</span><span class="pln"> </span><span class="lit">0.9082078</span><span class="pln"> </span><span class="lit">0.6291140</span><span class="pln"> </span><span class="lit">0.038410372</span><span class="pln"> </span><span class="lit">0.03800352</span>

and with a little help from dplyr:

<span class="pun">></span><span class="pln"> library</span><span class="pun">(</span><span class="pln">dplyr</span><span class="pun">)</span><span class="pln"><br /></span><span class="pun">></span><span class="pln"> data </span><span class="pun">%>%</span><span class="pln"><br /></span><span class="pun">+</span><span class="pln">   mutate_</span><span class="pun">(.</span><span class="pln">dots</span><span class="pun">=</span><span class="pln">list</span><span class="pun">(</span><span class="pln"><br /></span><span class="pun">+</span><span class="pln">     </span><span class="com"># compute derived value</span><span class="pln"><br /></span><span class="pun">+</span><span class="pln">     z  </span><span class="pun">=</span><span class="pln"> deparse</span><span class="pun">(</span><span class="pln">f</span><span class="pun">[[</span><span class="lit">3</span><span class="pun">]]),</span><span class="pln"><br /></span><span class="pun">+</span><span class="pln">     <br /></span><span class="pun">+</span><span class="pln">     </span><span class="com"># generates a mathematical expression to compute dz</span><span class="pln"><br /></span><span class="pun">+</span><span class="pln">     </span><span class="com"># as a character string</span><span class="pln"><br /></span><span class="pun">+</span><span class="pln">     dz </span><span class="pun">=</span><span class="pln"> sapply</span><span class="pun">(</span><span class="pln">all</span><span class="pun">.</span><span class="pln">vars</span><span class="pun">(</span><span class="pln">f</span><span class="pun">[[</span><span class="lit">3</span><span class="pun">]]),</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">(</span><span class="pln">v</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br /></span><span class="pun">+</span><span class="pln">             dfdp </span><span class="pun">=</span><span class="pln"> deparse</span><span class="pun">(</span><span class="pln">D</span><span class="pun">(</span><span class="pln">f</span><span class="pun">[[</span><span class="lit">3</span><span class="pun">]],</span><span class="pln"> v</span><span class="pun">))</span><span class="pln"><br /></span><span class="pun">+</span><span class="pln">             sprintf</span><span class="pun">(</span><span class="str">'(d%s*(%s))^2'</span><span class="pun">,</span><span class="pln"> v</span><span class="pun">,</span><span class="pln"> dfdp</span><span class="pun">)</span><span class="pln"><br /></span><span class="pun">+</span><span class="pln">           </span><span class="pun">})</span><span class="pln"> </span><span class="pun">%>%</span><span class="pln"><br /></span><span class="pun">+</span><span class="pln">           paste</span><span class="pun">(</span><span class="pln">collapse</span><span class="pun">=</span><span class="str">'+'</span><span class="pun">)</span><span class="pln"> </span><span class="pun">%>%</span><span class="pln"><br /></span><span class="pun">+</span><span class="pln">           sprintf</span><span class="pun">(</span><span class="str">'sqrt(%s)'</span><span class="pun">,</span><span class="pln"> </span><span class="pun">.)</span><span class="pln"><br /></span><span class="pun">+</span><span class="pln">       </span><span class="pun">))</span><span class="pln"><br />          x         y          dx         dy           z         dz<br /></span><span class="lit">1</span><span class="pln"> </span><span class="lit">0.8966972</span><span class="pln"> </span><span class="lit">0.2016819</span><span class="pln"> </span><span class="lit">0.006178627</span><span class="pln"> </span><span class="lit">0.07698414</span><span class="pln">  </span><span class="lit">0.57608929</span><span class="pln"> </span><span class="lit">0.14457245</span><span class="pln"><br /></span><span class="lit">2</span><span class="pln"> </span><span class="lit">0.2655087</span><span class="pln"> </span><span class="lit">0.8983897</span><span class="pln"> </span><span class="lit">0.020597457</span><span class="pln"> </span><span class="lit">0.04976992</span><span class="pln"> </span><span class="pun">-</span><span class="lit">0.46718831</span><span class="pln"> </span><span class="lit">0.03190297</span><span class="pln"><br /></span><span class="lit">3</span><span class="pln"> </span><span class="lit">0.3721239</span><span class="pln"> </span><span class="lit">0.9446753</span><span class="pln"> </span><span class="lit">0.017655675</span><span class="pln"> </span><span class="lit">0.07176185</span><span class="pln"> </span><span class="pun">-</span><span class="lit">0.33019871</span><span class="pln"> </span><span class="lit">0.01978697</span><span class="pln"><br /></span><span class="lit">4</span><span class="pln"> </span><span class="lit">0.5728534</span><span class="pln"> </span><span class="lit">0.6607978</span><span class="pln"> </span><span class="lit">0.068702285</span><span class="pln"> </span><span class="lit">0.09919061</span><span class="pln"> </span><span class="pun">-</span><span class="lit">0.05778613</span><span class="pln"> </span><span class="lit">0.07604809</span><span class="pln"><br /></span><span class="lit">5</span><span class="pln"> </span><span class="lit">0.9082078</span><span class="pln"> </span><span class="lit">0.6291140</span><span class="pln"> </span><span class="lit">0.038410372</span><span class="pln"> </span><span class="lit">0.03800352</span><span class="pln">  </span><span class="lit">0.11809201</span><span class="pln"> </span><span class="lit">0.02424023</span>

Taking this a step further, this method can be wrapped in a chainable function that determines the name of new variables from the LHS of a formula argument:

<span class="pln">mutate_with_error </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">(.</span><span class="pln">data</span><span class="pun">,</span><span class="pln"> f</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br />  exprs </span><span class="pun">=</span><span class="pln"> list</span><span class="pun">(</span><span class="pln"><br />      </span><span class="com"># expression to compute new variable values</span><span class="pln"><br />      deparse</span><span class="pun">(</span><span class="pln">f</span><span class="pun">[[</span><span class="lit">3</span><span class="pun">]]),</span><span class="pln"><br /><br />      </span><span class="com"># expression to compute new variable errors</span><span class="pln"><br />      sapply</span><span class="pun">(</span><span class="pln">all</span><span class="pun">.</span><span class="pln">vars</span><span class="pun">(</span><span class="pln">f</span><span class="pun">[[</span><span class="lit">3</span><span class="pun">]]),</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">(</span><span class="pln">v</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br />        dfdp </span><span class="pun">=</span><span class="pln"> deparse</span><span class="pun">(</span><span class="pln">D</span><span class="pun">(</span><span class="pln">f</span><span class="pun">[[</span><span class="lit">3</span><span class="pun">]],</span><span class="pln"> v</span><span class="pun">))</span><span class="pln"><br />        sprintf</span><span class="pun">(</span><span class="str">'(d%s*(%s))^2'</span><span class="pun">,</span><span class="pln"> v</span><span class="pun">,</span><span class="pln"> dfdp</span><span class="pun">)</span><span class="pln"><br />      </span><span class="pun">})</span><span class="pln"> </span><span class="pun">%>%</span><span class="pln"><br />        paste</span><span class="pun">(</span><span class="pln">collapse</span><span class="pun">=</span><span class="str">'+'</span><span class="pun">)</span><span class="pln"> </span><span class="pun">%>%</span><span class="pln"><br />        sprintf</span><span class="pun">(</span><span class="str">'sqrt(%s)'</span><span class="pun">,</span><span class="pln"> </span><span class="pun">.)</span><span class="pln"><br />  </span><span class="pun">)</span><span class="pln"><br />  names</span><span class="pun">(</span><span class="pln">exprs</span><span class="pun">)</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> c</span><span class="pun">(</span><span class="pln"><br />    deparse</span><span class="pun">(</span><span class="pln">f</span><span class="pun">[[</span><span class="lit">2</span><span class="pun">]]),</span><span class="pln"><br />    sprintf</span><span class="pun">(</span><span class="str">'d%s'</span><span class="pun">,</span><span class="pln"> deparse</span><span class="pun">(</span><span class="pln">f</span><span class="pun">[[</span><span class="lit">2</span><span class="pun">]]))</span><span class="pln"><br />  </span><span class="pun">)</span><span class="pln"><br /><br />  </span><span class="pun">.</span><span class="pln">data </span><span class="pun">%>%</span><span class="pln"><br />    </span><span class="com"># the standard evaluation alternative of mutate()</span><span class="pln"><br />    mutate_</span><span class="pun">(.</span><span class="pln">dots</span><span class="pun">=</span><span class="pln">exprs</span><span class="pun">)</span><span class="pln"><br /></span><span class="pun">}</span>

Thus, adding new derived variables and propagating errors accordingly becomes relatively easy:

<span class="pun">></span><span class="pln"> </span><span class="kwd">set</span><span class="pun">.</span><span class="pln">seed</span><span class="pun">(</span><span class="lit">0</span><span class="pun">)</span><span class="pln"><br /></span><span class="pun">></span><span class="pln"> data </span><span class="pun">=</span><span class="pln"> data</span><span class="pun">.</span><span class="pln">frame</span><span class="pun">(</span><span class="pln">x</span><span class="pun">=</span><span class="pln">runif</span><span class="pun">(</span><span class="lit">5</span><span class="pun">),</span><span class="pln"> y</span><span class="pun">=</span><span class="pln">runif</span><span class="pun">(</span><span class="lit">5</span><span class="pun">),</span><span class="pln"> dx</span><span class="pun">=</span><span class="pln">runif</span><span class="pun">(</span><span class="lit">5</span><span class="pun">)/</span><span class="lit">10</span><span class="pun">,</span><span class="pln"> dy</span><span class="pun">=</span><span class="pln">runif</span><span class="pun">(</span><span class="lit">5</span><span class="pun">)/</span><span class="lit">10</span><span class="pun">)</span><span class="pln"><br /></span><span class="pun">></span><span class="pln"> data<br />          x         y          dx         dy<br /></span><span class="lit">1</span><span class="pln"> </span><span class="lit">0.8966972</span><span class="pln"> </span><span class="lit">0.2016819</span><span class="pln"> </span><span class="lit">0.006178627</span><span class="pln"> </span><span class="lit">0.07698414</span><span class="pln"><br /></span><span class="lit">2</span><span class="pln"> </span><span class="lit">0.2655087</span><span class="pln"> </span><span class="lit">0.8983897</span><span class="pln"> </span><span class="lit">0.020597457</span><span class="pln"> </span><span class="lit">0.04976992</span><span class="pln"><br /></span><span class="lit">3</span><span class="pln"> </span><span class="lit">0.3721239</span><span class="pln"> </span><span class="lit">0.9446753</span><span class="pln"> </span><span class="lit">0.017655675</span><span class="pln"> </span><span class="lit">0.07176185</span><span class="pln"><br /></span><span class="lit">4</span><span class="pln"> </span><span class="lit">0.5728534</span><span class="pln"> </span><span class="lit">0.6607978</span><span class="pln"> </span><span class="lit">0.068702285</span><span class="pln"> </span><span class="lit">0.09919061</span><span class="pln"><br /></span><span class="lit">5</span><span class="pln"> </span><span class="lit">0.9082078</span><span class="pln"> </span><span class="lit">0.6291140</span><span class="pln"> </span><span class="lit">0.038410372</span><span class="pln"> </span><span class="lit">0.03800352</span><span class="pln"><br /><br /></span><span class="pun">></span><span class="pln"> data </span><span class="pun">%>%</span><span class="pln"> mutate_with_error</span><span class="pun">(</span><span class="pln">z </span><span class="pun">~</span><span class="pln"> </span><span class="pun">(</span><span class="pln">x</span><span class="pun">-</span><span class="pln">y</span><span class="pun">)/(</span><span class="pln">x</span><span class="pun">+</span><span class="pln">y</span><span class="pun">)^</span><span class="lit">2</span><span class="pun">)</span><span class="pln"><br />          x         y          dx         dy           z         dz<br /></span><span class="lit">1</span><span class="pln"> </span><span class="lit">0.8966972</span><span class="pln"> </span><span class="lit">0.2016819</span><span class="pln"> </span><span class="lit">0.006178627</span><span class="pln"> </span><span class="lit">0.07698414</span><span class="pln">  </span><span class="lit">0.57608929</span><span class="pln"> </span><span class="lit">0.14457245</span><span class="pln"><br /></span><span class="lit">2</span><span class="pln"> </span><span class="lit">0.2655087</span><span class="pln"> </span><span class="lit">0.8983897</span><span class="pln"> </span><span class="lit">0.020597457</span><span class="pln"> </span><span class="lit">0.04976992</span><span class="pln"> </span><span class="pun">-</span><span class="lit">0.46718831</span><span class="pln"> </span><span class="lit">0.03190297</span><span class="pln"><br /></span><span class="lit">3</span><span class="pln"> </span><span class="lit">0.3721239</span><span class="pln"> </span><span class="lit">0.9446753</span><span class="pln"> </span><span class="lit">0.017655675</span><span class="pln"> </span><span class="lit">0.07176185</span><span class="pln"> </span><span class="pun">-</span><span class="lit">0.33019871</span><span class="pln"> </span><span class="lit">0.01978697</span><span class="pln"><br /></span><span class="lit">4</span><span class="pln"> </span><span class="lit">0.5728534</span><span class="pln"> </span><span class="lit">0.6607978</span><span class="pln"> </span><span class="lit">0.068702285</span><span class="pln"> </span><span class="lit">0.09919061</span><span class="pln"> </span><span class="pun">-</span><span class="lit">0.05778613</span><span class="pln"> </span><span class="lit">0.07604809</span><span class="pln"><br /></span><span class="lit">5</span><span class="pln"> </span><span class="lit">0.9082078</span><span class="pln"> </span><span class="lit">0.6291140</span><span class="pln"> </span><span class="lit">0.038410372</span><span class="pln"> </span><span class="lit">0.03800352</span><span class="pln">  </span><span class="lit">0.11809201</span><span class="pln"> </span><span class="lit">0.02424023</span>

Written with StackEdit.

To leave a comment for the author, please follow the link and comment on their blog: Odd Hypothesis.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)