Hi, R users: I want to fit my data into a normal distribution by using the command "fitdistr" in "MASS". I changed my data class from "ts" to "numeric" by>class(mydata)="numeric"but after using "fitdistr", I got the result below>fitdistr(mydata,"normal")mean sd NA NA (NA) (NA) the help doc of "fitdistr" does not mention anything about that, thus I need your help. Thank you in advanced, Saji from Shanghai -- View this message in context: http://n4.nabble.com/Help-with-function-fitdistr-in-MASS-tp997609p997609.html Sent from the R help mailing list archive at Nabble.com.
I check my data again, and find that: 1. when the class of "mydata" is ts, I can't compute the sd of it. R returns 'NA'. 2. when I change the class from ts into numeric, R still can't compute the sd of the data. Any suggestion? -- View this message in context: http://n4.nabble.com/Help-with-function-fitdistr-in-MASS-tp997609p997612.html Sent from the R help mailing list archive at Nabble.com.
And when I used the command below:>fitdistr(mydata, "normal", na.rm=TRUE)the result is still the same. -- View this message in context: http://n4.nabble.com/Help-with-function-fitdistr-in-MASS-tp997609p997615.html Sent from the R help mailing list archive at Nabble.com.
Please read the footer of this message. ?fitdistr says x: A numeric vector. and setting the class does not make it a numeric vector (it is just a label). And fitdistr early on does if (missing(x) || length(x) == 0L || mode(x) != "numeric") stop("'x' must be a non-empty numeric vector") so you do have a non-empty numeric vector. It is likely that your data contains NAs, in which case the quoted result is correct. But despite the posting guide we have no details of your 'mydata' and have to guess. On Sat, 2 Jan 2010, Saji Ren wrote:> > Hi, R users: > > I want to fit my data into a normal distribution by using the command > "fitdistr" in "MASS". > I changed my data class from "ts" to "numeric" by > >> class(mydata)="numeric" > > but after using "fitdistr", I got the result below > >> fitdistr(mydata,"normal") > mean sd > NA NA > (NA) (NA) > > the help doc of "fitdistr" does not mention anything about that, thus I need > your help.The help page is not intended to be a very basic statistics/R textbook.> Thank you in advanced, > Saji from Shanghai > -- > View this message in context: http://n4.nabble.com/Help-with-function-fitdistr-in-MASS-tp997609p997609.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
On Sat, 2010-01-02 at 23:20 -0800, Saji Ren wrote:> Hi, R users: > > I want to fit my data into a normal distribution by using the command > "fitdistr" in "MASS". > I changed my data class from "ts" to "numeric" by > > >class(mydata)="numeric" > > but after using "fitdistr", I got the result below > > >fitdistr(mydata,"normal") > mean sd > NA NA > (NA) (NA) > > the help doc of "fitdistr" does not mention anything about that, thus I need > your help. > > Thank you in advanced, > Saji from ShanghaiHi Sajj, You hava NA in your data try: fitdistr(na.exclude(mydata),"normal") -- Bernardo Rangel Tura, M.D,MPH,Ph.D National Institute of Cardiology Brazil
Thank you,man. the problem solved. Plus. when I got the parameters of the data. And I used the "truehist(mydata)" to get a histogram of the data, How can I draw a line of the distribution of the estimated parameters in the histogram plot? for example:>fitdistr(na.exclude(mydata),"normal")mean sd 4.052594 75.620350 ( 1.420743) ( 1.004617)>truehist(mydata)After that, I got the histogram of mydata. And I want plot a extra line of the density of a normal distribution of mean=4.052594 and sd=75.620350 in the histogram plot? thank you Bernardo Rangel tura wrote:> > On Sat, 2010-01-02 at 23:20 -0800, Saji Ren wrote: >> Hi, R users: >> >> I want to fit my data into a normal distribution by using the command >> "fitdistr" in "MASS". >> I changed my data class from "ts" to "numeric" by >> >> >class(mydata)="numeric" >> >> but after using "fitdistr", I got the result below >> >> >fitdistr(mydata,"normal") >> mean sd >> NA NA >> (NA) (NA) >> >> the help doc of "fitdistr" does not mention anything about that, thus I >> need >> your help. >> >> Thank you in advanced, >> Saji from Shanghai > > Hi Sajj, > > You hava NA in your data > > try: fitdistr(na.exclude(mydata),"normal") > > -- > Bernardo Rangel Tura, M.D,MPH,Ph.D > National Institute of Cardiology > Brazil > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > >-- View this message in context: http://n4.nabble.com/Help-with-function-fitdistr-in-MASS-tp997609p998258.html Sent from the R help mailing list archive at Nabble.com.
Saji Ren wrote:> Thank you,man. the problem solved. > Plus. when I got the parameters of the data. > And I used the "truehist(mydata)" to get a histogram of the data, > How can I draw a line of the distribution of the estimated parameters in the > histogram plot? > > for example: >> fitdistr(na.exclude(mydata),"normal") > mean sd > 4.052594 75.620350 > ( 1.420743) ( 1.004617) >> truehist(mydata) > > After that, I got the histogram of mydata. > And I want plot a extra line of the density of a normal distribution of > mean=4.052594 and sd=75.620350 in the histogram plot?add this: curve(dnorm(x, mean=4.052594, sd=75.620350), add=TRUE) -Peter Ehlers> > thank you > > > > Bernardo Rangel tura wrote: >> On Sat, 2010-01-02 at 23:20 -0800, Saji Ren wrote: >>> Hi, R users: >>> >>> I want to fit my data into a normal distribution by using the command >>> "fitdistr" in "MASS". >>> I changed my data class from "ts" to "numeric" by >>> >>>> class(mydata)="numeric" >>> but after using "fitdistr", I got the result below >>> >>>> fitdistr(mydata,"normal") >>> mean sd >>> NA NA >>> (NA) (NA) >>> >>> the help doc of "fitdistr" does not mention anything about that, thus I >>> need >>> your help. >>> >>> Thank you in advanced, >>> Saji from Shanghai >> Hi Sajj, >> >> You hava NA in your data >> >> try: fitdistr(na.exclude(mydata),"normal") >> >> -- >> Bernardo Rangel Tura, M.D,MPH,Ph.D >> National Institute of Cardiology >> Brazil >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> >-- Peter Ehlers University of Calgary 403.202.3921