【问题标题】:Convert to dataframe: Model fit summaries of full factorial subsets of a dataframe转换为数据框:模型拟合数据框的全因子子集的摘要
【发布时间】:2019-07-14 08:52:52
【问题描述】:

我有一个包含变量和两个因素的数据框

test <- data.frame(variable = rnorm(100,10,5),
                   factor_1 = as.factor( rep(1:2,50)),
                   factor_2 = as.factor( rep(1:5,20)))

test <- test[test$variable>0,]

我将 Weibull 分布拟合到 full factorial 子集,并收集如下拟合参数:

DF <- split(test, list(test$factor_1, test$factor_2), drop = TRUE)

library(fitdistrplus)
fit.weibull <- function(DF) {
   scale <- summary(fitdist(DF[,1],'weibull'))[[1]][2]
   scale_sd <- summary(fitdist(DF[,1],'weibull'))[[3]][2]
   rbind(scale, scale_sd)
}
params <- lapply(DF, fit.weibull)

我本质上想要的最终输出是一个数据框,其中包括scalescale_sdfactor_2 作为列。但是我目前的输出很难转换成这样的数据框。

非常感谢任何帮助。

【问题讨论】:

标签: r weibull fitdistrplus


【解决方案1】:

好的,我找到了一个有效的丑陋解决方案:

scale <- c()
scale_sd <- c()
name <- c()

for (i in 1:length(params)) {

  scale[[i]] <- params[[i]][[1]]
  scale_sd[[i]] <- params[[i]][[2]]
  name[[i]] <- names(params)[i]

}

DF <- data.frame("name"= as.character(name),
                 "scale"= as.numeric(scale),
                 "scale_sd"= as.numeric(scale_sd))

name 列实际上包含这两个因子,因此数据框的每一行都代表一个完整的因子子集。

【讨论】:

    猜你喜欢
    • 2021-04-19
    • 1970-01-01
    • 2016-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-12
    • 1970-01-01
    • 2013-04-11
    相关资源
    最近更新 更多