0

I have plotted a ccdf graph of some of my simulated power-law tail data and would like to find a best fit line from my ccdf graph. I used the code from the link (http://www.net.t-labs.tu-berlin.de/~fabian/sources/plot.ccdf.R) and plotted my ccdf graph.

plot.ccdf <- function (data, log = "xy", xlab = "x", ylab = "CCDF(x)", xlim
= F, ymin = 0, sample.it=F, sample.count = 100, col = 1, cex = 1) 
{
if ( length(dim(data)) > 0) {
    cat ("Attention input is a matrix! Usign all values in it!")
}
x <- sort(data)

if ( (log == "xy") || ( log == "y")) {
if ( ymin == 0) {
    min = ceiling(log10(length(x)))
} else {
    min = ceiling(log10(1/ymin))
}
    ylab.at = (1/(10^(0:min)))
    ylab.lab = ylab.at
    yrange = c(min(ylab.at),1)
} else {
    ylab.at = 0:10/10
    ylab.lab = ylab.at
    yrange = c(0,1)
}

if ( length(xlim) != 2) {
if ( (log == "xy") || (log == "x")) { 
    minx.log = x[ x>0 ][1]
    xlim = c(minx.log, max(x)) 
} else {
    xlim = c(min(x), max(x))
}
}

cat( "yrange: ", yrange, "| xrange: ", xlim, "\n")
plot(1,1, log=log, xlab = xlab, ylab = ylab, 
ylim = yrange, xlim = xlim, axes = F, type = 'n')
add.ccdf(data, col = col, sample.it = sample.it, sample.count = sample.count, cex = cex)
axis(1)
axis(2, at = ylab.at, labels = ylab.lab)
box()
grid()
}

add.ccdf <- function (data, col = 2, sample.it = F, sample.count = 100, cex = 1) 
{
if ( length(dim(data)) > 0) {
    cat ("Attention input is a matrix! Usign all values in it!")
}

x <- sort(data)
y <- 1-((1:(length(x))-1)/length(x))

xmin <- min(x)
xmax <- max(x)
ymin <- min(y)
ymax <- max(y)

if (sample.it) {
if ( par("ylog") == T ) {
    ymarks <- 10^(seq(from=log10(ymin), to = log10(ymax), length.out=sample.count))
} else {
    ymarks <- seq(from=ymin, to = ymax, length.out=sample.count)
}


if ( par("xlog") == T ) { 
    xsbr <- 10^(seq(from=log10(xmin), to = log10(xmax), length.out=sample.count))
} else {
    xsbr <- seq(from=xmin, to = xmax, length.out=sample.count)
}
xmarks <- cumsum(table(cut(x, breaks = xsbr, labels = F)))
}

if ( sample.it ){
points(x= quantile(data, probs = 1-ymarks, type =2), y = ymarks, col = col, pch =      col, cex = cex)
points(x[xmarks], y[xmarks], col=col, pch = col, cex = cex)
} else {
points(x,y,col = col, pch = col, cex = cex)
}
}  

plot.ccdf(fakedata5000)
yrange:  1e-04 1 | xrange:  0.5000282 26980.13 

but whenever I try to fit my data to a linear regression using the lm() command, it contains the error message:

res=lm(plot.ccdf(fakedata5000))
yrange:  1e-04 1 | xrange:  0.5000282 26980.13 
Error in terms.formula(formula, data = data) : 
  argument is not a valid model

Does anyone know the method of getting a linear regression line from a plotted ccdf modle? thanks a lot!

user3579282
  • 35
  • 2
  • 9

0 Answers0