1

For a homework assignment I'm constructing a simple code. R keeps returning that a x0 is missing in evaluating p2. I can't figure out why, because it seems like I specified it correctly in the function Pareto.

lab1 <- 50; mu <- 1; sigma <- 1 alpha1 <- 1 ; beta1 <- 1 lab2 <- 3; mu <- 5; sigma <- 5 alpha2 <- (1+sqrt(2)); x0 <- (10- 5* sqrt(2)) ES1 <- lab1 * alpha1/beta1; VarS1 <- lab1 * alpha1/(beta1^2) ES2 <- lab2 * alpha2*x0/(alpha2-1); VarS2 <- lab2 * alpha2*x0^2/((alpha2-1)^2*(alpha2-2)) MM <- trunc(ES1 + ES2 + 10*sqrt(VarS1 + VarS2)) p1 <- pgamma((0:(MM-1)+0.5), alpha1, beta1) ##cdf p1 <- c(p1,1) - c(0,p1) ## pdf Pareto <- function (x, alpha2, x0) ifelse(x<x0 , 0, 1 - (x0/x)^alpha2) p2 <- integrate(Pareto, lower = 0, upper = (MM-1)+0.5) ##cdf p2 <- c(p2,1) - c(0,p2) ## pdf 

Many thanks in advance!

Regards, Vincent

2
  • Function Pareto is incomplete, what's with that? Commented May 13, 2013 at 21:04
  • I've changed it now. Don't know why it wasn't copied initially Commented May 13, 2013 at 21:07

2 Answers 2

2

It seems to me that you need to supply the arguments of your Pareto function within the integrate function. Like that

p2 <- integrate(Pareto, lower = 0, upper = (MM-1)+0.5, x0=x0, alpha2=alpha2) ##cdf 

And to access the value of after integrate you have to access it with the dollar sign

p2 <- c(p2$value,1) - c(0,p2$value) ## pdf 
Sign up to request clarification or add additional context in comments.

Comments

1

A workaround is to specify defaults for alpha2 and x0, as I've done below, so that R will use these values if they aren't specified.

Pareto <- function (x, alpha2 = (1+sqrt(2)), x0=(10- 5* sqrt(2))) ifelse(x<x0 , 0, 1 - (x0/x)^alpha2) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.