Reputation: 618
I'm trying to plot in R the graph of the density function of a Chi-Squared distribution with 28 df being the x higher to 7.5.
Until now I got this from what I've been able to gather around:
x <- pchisq(7.5, 28, lower.tail=FALSE)
hist(x, prob=TRUE)
curve( dchisq(x, df=28), col='red', main = "Chi-Square Density Graph")
But the plotting doesn't seem to work ._.
Upvotes: 1
Views: 12266
Reputation: 226332
I think you want:
curve( dchisq(x, df=28), col='red', main = "Chi-Square Density Graph",
from=0,to=60)
xvec <- seq(7.5,60,length=101)
pvec <- dchisq(xvec,df=28)
polygon(c(xvec,rev(xvec)),c(pvec,rep(0,length(pvec))),
col=adjustcolor("black",alpha=0.3))
In this case the graph is a little bit silly because almost all of the area under the curve is shaded -- the probability of x>7.5
is
pchisq(7.5,df=28,lower.tail=FALSE)
## [1] 0.9999611
Upvotes: 6