R:如何从 x 的 cdplot 中获取条件概率?

发布于 2025-01-09 05:28:25 字数 239 浏览 1 评论 0原文

可重现的数据集:

a <- sample(45:3600, 500)
b <- sample(1:2, 500, replace=TRUE)
b <- factor(b, levels=c(1,2), labels=c("one", "two"))
CDP <- cdplot(b ~ a)

我想获得任何 x(本例中为任何“a”)的条件概率(以 0 到 1 之间的数字形式)。

Reproducible dataset:

a <- sample(45:3600, 500)
b <- sample(1:2, 500, replace=TRUE)
b <- factor(b, levels=c(1,2), labels=c("one", "two"))
CDP <- cdplot(b ~ a)

I would like to get the conditional probability (in the form of a number between 0 and 1) for any x (any "a" in this case).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

污味仙女 2025-01-16 05:28:25

如果我们将 cdplot 分配给一个对象(如问题中的 CDP),则该对象将变为 1 的列表,并且内容是 b 的第二级别的函数(“二”,在上述情况)。可以使用 $ 访问该函数,并且可以通过将 x 放在括号中来获得任何 x 的条件概率,例如:

CDP$two(1500)
[1] 0.5388164

If we assign the cdplot to an object (like to CDP in the question), this object becomes a list of 1 and the content is a function for the second level of b ("two", in the above case). The function can be accessed using $, and the conditional probability for any x can be obtained by putting x in the brackets, e.g.:

CDP$two(1500)
[1] 0.5388164
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文