【发布时间】:2021-01-13 14:42:12
【问题描述】:
我想将我的“经验”数据与理论逆卡方分布进行比较。如何绘制理论分布?
假设以下数据:
require(invgamma)
set.seed(10)
y<-rinvchisq(1000, 10)
这导致如下“经验”分布:
as.tibble(y) %>%
ggplot(aes(y)) +
geom_histogram(bins=100)
我的直觉告诉我,我应该使用dinvchisq-函数,它可以在invgamma 包中找到。但不能正确安装。有谁知道如何解决这个问题?
编辑:
感谢@marvinschmit 和@BenBolker 添加解决方案。
require(invgamma)
set.seed(10)
y = rinvchisq(1000, 10)
x = seq(0,1, by=.001)
d = invgamma::dinvchisq(x, df=10)
df = data.frame(x=x,d=d)
as.tibble(y) %>%
ggplot(aes(x = y)) +
geom_histogram(bins=100, aes(y=..density..)) +
geom_line(data = df, aes(x = x, y = d), color = "blue")
【问题讨论】:
标签: r probability distribution chi-squared