r
  • finance
  • 2012-08-06 75 views 1 likes 
    1

    我正在运行一些测试以尝试确定我的数据遵循什么分布。从我的数据密度来看,我认为它看起来有点像逻辑分布。我比使用包MASS来估计分布的参数。但是,当我将它们绘制在一起时,虽然比正常情况好,但物流仍然不是很好。是否有办法找到哪种分布会更好?感谢您的帮助 !图形拟合分布

    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) 
    
    +0

    请在代码中为所有必需的包添加'library()'语句。我猜你也在这里使用'xts'或'quantmod'? – Andrie 2012-08-06 14:27:35

    +0

    感谢您的提醒!我相信quantmod自动加载它使用的其他的!我修改了一下我的问题,因为我设法将我所做的事情图表化了。 – 2012-08-06 14:32:23

    +0

    这是一个类似的问题http://stats.stackexchange.com/questions/33115/whats-the-distribution-of-these-data – Seth 2012-08-06 15:42:16

    回答

    3

    这是基本的R:plot()默认会创建一个新绘制画布,你应该使用一个命令如lines()添加到现有的情节。

    这适用于你的例子:

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

    ,因为它增加了估计数拟合蓝色到现有的情节。

    相关问题