# [R] Probability distribution of fitted gaussian distribution.

Jacob Varughese zdjacob at gmail.com
Sat Jan 3 18:27:44 CET 2015

```Hi,

I have a discrete set of data on the returns for 3 indices with 206 data
points. Since the number of points is less it doesnt exact look like a
gaussian distribution.

I wanted to fit the data to a gaussian distribution and have used the
fitdist function and have gotten the plots and the mean and sd estimates
for the gaussian that fits my data.

What I then want to do is to get a U=F(x) where U is the uniform variable
corresponding to the CDF function applied on the fitted theoritical CDF
curve. How can I get that?

Equivalent data that I find in matlab. Here the ksdensity gives an array of
f and xi values and I could use the f values for my usage. But I am trying
to work it out in R. The steps that I am going through in R are below. I
have also attached the input sheet that I am using for the indices. Sorry
in advance, case its a dumb one.

Estimate Density

Generate a sample data set from a mixture of two normal distributions.

rng default  % for reproducibility
x = [randn(30,1); 5+randn(30,1)];

Plot the estimated density.

[f,xi] = ksdensity(x);
figure
plot(xi,f);

Steps that I am following.

# Reading and finding the returns for 3 indices.
numRows=nrow(CDSPrices)
CDSReturnsN225=CDSPrices\$N225[2:numRows]/CDSPrices\$N225[1:numRows-1]-1
CDSReturnsSPX=CDSPrices\$SPX[2:numRows]/CDSPrices\$SPX[1:numRows-1]-1
CDSReturnsIBOVESPA=CDSPrices\$IBOVESPA[2:numRows]/CDSPrices\$IBOVESPA[1:numRows-1]-1
CDS_Returns<-cbind(CDSReturnsN225,CDSReturnsSPX,CDSReturnsIBOVESPA)

# Using fitdist to fit a gaussian distribution onto the discrete empirical
data I have.
library(fitdistrplus)
fittedNormal<-fitdist(CDS_Returns[,1],"norm")
plot(fittedNormal)

> fittedNormal[]
\$estimate
mean           sd
-0.002035951  0.028654032

\$method
[1] "mle"

\$sd
mean          sd
0.001996421 0.001403953

Reference

http://cran.r-project.org/web/packages/fitdistrplus/fitdistrplus.pdf  ~
Page 15

--
*Jacob Varughese*
```