[R] plotting functions of chi square

maiya maja.zaloznik at gmail.com
Wed Aug 18 02:47:11 CEST 2010


OK, for the record, this is not my homework, thanks for asking!

Also, I am sure I could have phrased my question more eloquently, but (hence
the newbie qualifier) I didn't.  The code I posted was for the plot I want,
only smoothed i.e not based on random sampling from the distribution. 

Dennis: I tried that :) but your code divides the densities by df. I want
the density of X^2/df
Rookie: Same thing as David before - I know how to plot chi squared
densities with different dfs!
David: looks great! It's only the "playing around" that is off-putting...
(sorry again for not explaining well, but illustrate I definitely did!)

Ben & William: Thank you! Jointly you managed to plot exactly what I wanted
and show me why and how so I can do it to more complicated functions!

And just to prove you guys right, here's what I really wanted to plot - but
refrained from mentioning in my original post: how by the central limit
theorem for large df chi^2 approaches normality with a mean of df and
variance of 2*df. 

d2chisq <- function(x,df) {
  dchisq(x*sqrt(2*df)+df,df)*sqrt(2*df)
}

plot(1, type="n",  xlab="", ylab="", xlim=c(-3,3), ylim=c(0,0.5))

for (i in c(5,10,50,100,200,500)){
curve(d2chisq(x,i),add=TRUE)
}
lines(seq(-3,3,.1),dnorm(seq(-3,3,.1),0,1 ), col="red")

Not bad considering I had to look up the chain rule on Wikipedia ;)

Thanks again guys!

maja. 





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



More information about the R-help mailing list