【问题标题】:Graph estimated parameters from a set of estimated distributions从一组估计分布中绘制估计参数
【发布时间】:2017-05-26 19:15:54
【问题描述】:

我通过使用以下代码对时间段和性别的数据进行分组来估计一组分布:

df.weibull <- tapply(df$attribute, list(time=df$time, gender=df$gender), fitdist, "weibull")

我想绘制这些分布随时间变化的尺度参数,并为每个性别分别绘制一条线。我知道我可以通过以下方式访问单个比例参数:

df.weibull[1,"M"][[1]]$estimate["scale"]

但我无法弄清楚如何以直接方式一次访问所有比例参数。访问所有参数或如何编写原始函数以返回更易于访问的数据结构的解决方案都很好。

编辑:这是一些重现数据结构的代码:

 gender.df <- c("M","M","M","M","M","M","F","F","F","F","F","F")
 time.df <- c(1,1,1,2,2,2,1,1,1,2,2,2)
 attribute.df <- c(10,20,30,11,21,31,45,55,65,1,2,3)
 df <- data.frame(attribute.df,time.df,gender.df)
 names(df) <- c("attribute", "time", "gender")
 library(fitdistrplus)
 df.weibull <- tapply(df$attribute, list(time=df$time, gender=df$gender), fitdist, "weibull")

【问题讨论】:

  • 您能提供一部分数据集吗?
  • 作为编辑添加。

标签: r dataset


【解决方案1】:

您似乎正在尝试通过 gendertime 组来拟合 Weibull 分布。我想这只是数据集的一小部分,因为每组只有 3 个观察值。怎么样:

library(tidyverse)
library(data.table)
sumdf <- setDT(df)[, as.list(fitdist(attribute, dist= "weibull")$estimate), by = .(time, gender)]

   time gender    shape     scale
1:    1      M 2.738085 22.587353
2:    2      M 2.893080 23.666143
3:    1      F 7.793204 58.553205
4:    2      F 2.738652  2.258509

然后你可以绘制例如:

ggplot(sumdf) + geom_line(aes(x = time, y = scale, col = gender))

或者

ggplot(sumdf) + geom_line(aes(x = time, y = shape, col = gender))

【讨论】:

  • 谢谢!这可行,但似乎计算量很大。就好像我还想为形状参数创建一个图形一样,我需要重新估计所有分布,而不是从数据结构中访问信息。虽然这确实会生成图表,但我很想知道是否还有其他方法。
  • 见上面的编辑。形状和比例都存储在分组数据框中。然后您可以使用所需的工具进行绘图。希望这会有所帮助。
  • 非常好,实用性好一些。谢谢!
猜你喜欢
  • 1970-01-01
  • 2020-03-18
  • 1970-01-01
  • 1970-01-01
  • 2019-08-18
  • 1970-01-01
  • 1970-01-01
  • 2023-03-19
  • 1970-01-01
相关资源
最近更新 更多