I want to compare my 'empirical' data with the theoretical inverse-chi-square distribution. How do I plot the theoretical distribution?
Assume the following data:
require(invgamma)
set.seed(10)
y<-rinvchisq(1000, 10)
which leads to an 'empitical' distribution as follows:
as.tibble(y) %>%
ggplot(aes(y)) +
geom_histogram(bins=100)
My gut tells me that I should use the dinvchisq-function that can be found in the invgamma package. But cannot fit it properly. Does anyone know how to tackle this matter?
EDIT:
Adding solution, thanks to @marvinschmit and @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")

