Re: [R] fitdistr for t distribution

2009-05-16 Thread Martin Maechler
 l == lagreene  lagreene...@gmail.com
 on Fri, 15 May 2009 04:22:59 -0700 (PDT) writes:

l Thanks Jorge,

l but I still don't understand where they come from.  when I use: 
l fitdistr(mydata, t, df = 9) and get values for m and s, and the 
variance
l of my data should be the df/s?

definitely *not*;  How did you get to this completely wrong formula?
 
l I jsut want to be able to confirm how m and s are calculated
 
by maximum likelihood.
And, of course, only for the normal (aka Gaussian) are the ML
estimates of mu the artithmetic mean and of sigma  (n-1)/n * sd(x)
{i.e. even *there* the ML estimate of s is *not* the SD}

As you can read on  ?dt,
the variance of a (0,1)-t-distribution is  df / (df - 2)
and hence only defined for df  2.
Consequently, the variance of a  (mu,sigma)-t-distribution is

   sigma^2 * df / (df - 2)

l mydt - function(x, m, s, df) dt((x-m)/s, df)/s
l fitdistr(x2, mydt, list(m = 0, s = 1), df = 9, lower = c(-Inf, 0))

{this is copy-pasted from example(dt);
 the examples have nice comments there}


l Jorge Ivan Velez wrote:
 
 Dear lagreene,
 See the second example in
 
 require(MASS)
 ?fitdistr
 
 HTH,
 
 Jorge
 
 
 On Thu, May 14, 2009 at 7:15 PM, lagreene lagreene...@gmail.com wrote:
 
 
 Hi,
 I was wondering if anyone could tell me how m and s are calculated for a
 t
 distribution?
 
 I thought m was the sample mean and s the standard deviation- but
 obviously
 I'm wrong as this doesn'y give the same answer.
 
 Thank you

__
R-help@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.


Re: [R] fitdistr for t distribution

2009-05-16 Thread Paul Johnson
On Fri, May 15, 2009 at 6:22 AM, lagreene lagreene...@gmail.com wrote:

 Thanks Jorge,

 but I still don't understand where they come from.  when I use:
 fitdistr(mydata, t, df = 9) and get values for m and s, and the variance
 of my data should be the df/s?

 I jsut want to be able to confirm how m and s are calculated

I've wondered the same kind of thing and I've learned the answer is
easy!  It is not so easy for all R functions, but did you try this
with fitdistr?

 library (MASS)
 fitdistr

the output that follows is the ACTUAL FORMULA that is used to make the
calculations!

I've not yet mastered the art of getting code for some functions.

 predict
function (object, ...)
UseMethod(predict)
environment: namespace:stats

But I know there is a way to get that code if you know the correct way
to run getS3method().  But I usually just go read the R source code
rather than puzzle over that.




 mydt - function(x, m, s, df) dt((x-m)/s, df)/s
 fitdistr(x2, mydt, list(m = 0, s = 1), df = 9, lower = c(-Inf, 0))

 Thanks anyway for the help!

-- 
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas

__
R-help@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.


Re: [R] fitdistr for t distribution

2009-05-16 Thread spencerg
 In addition to seeing the code by typing the name of the function 
(and copying it from there into a file), you can also enter 
debug(fitdistr), for example.  Then the next time you use fitdistr, 
either directly  or indirectly, it puts you in the environment of that 
function, and you can walk through it line by line, examining objects, 
changing them, etc. 



 To get the code for an S3 generic function like predict, use the 
methods function, followed, e.g., by getAnywhere. 



 Hope this helps. 
 Spencer Graves


Paul Johnson wrote:

On Fri, May 15, 2009 at 6:22 AM, lagreene lagreene...@gmail.com wrote:
  

Thanks Jorge,

but I still don't understand where they come from.  when I use:
fitdistr(mydata, t, df = 9) and get values for m and s, and the variance
of my data should be the df/s?

I jsut want to be able to confirm how m and s are calculated



I've wondered the same kind of thing and I've learned the answer is
easy!  It is not so easy for all R functions, but did you try this
with fitdistr?

  

library (MASS)
fitdistr



the output that follows is the ACTUAL FORMULA that is used to make the
calculations!

I've not yet mastered the art of getting code for some functions.

  

predict


function (object, ...)
UseMethod(predict)
environment: namespace:stats

But I know there is a way to get that code if you know the correct way
to run getS3method().  But I usually just go read the R source code
rather than puzzle over that.



  

mydt - function(x, m, s, df) dt((x-m)/s, df)/s
fitdistr(x2, mydt, list(m = 0, s = 1), df = 9, lower = c(-Inf, 0))

Thanks anyway for the help!






__
R-help@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.


Re: [R] fitdistr for t distribution

2009-05-15 Thread lagreene

Thanks Jorge,

but I still don't understand where they come from.  when I use: 
fitdistr(mydata, t, df = 9) and get values for m and s, and the variance
of my data should be the df/s?

I jsut want to be able to confirm how m and s are calculated

mydt - function(x, m, s, df) dt((x-m)/s, df)/s
fitdistr(x2, mydt, list(m = 0, s = 1), df = 9, lower = c(-Inf, 0))

Thanks anyway for the help!




Jorge Ivan Velez wrote:
 
  Dear lagreene,
 See the second example in
 
 require(MASS)
 ?fitdistr
 
 HTH,
 
 Jorge
 
 
 On Thu, May 14, 2009 at 7:15 PM, lagreene lagreene...@gmail.com wrote:
 

 Hi,
 I was wondering if anyone could tell me how m and s are calculated for a
 t
 distribution?

 I thought m was the sample mean and s the standard deviation- but
 obviously
 I'm wrong as this doesn'y give the same answer.

 Thank you
 --
 View this message in context:
 http://www.nabble.com/fitdistr-for-t-distribution-tp23550779p23550779.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@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.

 
   [[alternative HTML version deleted]]
 
 __
 R-help@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://www.nabble.com/fitdistr-for-t-distribution-tp23550779p23557778.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] fitdistr for t distribution

2009-05-14 Thread Jorge Ivan Velez
 Dear lagreene,
See the second example in

require(MASS)
?fitdistr

HTH,

Jorge


On Thu, May 14, 2009 at 7:15 PM, lagreene lagreene...@gmail.com wrote:


 Hi,
 I was wondering if anyone could tell me how m and s are calculated for a t
 distribution?

 I thought m was the sample mean and s the standard deviation- but obviously
 I'm wrong as this doesn'y give the same answer.

 Thank you
 --
 View this message in context:
 http://www.nabble.com/fitdistr-for-t-distribution-tp23550779p23550779.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@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.


[[alternative HTML version deleted]]

__
R-help@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.