0

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 ._.

Strinnityk
  • 548
  • 1
  • 5
  • 17
  • Perhaps helpful: http://r.789695.n4.nabble.com/How-to-plot-a-normal-distribution-curve-and-a-shaded-tail-with-alpha-td3032194.html – Ben Bolker May 26 '14 at 01:15

1 Answers1

5

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
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453