David LeBauer
2010-Jun-17 23:06 UTC
[R] is there a function to find the quantile of the mean of a vector?
Hello, I am interested in finding the quantile of the mean of a vector, something analogous to using the pnorm(), but for an mcmc chain instead of a distribution with known parameters. One approach would be to write a function that finds the index of x_i that minimizes (x-mean(x))^2 I suspect there is a function available to do this, but I can't find it? Thank you, David
Jorge Ivan Velez
2010-Jun-18 03:15 UTC
[R] is there a function to find the quantile of the mean of a vector?
Hi David, You might try:> set.seed(1) > x <- runif(10, 3, 7) > x[1] 4.062035 4.488496 5.291413 6.632831 3.806728 6.593559 6.778701 5.643191 5.516456 3.247145> (x-mean(x))^2[1] 1.308783661 0.514892188 0.007285983 2.035688832 1.958118177 1.925165288 2.473214156 [8] 0.191087609 0.096348590 3.837329960> which.min((x-mean(x))^2)[1] 3> x[which.min((x-mean(x))^2)][1] 5.291413> which.min(scale(x, scale = FALSE)**2)[1] 3 See ?which.min and ?scale for more information. HTH, Jorge On Thu, Jun 17, 2010 at 7:06 PM, David LeBauer <> wrote:> Hello, > > I am interested in finding the quantile of the mean of a vector, > something analogous to using the pnorm(), but for an mcmc chain > instead of a distribution with known parameters. > > One approach would be to write a function that finds the index of x_i > that minimizes (x-mean(x))^2 > > I suspect there is a function available to do this, but I can't find it? > > Thank you, > > David > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]