如何绘制“反转"使用 ECDF 的累积频率图 [英] How to Plot "Reverse" Cumulative Frequency Graph With ECDF

查看:28
本文介绍了如何绘制“反转"使用 ECDF 的累积频率图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

绘制以下累积频率图没有问题像这样.

I have no problem plotting the following cumulative frequency graph plot like this.

     library(Hmisc)
     pre.test <- rnorm(100,50,10)
     post.test <- rnorm(100,55,10)
     x <- c(pre.test, post.test)
     g <- c(rep('Pre',length(pre.test)),rep('Post',length(post.test)))
     Ecdf(x, group=g, what="f", xlab='Test Results', label.curves=list(keys=1:2))

但我想以值 > x 的反向"累积频率的形式显示图形.(即相当于 what="1-f").

But I want to show the graph in forms of the "reverse" cumulative frequency of values > x. (i.e. something equivalent to what="1-f").

有办法吗?

在 R 中除了使用 Hmisc 之外的其他建议也非常受欢迎.

Other suggestions in R other than using Hmisc are also very much welcomed.

推荐答案

使用 Musa 建议:

Using Musa suggestion:

pre.ecdf <- ecdf(pre.test)
post.ecdf <- ecdf(post.test)

r <- range(pre.test,post.test)
curve(1-pre.ecdf(x), from=r[1], to=r[2], col="red", xlim=r)
curve(1-post.ecdf(x), from=r[1], to=r[2], col="blue", add=TRUE)

您可以设置一些参数,如标题、图例等

You could set some parameters like title, legend, etc.

如果你想要频率而不是比例,简单的解决方案是:

If you want frequency instead of proportion simple solution will be:

pre.ecdf <- ecdf(pre.test)
post.ecdf <- ecdf(post.test)

rx <- range(pre.test,post.test)
ry <- max(length(pre.test),length(post.test))
curve(length(pre.test)*(1-pre.ecdf(x)), from=rx[1], to=rx[2], col="red", xlim=rx, ylim=c(0,ry))
curve(length(post.test)*(1-post.ecdf(x)), from=rx[1], to=rx[2], col="blue", add=TRUE)

这篇关于如何绘制“反转"使用 ECDF 的累积频率图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆