Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Variance of a ratio with unknown covariance between numerator and denominator

    I have two means and their standard errors from a paper. I would like to calculate their ratio and its variance, but I don't have the covariance. But if I could make some assumptions about the correlation and proceed from there by backing out the covariance, I can get a range of estimates. Theory suggests that the correlation is positive. I implemented this approach with the Delta Method and also Fieller's method on some fake data:

    #delimit;
    clear;
    set obs 21;
    egen rho = seq(), from(-10) to(10);
    replace rho = rho/10;

    scalar dR = 1026;
    scalar dS = 305;
    scalar var_dR = 2026^2;
    scalar var_dS = 40^2;

    gen cov = rho*sqrt(scalar(var_dR))*sqrt(scalar(var_dS));
    gen roas = scalar(dR)/scalar(dS);

    /* Delta Method */
    gen var_roas = ((scalar(dR)^2)/(scalar(dS)^4))*scalar(var_dS)
    + (1/(scalar(dS)^2))*scalar(var_dR)
    - 2*((scalar(dR))/(scalar(dS)^3))*cov;
    gen roas_lb = roas - 1.96*sqrt(var_roas);
    gen roas_ub = roas + 1.96*sqrt(var_roas);

    /* Fieller's Method */
    scalar t2 = invt(28,.95);
    scalar aa = (scalar(dS)^2) - (scalar(var_dS)*scalar(t2)^2);
    gen bb = (2*cov*scalar(t2)^2) - (2*scalar(dR)*scalar(dS));
    scalar cc = (scalar(dR)^2) - (var_dR*scalar(t2)^2);
    gen rad = sqrt(bb*bb - 4*aa*cc);
    gen fi_lb = (-bb - rad) / (2 * aa);
    gen fi_ub = (-bb + rad) / (2 * aa);

    tw
    (line roas rho, lcolor(navy))
    (line roas_ub rho, lpattern(dash) lcolor(navy))
    (line roas_lb rho, lpattern(dash) lcolor(navy))
    (line fi_ub rho, lpattern(dash) lcolor(maroon))
    (line fi_lb rho, lpattern(dash) lcolor(maroon))
    , legend(label(1 "ROAS") label(2 "Delta Method CI") label(5 "Fieller's Method CI") order(1 2 5) rows(1) span)
    xlab(#10, grid) ylab(#10, angle(0) grid)
    yline(0, lpattern(solid) lcolor(gs5))
    xtitle("Correlation Between dR and dS")
    title("dR/dS Ratio With 95% Confidence Interval")
    plotregion(fcolor(white) lcolor(white)) graphregion(fcolor(white) lcolor(white));
    I am little puzzled by why the intervals look so different, and I am uncertain if I specified t2 correctly (the means are based on 28 days of data).

    Am I doing something stupid here? Is there any way to do something like this better (with tighter bounds)?

  • #2
    Have you compared your two methods (delta and Fieller) with the CI you'd obtain if you bootstrapped the process?

    Comment


    • #3
      John Mullahy I am not sure how I would bootstrap here since I don’t have the original data or code, only the four moments. I suppose I could draw from two normals with those parameters while varying the correlation. Is that what you had in mind here?

      Comment


      • #4
        I tried to implement the bootstrap solution:

        Code:
        #delimit;
        clear;
        set obs 21;
        egen rho = seq(), from(-10) to(10);
        replace rho = rho/10;
        
        scalar dR     = 1026;
        scalar dS     = 305;
        scalar var_dR = 2026^2; 
        scalar var_dS = 40^2;
        
        gen cov = rho*sqrt(scalar(var_dR))*sqrt(scalar(var_dS));
        gen roas = scalar(dR)/scalar(dS);
        
        /* Delta Method */
        gen var_roas = ((scalar(dR)^2)/(scalar(dS)^4))*scalar(var_dS)
                       + (1/(scalar(dS)^2))*scalar(var_dR)
                       - 2*((scalar(dR))/(scalar(dS)^3))*cov;
        gen roas_lb = roas - 1.96*sqrt(var_roas);
        gen roas_ub = roas + 1.96*sqrt(var_roas);
        
        /* Fieller's Method */
        scalar t2 = invt(28,.95);
        scalar aa = (scalar(dS)^2) - (scalar(var_dS)*scalar(t2)^2);
        gen bb    = (2*cov*scalar(t2)^2) - (2*scalar(dR)*scalar(dS));
        scalar cc = (scalar(dR)^2) - (var_dR*scalar(t2)^2);
        gen rad   = sqrt(bb*bb - 4*aa*cc);
        gen fi_lb = (-bb - rad) / (2 * aa);
        gen fi_ub = (-bb + rad) / (2 * aa);
        
        
        /* Bootstrap Medhod */
        gen bs_lb =.;
        gen bs_ub =.;
        
        foreach rho of numlist -1(.1)1 {;
        
            preserve;
            
                clear;
                scalar rho =`rho';
                scalar cov    = scalar(rho)*sqrt(scalar(var_dR))*sqrt(scalar(var_dS));
                matrix V      = [scalar(var_dR), scalar(cov) \ //
                                 scalar(cov), scalar(var_dS)];
                                 
                qui corr2data dR dS, n(10000) means(`=scalar(dR)' `=scalar(dS)') cov(V) double clear;
                // corr dR dS, cov means;
                qui gen roas = dR/dS;
                qui _pctile roas, percentile(2.5 97.5);
            
            restore;
                
            qui replace bs_lb = r(r1);
            qui replace bs_ub = r(r2);
            
        };
        
        
        local graph_roas: display %9.1f scalar(roas);
        
        tw 
        (line roas rho, lcolor(dkorange) lwidth(medthick))
        (line roas_ub rho, lpattern(dash) lcolor(navy))
        (line roas_lb rho, lpattern(dash) lcolor(navy))
        (line fi_ub rho, lpattern(dash) lcolor(maroon))
        (line fi_lb rho, lpattern(dash) lcolor(maroon))
        (line bs_ub rho, lpattern(dash) lcolor(forest_green))
        (line bs_lb rho, lpattern(dash) lcolor(forest_green))
        , legend(label(1 "ROAS") label(2 "Delta Method") label(5 "Fieller") label(7 "Bootstrap") 
            order(1 2 5 7) rows(1) span)
        xlab(#10, grid) ylab(#8 `graph_roas',  angle(0) grid)
        yline(0, lpattern(solid) lcolor(gs5))
        xtitle("Correlation Between dR and dS")
        ytitle("ROAS")
        title("Implied Ratio With 95% Confidence Intervals")
        plotregion(fcolor(white) lcolor(white)) graphregion(fcolor(white) lcolor(white)) 
        name(roas, replace);
        The graph looks like this:

        Click image for larger version

Name:	Screen Shot 2020-11-07 at 12.38.21 PM.png
Views:	1
Size:	91.0 KB
ID:	1580765

        The shrinkage in BS CI is there but very small. I am not sure what I take away from this.

        Comment

        Working...
        X