1

I am running some tests to try and determine what distribution my data follows. By the look of the density of my data I thought it looked a bit like a logistic distribution. I than used the package MASS to estimate the parameters of the distribution. However when I graph them together although better than the normal, the logistic is still not very good..Is there a way to find what distribution would go better? Thank you for the help !

library(quantmod)
getSymbols("^NDX",src="yahoo", from='1997-6-01', to='2012-6-01')
daily<- allReturns(NDX) [,c('daily')]
dailySerieTemporel<-ts(data=daily)
x<-na.omit(dailySerieTemporel)

library(MASS)
(xFit<-fitdistr(x,"logistic"))
#      location        scale    
#   0.0005210570   0.0106366354 
#  (0.0002941922) (0.0001444678)
xFitEst<-coef(xFit)

plot(density(x))
set.seed(125)
lines(density(rlogis(length(x), xFitEst['location'], xFitEst['scale'])), col=3)
lines(density(rnorm(length(x), mean(x), sd(x))), col=2) 
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
jeremy.staub
  • 369
  • 4
  • 12
  • Please add `library()` statements for all required packages in your code. I guess you also use `xts` or `quantmod` in here? – Andrie Aug 06 '12 at 14:27
  • Thanks for the reminder! I believe quantmod automaticly loads the other ones it uses! I modified a bit my question, as I managed to graph what I have done sofar! – jeremy.staub Aug 06 '12 at 14:32
  • Here is a similar question http://stats.stackexchange.com/questions/33115/whats-the-distribution-of-these-data – Seth Aug 06 '12 at 15:42

1 Answers1

3

This is elementary R: plot() creates a new plotting canvas by default, and you should use a command such as lines() to add to an existing plot.

This works for your example:

plot(density(x))
lines(density(rlogis(length(x), location = 0.0005210570,
                     scale = 0.0106366354)), col="blue")

as it adds the estimated logistic fit in blue to your existing plot.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725