[R-sig-finance] Distribution Fitting

Dirk Eddelbuettel edd at debian.org
Mon Apr 24 00:40:43 CEST 2006


On 24 April 2006 at 00:10, Lorenzo Isella wrote:
|  Dear All,
| I am experiencing some problems in fitting a trimodal distribution (which
| should be thought as a sum of three Gaussian distributions) using the nls
| function for nonlinear fittings.
| As a test, just consider the very simple code:
| 
| rm(list=ls());
| mydata<-rnorm(10000,0,4);
| mydens<-density(mydata,kernel="gaussian");
| y1<-mydens$y;
| x1<-mydens$x;
| myfit<-nls(y1~A*exp(-x1^2/sig));
| 
| 
| which I use to get the empirical density (as I would from real experimental
| data) and test it against a Gaussian ansatz.
| Well, either R always crashes for a segmentation fault and I have to restart
| it manually or I get this output:
| 
| Error in match.call(definition, call, expand.dots) :
| '.Primitiv�i�d�������������...' is not a function
| 
| Am I missing the obvious or is there some bug in my R build?

Are you aware of fitdistr() in MASS?

> library(MASS)
> mydata<-rnorm(10000,0,4)
> fitdistr(mydata, "normal")
        mean                  sd            
  -0.0055755191185632    3.9956609772436904 
 ( 0.0399566097724369) ( 0.0282535897233148)
> 

fitdistr() fits a bunch of distribution. I can't recall whether I used this,
or one of the mixed distribution packages from CRAN when I was doing some
work on mixtures for fat tails.

Dirk

-- 
Hell, there are no rules here - we're trying to accomplish something. 
                                                  -- Thomas A. Edison



More information about the R-sig-finance mailing list