> fitdistr(y, "chi-squared", start = list(4), method =
"Brent", lower=0.9, upper=3)
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
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at
r-project.org] On Behalf
> Of Jim Silverton
> Sent: Tuesday, November 19, 2013 4:30 PM
> To: r-help at r-project.org
> Subject: [R] (no subject)
>
> I generated some random data using R and then trying to see if it came from
> the same distribution but the erros keep piling. Can anyone help?
>
>
>
> y=rchisq(100000,1)
> mean(y)
> var(y)
> library(MASS)
> fitdistr(y, "chi-squared", start = list(4), method =
"Brent", lower=0.9,
> upper=3)
>
>
> --
> Thanks,
> Jim.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.