title: Derive standard error of a transformed variable in linear regression
body: <p>I would like to calculate the standard error of a transformed variable from my linear regression, i.e. divide two variables and get the standard error from this variable.</p>
  
  <p>I use the <code>deltamethod</code> function from the <code>msm</code> package, but fail to get accurate standard errors.</p>
  
  <p>For example:</p>
  
  <h1>Simulation of data:</h1>
  
  <pre><code>set.seed(123)
  nobs = 1000
  data &lt;- data.table(
    x1 = rnorm(nobs),
    x2 = rnorm(nobs),
    x3 = rnorm(nobs),
    x4 = rnorm(nobs),
    y = rnorm(nobs))
  </code></pre>
  
  <h1>Linear regression:</h1>
  
  <pre><code>reg2 &lt;- lm(y~x1+x2+x3+x4, data=data)
  </code></pre>
  
  <h1>Get the coef and vcov (Here I need to get rid of the missings, as some coefficients in my real data are NA and I calculate a lot of regressions in loop)</h1>
  
  <pre><code>vcov_reg &lt;- vcov(reg2)
  
  coef_reg &lt;- coef(reg2)
  coef_reg &lt;- na.omit(coef_reg) 
  coef_reg &lt;- as.numeric(coef_reg)
  </code></pre>
  
  <h1>Deltamethod, for the the variable x1 divided by x3 (meaning I should use x2 and x4 according to the msm package):</h1>
  
  <pre><code>deltamethod(~ x2/x4, coef_reg, vcov_reg)
  </code></pre>
  
  <p>This gives me a standard error of the transformed variable (x1/x3) of 3.21, while all standard errors from this regression are around 0.03. </p>
  
  <p>Any idea's why/what's wrong here?
  Other suggestions to calculate it are also welcome.</p>