我使用社区发布的代码在R中绘制ccdf。在许多情况下,它工作正常,但是对于以下数据,其绘制的ccdf图从0.4开始而不是从1开始;有人可以帮忙吗?
x = c(50.76535,54.89802,74.12376,72.67228,50.76535,50.76535,50.76535,50.76535,50.76535,50.76535,72.67228,59.54455,72.67228,72.67228,72.67228,50.76535,50.76535,72.20198,50.76535,89.10891,50.76535,72.67228,50.76535,72.20198,50.76535,50.76535,50.76535)
plot(sort(x) , 1-ecdf(x)(sort(x) ), xlab = "x = log mean rain", ylab = "P(X > x)", pch = 1
, ylim = c(0,1),t='b', log = 'x')
答案 0 :(得分:1)
ecdf 从0开始。它是右连续的,并且在每个数据点处跳转。也就是说,它在min(x)
之前等于0,并且它的第一个跳转点是min(x)
:
x <- c(50.76535,54.89802,74.12376,72.67228,50.76535,50.76535,50.76535,50.76535,
50.76535,50.76535,72.67228,59.54455,72.67228,72.67228,72.67228,50.76535,
50.76535,72.20198,50.76535,89.10891,50.76535,72.67228,50.76535,72.20198,
50.76535,50.76535,50.76535)
Fn <- ecdf(x)
Fn(min(x) - 1)
# 0
Fn(min(x))
# 0.5555556
ecdf 及其补充功能是 step函数。当您执行 ecdf(x)时,您将获得一个步进函数。要定义互补的 ecdf ,您必须使用stepfun
:
jumps_at <- sort(unique(x))
CFn <- stepfun(jumps_at, c(1, 1-Fn(jumps_at)))
plot(CFn, xlab = "x = mean rain", ylab = "P(X > x)",
verticals = FALSE, pch = 19, ylim = c(0,1))