[R] plotting functions of chi square

David Winsemius dwinsemius at comcast.net
Wed Aug 18 00:19:39 CEST 2010


On Aug 17, 2010, at 5:28 PM, maiya wrote:

>
> 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?

Maybe you should explain what you are trying to achieve or illustrate?  
X^2/df is not a verb, hence one cannot "do" it. If you want to plot a  
chi-square density on a scaled x-axis then you should say so. Let's  
assume for a moment that my guess is correct, ... then this would be  
the first cut:

plot(1, type="n",  xlab="", ylab="", xlim=c(0,2), ylim=c(0,1e-2))
for (i in c(10,50,100,200,500)){
lines(seq(0,2, by=0.01), dchisq(seq(0,2*i, 0.01*i),i)/i)
                                }

Notice that the peak heights are gradually spreading out. You will  
need a vertical factor that increases as some function of "i" in front  
of that dchisq().

Playing around with the ylims and scaling factors produces:

plot(1, type="n",  xlab="", ylab="", xlim=c(0,2), ylim=c(0,.1))
for (i in c(10,50,100,200,500)){
lines(seq(0,2, by=0.01), i*dchisq(seq(0,2*i, 0.01*i),i)/i)
}

Using i^2 as a vertical scaling factor :

plot(1, type="n",  xlab="", ylab="", xlim=c(0,2), ylim=c(0,10))
for (i in c(10,50,100,200,500)){
lines(seq(0,2, by=0.01), i^2*dchisq(seq(0,2*i, 0.01*i),i)/i)
                               }


Now, just what is it that you are trying to do? Or have I just done  
someone's homework again?


> -- 
> View this message in context: http://r.789695.n4.nabble.com/plotting-functions-of-chi-square-tp2329020p2329057.html
> Sent from the R help mailing list archive at Nabble.com.
>
-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list