Skip to content

(no subject)

3 messages · Jim Silverton, Pascal Oettli, William Dunlap

#
Hello,

The value for 'start' is not correct. According to the help for
"fitdistr", 'start' should contain the paramaters used by the random
function (?rchisq)

Hope this helps,
Pascal
On 20 November 2013 09:29, Jim Silverton <jim.silverton at gmail.com> wrote:

  
    
#
First, it would  be nice if your mail had a subject line and you showed
the error message you got from this command.
I got:
  > z <- fitdistr(y, "chi-squared", start = list(4), method="Brent", lower=0.9, upper=3)
  > z
  Error in dn[[2L]] : subscript out of bounds
  > str(z)
  List of 5
   $ estimate: num 1
   $ sd      : num 0.00286
   $ vcov    : num [1, 1] 8.16e-06
   $ loglik  : num -79007
   $ n       : int 100000
   - attr(*, "class")= chr "fitdistr"
showing that the error was in the printing of the result, not in computing
the result.

There are a few problems here.  First, the print method assumes that the
optimizer attaches parameter names to the parameter vector.  Second,
optim(method="Brent") does not attach a name to its output parameter the
way the other optimization method do (I suppose that is because it only
works on univariate problems.)  Third, you didn't supply a parameter name
in 'start'.

You can get a printable answer by using the default method and supplying
a name for the parameter.
   > zz <- fitdistr(y, "chi-squared", start = list(df=4), lower=0.9, upper=3)
   > zz
          df     
     1.003840114 
    (0.002856363)
   > str(zz)
   List of 5
    $ estimate: Named num 1
     ..- attr(*, "names")= chr "df"
    $ sd      : Named num 0.00286
     ..- attr(*, "names")= chr "df"
    $ vcov    : num [1, 1] 8.16e-06
     ..- attr(*, "dimnames")=List of 2
     .. ..$ : chr "df"
     .. ..$ : chr "df"
    $ loglik  : num -79007
    $ n       : int 100000
    - attr(*, "class")= chr "fitdistr"

By the way, giving a starting value that is not between the upper and lower
limits that you also gave is asking for trouble of a different sort.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com