【问题标题】:The plpearsonIII function should return a zero-length vector when input has length zero当输入长度为零时,plpearsonIII 函数应返回长度为零的向量
【发布时间】:2021-11-02 13:29:29
【问题描述】:

我正在使用以下表达式:

fitlpIII <- fitdist(log(Data), dlpearsonIII, start=list(meanlog=mean(log(Data)), sdlog=sd(log(Data)), skew=e1071::skewness(log(Data), type= 1)))

但它显示以下错误:

警告信息:在 fitdist(log(Dados), dlpearsonIII, start = list(meanlog = mean(log(Dados)), : plpearsonIII 函数应该 当输入长度为零时返回一个长度为零的向量

【问题讨论】:

  • 你能分享你的数据吗?
  • 是的。数据
  • 得到一个不同的错误,但它似乎与optim 函数有关,所以我猜是启动参数的问题。会尝试不同的东西
  • 您能提供您的电子邮件吗?

标签: r


【解决方案1】:

据我所见,您的数据与函数的密度不同,因此它会给出错误,因为它可以从您的起始值中找到估计值。

这里我根据原始数据计算指标,然后用分布模拟数据。

# remotes::install_github("USGS-R/smwrBase")
library(smwrBase)
library(tidyverse)

示例数据

x <- c(38.8,40.0,44.1,44.4,58.6,60.5,62.4,65.4,66.6,67.3,68.3,70.0,70.0,70.4,77.1,77.4,78.4,86.9,94.9,95.1,98.0,107.9,126.6)

计算指标

lx <- log(x)
sd_log <- sd(lx)
mean_log <-  mean(lx)
skew_log <- e1071::skewness(lx,type= 1)

使用原始数据指标从分布中模拟数据

simul_x <- rlpearsonIII(n = 1000,sdlog = sd_log,meanlog =mean_log,skew = slew_log)

绘图代码

tibble(
  value = c(lx,simul_x),
  name = c(rep("Original",length(lx)),rep("Simulated",length(simul_x)))) %>% 
  ggplot(aes(value,col = name))+
  geom_density()+
  facet_wrap(~name,scales = "free")

【讨论】:

  • 如果我的数据不适用于此分布?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-23
  • 1970-01-01
  • 2021-03-18
  • 1970-01-01
  • 2010-09-22
  • 1970-01-01
相关资源
最近更新 更多