Matej Cepl
2002-Oct-14 21:20 UTC
[R] Another newbie question: curve of normal distribution
I would like to get a curve of normal distrubtion over the histogram. Something like the following (which obviously doesn't work; see attached example). maluj <- function() { vrhy=read.csv("pennies.csv",head=TRUE) hf=table(vrhy$HEADS) postscript("heads.eps",onefile=FALSE,width=4.134,height=3.445,pointsize=12) plot(hf,main="Frequency distribution of heads",xlab="Throws", ylab="Frequency") lines(rnorm(length(hf),mean=mean(hf),sd=sd(hf))) dev.off(2) } Any help, please? Thanks Matej -- Matej Cepl, matej at ceplovi.cz, PGP ID# D96484AC 138 Highland Ave. #10, Somerville, Ma 02143, (617) 623-1488 understand, v.: To reach a point, in your investigation of some subject, at which you cease to examine what is really present, and operate on the basis of your own internal model instead. -------------- next part -------------- A non-text attachment was scrubbed... Name: heads.eps Type: application/postscript Size: 5242 bytes Desc: not available Url : https://stat.ethz.ch/pipermail/r-help/attachments/20021014/b203f123/heads.eps
Uwe Ligges
2002-Oct-15 06:52 UTC
[R] Another newbie question: curve of normal distribution
Matej Cepl wrote:> > I would like to get a curve of normal distrubtion over the > histogram. Something like the following (which obviously doesn't > work; see attached example). > > maluj <- function() { > > vrhy=read.csv("pennies.csv",head=TRUE) > > hf=table(vrhy$HEADS) > postscript("heads.eps",onefile=FALSE,width=4.134,height=3.445,pointsize=12) > plot(hf,main="Frequency distribution of heads",xlab="Throws", > ylab="Frequency") > lines(rnorm(length(hf),mean=mean(hf),sd=sd(hf)))Try curve(function(x) dnorm(x, mean=mean(hf), sd=sd(hf)), add = TRUE, from = min(hf) to = max(hf)) Uwe Ligges> dev.off(2) > > } > > Any help, please? > > Thanks > > Matej > > -- > Matej Cepl, matej at ceplovi.cz, PGP ID# D96484AC > 138 Highland Ave. #10, Somerville, Ma 02143, (617) 623-1488 > > understand, v.: > To reach a point, in your investigation of some subject, > at which you cease to examine what is really present, and > operate on the basis of your own internal model instead. > > ------------------------------------------------------------------------ > Name: heads.eps > heads.eps Type: Postscript Document (application/postscript) > Encoding: quoted-printable-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Matej Cepl
2002-Oct-15 17:17 UTC
[R] Another newbie question: curve of normal distribution
On Tue, Oct 15, 2002 at 08:33:43AM +0000, Renaud Lancelot wrote:> Hi Matej, > > heads <- rbinom(n = 100, size = 40, p = .5) ### simulated data > X <- quantile(heads, probs = seq(.001, .999, length = 1000)) > Y <- dnorm(X, mean = mean(heads), sd = sqrt(var(heads))) > hist(heads, probability = T) > lines(X, Y, col = "red")Thanks, that's exactly what I need -- sorry for not explaining better. Matej -- Matej Cepl, matej at ceplovi.cz, PGP ID# D96484AC 138 Highland Ave. #10, Somerville, Ma 02143, (617) 623-1488 [W]hat country can preserve its liberties, if its rulers are not warned from time to time that [the] people preserve the spirit of resistance? Let them take arms...The tree of liberty must be refreshed from time to time, with the blood of patriots and tyrants. -- Thomas Jefferson, letter to Col. William S. Smith, 1787 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : https://stat.ethz.ch/pipermail/r-help/attachments/20021015/9c50a1cd/attachment.bin