【问题标题】:Fitting distribution using fitdistplus caused error in charToDate(x)使用 fitdistplus 拟合分布导致 charToDate(x) 出现错误
【发布时间】:2019-09-04 09:47:00
【问题描述】:

我正在我的数据框中安装有毒分布的列,但是,它一直警告此错误:“charToDate(x) 中的错误: 字符串不是标准的明确格式”

 Date       Admissions Attendance Tri_1 Tri_2 Tri_3 Tri_4 Tri_5
   <date>          <int>      <int> <dbl> <dbl> <dbl> <dbl> <dbl>
 1 2014-04-01         84        209     5    33    62    80    29
 2 2013-08-01         96        207     2    45    95    59     6
 3 2013-12-01        100        254     3    37    97   102    14
 4 2014-02-01        106        235     3    38    83    94    17
 5 2014-01-01         84        222    10    25    53   115    18
 6 2013-07-01         99        235     8    33    89    85    20
 7 2014-06-01         89        210     9    37    58    89    17
 8 2014-03-01         94        247     6    36    73   110    22
 9 2014-05-01        101        211     5    33   113    53     6
10 2013-11-01        104        234     3    42   108    73     8

这是我的数据,我想将它拟合到 tri_1 列。即使我更改了日期的类型,仍然会导致错误。

这是我的代码: 估计 % fitdist(data= Tri_1,distr = "pois")

它一直警告这个错误: “charToDate(x) 中的错误: 字符串不是标准的明确格式”

【问题讨论】:

  • 它不在 tidyverse 的功能之一内。因此,您需要像.$Tri_1 一样提取列,即df %&gt;% fitdist(data = .$Tri_1, distr = "Pois")

标签: r tidyverse fitdistrplus


【解决方案1】:

未加引号的列名在 tidyverse 函数环境中工作,例如 mutate/summarise/select/..fitdist 来自 fitdistrplus,它可能与 tidyverse 功能不兼容。我们可以直接申请

library(fitdistrplus)
fitdist(df$Tri_1,distr = "gamma")
#Fitting of the distribution ' gamma ' by maximum likelihood 
#Parameters:
#       estimate Std. Error
#shape 4.0508963  1.7421450
#rate  0.7501967  0.3434884

或者如果我们需要在管道中使用它,那么列应该是pulled

library(dplyr)
df %>%
    pull(Tri_1) %>%
    fitdist(data = ., distr = "gamma")
#Fitting of the distribution ' gamma ' by maximum likelihood 
#Parameters:
#       estimate Std. Error
#shape 4.0508963  1.7421450
#rate  0.7501967  0.3434884

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-05
    • 2016-05-02
    • 2020-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多