我已经绘制了一些我的模拟幂律尾数据的ccdf图,并希望从我的ccdf图中找到最佳拟合线。我使用了链接中的代码(http://www.net.t-labs.tu-berlin.de/~fabian/sources/plot.ccdf.R)并绘制了我的ccdf图。
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
但每当我尝试使用lm()命令将数据拟合到线性回归时,它都包含错误消息:
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
有人知道从绘制的ccdf模型中获取线性回归线的方法吗?非常感谢!