r - Estimating the Standard Deviation of a ratio using Taylor expansion -


i interested build r function can use test limits of taylor series approximation. aware there limits doing, it's limits wish investigate.

i have 2 distributed random variables x , y. x has mean of 7 , standard deviation (sd) of 1. y has mean of 5 , sd of 4.

me.x <- 4; sd.x <- 1 me.y <- 5; sd.y <- 4 

i know how estimate mean ratio of y/x,

# e(y/x) = e(y)/e(x) - cov(y,x)/e(x)^2 + var(x)*e(y)/e(x)^3 me.y/me.x - 0/me.x^2 + sd.x*me.y/me.x^3 [1] 1.328125 

i stuck on how estimate standard deviation of ratio? realize have use taylor expansion, not how use it.

doing simple simulation

 x <- rnorm(10^4, mean = 4, sd = 1);  y <- rnorm(10^4, mean = 5, sd = 4)  sd(y/x)  [1] 2.027593  mean(y/x)[1]  1.362142 

there analytical expression pdf of ratio of 2 gaussians, done david hinkley (e.g. see wikipedia). compute momentums, means etc. typed , apparently doesn't have finite second momentum, doesn't have finite standard deviation. note, i've denoted y gaussian x, , x y (formulas assume x/y). i've got mean value of ratio pretty close you've got simulation, last integral infinite, sorry. sample more , more values, sampling std.dev growing well, noted @g.grothendieck

library(ggplot2)  m.x <- 5; s.x <- 4 m.y <- 4; s.y <- 1  <- function(x) {     sqrt( (x/s.x)^2 + (1.0/s.y)^2 ) }  b <- function(x) {     (m.x*x)/s.x^2 + m.y/s.y^2 }  c <- (m.x/s.x)^2 + (m.y/s.y)^2  d <- function(x) {     u <- b(x)^2 - c*a(x)^2     l <- 2.0*a(x)^2     exp( u / l ) }  # pdf ratio of 2 different gaussians pdf <- function(x) {     r <- b(x)/a(x)     q <- pnorm(r) - pnorm(-r)      (r*d(x)/a(x)^2) * (1.0/(sqrt(2.0*pi)*s.x*s.y)) * q + exp(-0.5*c)/(pi*s.x*s.y*a(x)^2) }  # normalization nn <- integrate(pdf, -inf, inf) nn <- nn[["value"]]  # plot pdf p <- ggplot(data = data.frame(x = 0), mapping = aes(x = x)) p <- p + stat_function(fun = function(x) pdf(x)/nn) + xlim(-2.0, 6.0) print(p)  # first momentum m1 <- integrate(function(x) x*pdf(x), -inf, inf) m1 <- m1[["value"]]  # mean print(m1/nn)  # sampling set.seed(32345) n <- 10^7l x <- rnorm(n, mean = m.x, sd = s.x); y <- rnorm(n, mean = m.y, sd = s.y) print(mean(x/y)) print(sd(x/y))  # second momentum - infinite! m2 <- integrate(function(x) x*x*pdf(x), -inf, inf) 

thus, impossible test taylor expansion std.dev.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -