R:如何从 x 的 cdplot 中获取条件概率?
可重现的数据集:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我们将 cdplot 分配给一个对象(如问题中的 CDP),则该对象将变为 1 的列表,并且内容是 b 的第二级别的函数(“二”,在上述情况)。可以使用 $ 访问该函数,并且可以通过将 x 放在括号中来获得任何 x 的条件概率,例如:
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.: