kyong park
2012-Dec-06 18:14 UTC
[R] Get an expected value for Order Statistics by applying double integrals
Hi R users, I’d like to get an expected value for a minimum value from order statistics of sample size, say, 5 for standard normal distribution, and the formula would be 5* Integral (from -inf to Inf) x*f(x)* (1-F(x))^4,where f(x) and F(x) are a standard normal density and a cumulative distribution function respectively. After searching R posts, I applied the following double integral formula which gave an error message saying “the integral is probably divergent.” integrate(function(y){ + sapply(y,function(y){ + integrate(function(x)5*y*(1/sqrt(2*pi))*exp(-y^2/2)*(1-(1/sqrt(2*pi))*exp(-x^2/2))^4,-Inf,y)$value}) + },-Inf,Inf) I’m not sure whether the syntax is correct or not. Appreciate your help. Kyong [[alternative HTML version deleted]]
Thomas Stewart
2012-Dec-06 20:41 UTC
[R] Get an expected value for Order Statistics by applying double integrals
Kyong- It isn't clear to me why are you using a double integral. You have the pdf and your goal is to calculate the expected value of a univariate random variable (the first order statistic). Shouldn't the expected value be E[X_(1)] = int x * 5 * f(x) * (1-F(x))^4 dx? A single integral? Here are two different numerical techniques to calculate the expected value. -tgs fff <- function(x) 5 * x * dnorm(x) * (1 - pnorm(x))^4 integrate(fff,-Inf,Inf) M <- 100000 N <- 5 D <- matrix(rnorm(M*N),nrow=M) mean(apply(D,1,min)) On Thu, Dec 6, 2012 at 1:14 PM, kyong park <kpypark@gmail.com> wrote:> Hi R users, > > > > I’d like to get an expected value for a minimum value from order > statistics of sample size, say, 5 for standard normal distribution, and the > formula would be 5* Integral (from -inf to Inf) x*f(x)* (1-F(x))^4,where > f(x) and F(x) are a standard normal density and a cumulative distribution > function respectively. After searching R posts, I applied the following > double integral formula which gave an error message saying “the integral is > probably divergent.” > > > > integrate(function(y){ > > > > + sapply(y,function(y){ > > > > + > > integrate(function(x)5*y*(1/sqrt(2*pi))*exp(-y^2/2)*(1-(1/sqrt(2*pi))*exp(-x^2/2))^4,-Inf,y)$value}) > > > > + },-Inf,Inf) > > > > I’m not sure whether the syntax is correct or not. Appreciate your help. > > > > Kyong > > [[alternative HTML version deleted]] > > > ______________________________________________ > 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]]
Maybe Matching Threads
- A function for random test based on longest run (UNCLASSI FIED)
- Importing an Excel file
- Retrieving an evaluated gradient value (UNCLASSIFIED)
- A function for random test based on longest run (UNCLASSIFIED)
- Lme does not work without a random effect (UNCLASSIFIED)