[R] Chi-Square Distribution Plots

John Fox jfox at mcmaster.ca
Mon Sep 30 14:30:31 CEST 2002


Dear Laura,

You can use the truehist function in the MASS package to draw a histogram 
with density scaling. Then calculate the chi-square densities, and add the 
density curve to the plot; something like:

     x <- seq(min(data), max(data), length=100)
     d <- dchisq(x, df)
     lines(x, d)

Of course, this requires that you know the degrees of freedom (replacing 
df). You may want to modify the range of plotted density values or change 
the range of the axes.

It is probably preferable to use a quantile-comparison plot rather than a 
histogram to visualize the fit of the data to the chi-square distribution. 
It's not hard to construct one yourself, but the qq.plot function in the 
car package makes this simple: qq.plot(data, 'chisq', df=df); the resulting 
plot includes a point-wise confidence envelope.

I hope that this helps,
  John

At 04:57 AM 9/30/2002 -0400, Bayesianbay at aol.com wrote:
>Dear list
>
>I have a vector of values that allegedly have a chi-squared distribution. I
>want to create a plot that shows the values I have obtained,  and the
>chi-squared distribution curve for the specified number of degrees of freedom
>to show what should have been obtained.
>
>At the moment I am plotting the values I have obtained as a histogram and
>somehow want to put on to this plot the expected frequency curve. Is there a
>way of doing this in R?
>
>Many thanks in davance
>Laura

-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list