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 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hi On 30 Sep 2002 at 4:57, 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?after making histogram something like lines(density(rchisq(number,deg.f))) could help, where number is number of generated points and deg.f is selected degrees of freedom> > Many thanks in davance > Laura > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. > -.-.-.-.- 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. > _._._._._RegardsPetr Pikal petr.pikal at precheza.cz p.pik at volny.cz -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
How about something like (untested) curve(dchisq(x,df=df),add=TRUE) [you'll need to make sure that you've plotted your histogram with freq=FALSE] On Mon, 30 Sep 2002 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 > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-- 318 Carr Hall bolker at zoo.ufl.edu Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker Box 118525 (ph) 352-392-5697 Gainesville, FL 32611-8525 (fax) 352-392-3704 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Suppose your chi-squared values witrh, let us say, 5 degrees of freedom are in x. You need to make the histogram with the argument probability=TRUE first. Then:> x <- rchisq(1000, 5) > hist(x, prob=TRUE) > plot( function(x) dchisq(x, df=5), from=0, to=35, add=TRUE)Kjetil Halvorsen 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 > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 2002-09-30 at 03:57, 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?Of course. I assume a qqplot is what you are looking for. Use something like this line: qqplot(qchisq(ppoints(375), df=9), actual.values) This puts the expected distribution on the x-axis, and the empirical distribution on the y-axix. Change the number of data points (375) and the degrees of freedom (9) to values appropriate to your data. -- Stuart Luppescu -=- s-luppescu at uchicago.edu University of Chicago -=- CCSR $B:MJ8$HCRF`H~$NIc(B -=- Kernel 2.4.19-xfs-r1 Somebody's terminal is dropping bits. I found a pile of them over in the corner. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : https://stat.ethz.ch/pipermail/r-help/attachments/20020930/1af0527e/attachment.bin