简体   繁体   中英

Density Graph for Chi Square in R

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM