【问题标题】:How to get gofstat from fitted models by group in R如何在 R 中按组从拟合模型中获取 gofstat
【发布时间】:2016-10-13 23:53:09
【问题描述】:

我有一个包含数千个独特测试 (TestNum) 及其相关响应 (Response) 的大型数据集,其中响应的长度在测试中有所不同。测试基于某些标准被丢弃,因此 TestNum 值缺乏序列。这里是一个简化的例子:

dat <- data.frame(Response=c(rlnorm(10, 2.9, 0.3), rlnorm(14, 2.88, 0.38), rlnorm(19, 2.44, 0.08)),TestNum=rep(c(1,4,9), times=c(10,14,19)))
dat$TestNum<-factor(dat$TestNum)
dat

我正在为每个 TestNum 拟合 lnnorm 分布并提取系数

dat_fit1 <- with(dat,
        by(dat[,1], TestNum, fitdist, "lnorm"))
dat_fit2 <-t(sapply(dat_fit1, coef))

我想测试其他分布,但需要拟合优度统计信息(gofstat;例如“chi”chisqpvalue、“cvm”、“ad”、“ks”、“aic”、“bic” ) 从 TestNum 的每条拟合曲线中得到。我可以使用下面的代码得到“aic”和“bic”,但不能得到其余的统计数据。

gof_f<-do.call(rbind, dat_fit1) 
gof_f<-gof_f[,7:8]

任何建议将不胜感激!

【问题讨论】:

    标签: r curve-fitting goodness-of-fit


    【解决方案1】:
    dat.lnorm <- with(dat,
                  by(dat[,1], dat[,2], 
            function(x){
            fit<-fitdist(x,"lnorm", method="mme")                                   
            coef_meanlog <-fit[[1]][[1]]
            coef_sdlog   <-fit[[1]][[2]]
            ks <-ks.test(jitter(x),"plnorm", meanlog=coef_meanlog, sdlog=coef_sdlog)$p.value
            ad <-ad.test(plnorm(x, meanlog=coef_meanlog, sdlog=coef_sdlog))$p.value
            return(list(cbind(rbind(fit[7:8]), ks, ad)))
    }))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-26
      相关资源
      最近更新 更多