[R] plotting functions of chi square

Ben Bolker bbolker at gmail.com
Tue Aug 17 23:41:42 CEST 2010


maiya <maja.zaloznik <at> gmail.com> writes:

> Thanks, but that wasn't what I was going for. Like I said, I know how to do a
> simple chi-square density plot with dchisq(). 
> 
> What I'm trying to do is chi-square / degrees of freedom. Hence
> rchisq(100000,i)/i).
> 
> How do I do that with dchisq?


  By explicitly using the formula to change variables:

plot(density(rchisq(10000,5)/5))

dscchisq <- function(x,df) {
  dchisq(x*df,df)*df
}
curve(dscchisq(x,5),add=TRUE,col=2)

  note that density() generates a smoothing artifact near zero ...



More information about the R-help mailing list