Debugging simple R code -


for homework assignment i'm constructing simple code. r keeps returning x0 missing in evaluating p2. can't figure out why, because seems specified correctly in 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 in advance!

regards, vincent

a workaround specify defaults alpha2 , x0, i've done below, r use these values if aren't specified.

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

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -