我用包中的fitdist函数拟合了正态分布fitdistrplus.使用denscomp,qqcomp,cdfcomp和ppcomp我们就可以绘制histogram against fitted density functions,theoretical quantiles against empirical ones,the empirical cumulative distribution against fitted distribution functions,和theoretical probabilities against empirical ones分别为如下.
set.seed(12345)
df <- rnorm(n=10, mean = 0, sd =1)
library(fitdistrplus)
fm1 <-fitdist(data = df, distr = "norm")
summary(fm1)
denscomp(ft = fm1, legendtext = "Normal")
Run Code Online (Sandbox Code Playgroud)
qqcomp(ft = fm1, legendtext = "Normal")
Run Code Online (Sandbox Code Playgroud)
cdfcomp(ft = fm1, legendtext = "Normal")
Run Code Online (Sandbox Code Playgroud)
ppcomp(ft = fm1, legendtext …Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码来适应正态分布."b"(太大而不能直接发布)的数据集链接是:
setwd("xxxxxx")
library(fitdistrplus)
require(MASS)
tazur <-read.csv("b", header= TRUE, sep=",")
claims<-tazur$b
a<-log(claims)
plot(hist(a))
Run Code Online (Sandbox Code Playgroud)
绘制直方图后,似乎正态分布应该很好.
f1n <- fitdistr(claims,"normal")
summary(f1n)
#Length Class Mode
#estimate 2 -none- numeric
#sd 2 -none- numeric
#vcov 4 -none- numeric
#n 1 -none- numeric
#loglik 1 -none- numeric
plot(f1n)
Run Code Online (Sandbox Code Playgroud)
xy.coords(x,y,xlabel,ylabel,log)中的错误:
'x'是一个列表,但没有组件'x'和'y'
当我尝试绘制拟合分布时,我得到上述错误,甚至f1n的摘要统计信息都没有.
非常感谢任何帮助.
以下是我的代码:
library(fitdistrplus)
s <- c(11, 4, 2, 9, 3, 1, 2, 2, 3, 2, 2, 5, 8,3, 15, 3, 9, 22, 0, 4, 10, 1, 9, 10, 11,
2, 8, 2, 6, 0, 15, 0 , 2, 11, 0, 6, 3, 5, 0, 7, 6, 0, 7, 1, 0, 6, 4, 1, 3, 5,
2, 6, 0, 10, 6, 4, 1, 17, 0, 1, 0, 6, 6, 1, 5, 4, 8, 0, 1, 1, 5, 15, 14, 8, 1,
3, …Run Code Online (Sandbox Code Playgroud) 我正在尝试重现此答案中的代码,但是这样做时遇到问题。VGAM我正在使用 package和中的gumbel 发行版fitdistrplus。执行以下操作时出现问题:
fit = fitdist(data1, 'gumbel', start = list(location = 0, scale = 1))
Error in mledist(data, distname, start, fix.arg, ...) :
'start' must specify names which are arguments to 'distr'.
Run Code Online (Sandbox Code Playgroud)
就好像location和scale不是 *gumbel 的参数一样。
dgumbel、pgumbel、rgumbel和qgumbel均由 正确提供VGAM。然而,该包还提供了一个名为 的函数gumbel,具有不同的语法。这可能会引起问题吗?
编辑:是的,它确实引起了问题:使用包FAdist代替工作得很好。
我正在尝试在 Go 中重现拟合 beta 分布,给定浮点率的输入:
rates = [0.20, 0.15, 0.002, 0.017, 0.181, 0.004, ...]
Run Code Online (Sandbox Code Playgroud)
您可以在 R 中使用轻松完成此操作fitdistrplus,它会自动选择合理的起始值,这与“挣扎”的 MASS 包不同:
x <- c(0.0955104277250779, 0.0782381918284555, 0.109683584625186,
0.10115721657354, 0.102377369846524, 0.0691699604743083,
0.0940254652301665, 0.078494747777906, 0.0824474231569216,
0.0886513916653852)
fit <- fitdist(x, "beta")
Run Code Online (Sandbox Code Playgroud)
我试图弄清楚如何在 Go 中适应 beta 分布,尽管事实证明这很困难,找到正确的函数(统计不是我的强项)。
我听说我可以使用“时刻方法”作为起始值,但如果它像开箱即用的那样工作,那么自动决定它们会很好。
我正在尝试使用包中的fitdist ()函数fitdistrplus来使我的数据适合不同的分布。假设我的数据如下所示:
x = c (1.300000, 1.220000, 1.160000, 1.300000, 1.380000, 1.240000,
1.150000, 1.180000, 1.350000, 1.290000, 1.150000, 1.240000,
1.150000, 1.120000, 1.260000, 1.120000, 1.460000, 1.310000,
1.270000, 1.260000, 1.270000, 1.180000, 1.290000, 1.120000,
1.310000, 1.120000, 1.220000, 1.160000, 1.460000, 1.410000,
1.250000, 1.200000, 1.180000, 1.830000, 1.670000, 1.130000,
1.150000, 1.170000, 1.190000, 1.380000, 1.160000, 1.120000,
1.280000, 1.180000, 1.170000, 1.410000, 1.550000, 1.170000,
1.298701, 1.123595, 1.098901, 1.123595, 1.110000, 1.420000,
1.360000, 1.290000, 1.230000, 1.270000, 1.190000, 1.180000,
1.298701, 1.136364, 1.098901, 1.123595, 1.316900, 1.281800,
1.239400, 1.216989, 1.785077, 1.250800, 1.370000) …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 t 分布拟合到我的数据中,但无法这样做。我的第一次尝试是
fitdistr(myData, "t")
Run Code Online (Sandbox Code Playgroud)
有 41 个警告,都说产生了 NaN。我不知道如何,似乎涉及对数。所以我稍微调整了我的数据,使所有数据都> 0,但我仍然有同样的问题(虽然警告减少了 9 个......)。sstdFit() 也有同样的问题,会产生 NaN。
因此,我尝试使用我在 stackoverflow 和 CrossValidated 上看到的 fitdist:
fitdist(myData, "t")
Run Code Online (Sandbox Code Playgroud)
然后我得到
Error in mledist(data, distname, start, fix.arg, ...) :
'start' must be defined as a named list for this distribution
Run Code Online (Sandbox Code Playgroud)
这是什么意思?我试图查看文档,但没有告诉我什么。我只想拟合一个 t 分布,这太令人沮丧了:P
谢谢!
我使用rplcon()包中的函数生成一些随机变量poweRlaw
data <- rplcon(1000,10,2)
现在,我想知道哪些已知分布最适合数据。对数范数?经验?伽玛?幂律?指数截止的幂律?
所以我fitdist()在包中使用函数fitdistrplus:
fit.lnormdl <- fitdist(data,"lnorm")
fit.gammadl <- fitdist(data, "gamma", lower = c(0, 0))
fit.expdl <- fitdist(data,"exp")
Run Code Online (Sandbox Code Playgroud)
由于幂律分布和具有指数截止的幂律不是根据CRAN Task View: Probability Distributions的基本概率函数,所以我根据示例 4 编写了幂律的 d,p,q 函数?fitdist
dplcon <- function (x, xmin, alpha, log = FALSE)
{
if (log) {
pdf = log(alpha - 1) - log(xmin) - alpha * (log(x/xmin))
pdf[x < xmin] = -Inf
}
else {
pdf = (alpha - 1)/xmin * (x/xmin)^(-alpha)
pdf[x < …Run Code Online (Sandbox Code Playgroud) 我有100x2数据帧DFN.fitdist在DFN $ Lret列上运行会出现错误消息"函数mle无法估计参数,错误代码为100".我想是原因是最后一行包含一个NA.因此我运行fitdist排除NAs,现在我得到错误"数据必须是长度大于1的数字向量".有关如何解决此问题的任何想法?非常感谢.
DFN <- structure(list(LRet = c(0.0011, 0, -0.0026, 0, -0.0015, 0.0038, 3e-04, -0.0021, 4e-04, -0.001, 0, 0.0019, -6e-04, -8e-04, -5e-04, -8e-04, 3e-04, -5e-04, -0.0026, 0.0014, 7e-04, 0, -2e-04, 0.0011, -0.0025, 0.0042, 0.0022, -0.0017, -0.0058, 1e-04, 2e-04, 8e-04, -9e-04, -0.0014, -0.0014, -0.001, -0.0032, -0.0015, 6e-04, -8e-04, 0.001, -0.0014, -0.0017, -8e-04, -0.001, 0.0011, 0.0013, -0.001, 5e-04, 9e-04, -8e-04, -0.0025, 0.0027, 6e-04, 2e-04, -6e-04, 9e-04, -3e-04, -7e-04, 3e-04, 0, 2e-04, -6e-04, 1e-04, -1e-04, -7e-04, -8e-04, 7e-04, -1e-04, …Run Code Online (Sandbox Code Playgroud) fitdistrplus ×9
r ×9
distribution ×4
statistics ×4
ggplot2 ×1
go ×1
math ×1
mle ×1
na ×1
plot ×1
power-law ×1