简体   繁体   English

如何计算R和plot中的1-CDF呢?

[英]How to calculate 1-CDF in R and plot it?

I want to plot the 1-CDF in R我想要 plot R 中的 1-CDF

I am using the ggplot stat_ecdf我正在使用 ggplot stat_ecdf

g1=ggplot() +
  stat_ecdf(data=data_ploting, aes(x, colour=ggg), alpha=0.8, geom= "smooth", pad = FALSE) +
  theme_test ()

The base R function ecdf returns a function that you can use in new expressions, including subtracting it from one.基数 R function ecdf返回一个 function,您可以在新表达式中使用它,包括从一个表达式中减去它。 You can therefore also use the usual methods for plotting $1-F(x)$.因此,您也可以使用常用方法绘制 $1-F(x)$。 Example:例子:

x <- sort(iris$Sepal.Length)
cdf <- ecdf(x)
plot(x, 1 - cdf(x), type="s")

The ?stat_ecdf help page shows that there is a "Computed variable" y which holds the calculated CDF value. ?stat_ecdf帮助页面显示有一个“计算变量” y保存计算的 CDF 值。 You can get at that value using stat() and then transform it however you like.您可以使用stat()获取该值,然后根据需要对其进行转换。 So, for example, this should work因此,例如,这应该有效

ggplot(data_ploting) +
  aes(x = x, y = 1-stat(y), colour=ggg) + 
  stat_ecdf(alpha=0.8, geom = "smooth", pad = FALSE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM