我想生成相关pdf的样本。我发现 EnvStats 包中包含的函数 simulateMvMatrix 允许这样做。我的代码是:
library(EnvStats)
vfyfueu <- matrix(, nrow = 0, ncol = 3)
for (i in 1:10 ) {
# (*) Ref 1: Statistical evaluation of the lateral torsional buckling resistance of steel beams Part 2
# (**) fixed
# fy (S355)
meanmean = 419.38 #(*)
sdmean = 10 #(**)
meanmeanlv = 400 #(**)
meanmeanuv = 440 #(**)
meanfy <- dist(meanmean,sdmean,meanmeanlv,meanmeanuv,"norm")
meansd = 20.25 #(*)
sdsd = 5 #(**)
meansdlv = 15 #(**)
meansduv = 25 #(**)
sdfy <- dist(meansd,sdsd,meansdlv,meansduv,"norm")
fylv = 355 #(*)
fyuv = 500 #(**)
lsupfy <- 1 - plnormTruncAlt(fyuv, mean = meanfy[1], cv = sdfy[1]/meanfy[1])
linffy <- plnormTruncAlt(fylv, mean = meanfy[1], cv = sdfy[1]/meanfy[1])
# fu (S355)
meanmean = 533.44 #(*)
sdmean = 10 #(**)
meanmeanlv = 500 #(**)
meanmeanuv = 550 #(**)
meanfu <- dist(meanmean,sdmean,meanmeanlv,meanmeanuv,"norm")
meansd = 16.53 #(*)
sdsd = 5 #(**)
meansdlv = 10 #(**)
meansduv = 25 #(**)
sdfu <- dist(meansd,sdsd,meansdlv,meansduv,"norm")
fulv = 470 #(*)
fuuv = 630 #(*)
lsupfu <- 1 - plnormTruncAlt(fuuv, mean = meanfu[1], cv = sdfu[1]/meanfu[1])
linffu <- plnormTruncAlt(fulv, mean = meanfu[1], cv = sdfu[1]/meanfu[1])
# eu (S355)
meanmean = 0.2645 #(*)
sdmean = 10 #(**)
meanmeanlv = 0.2 #(**)
meanmeanuv = 0.3 #(**)
meaneu <- dist(meanmean,sdmean,meanmeanlv,meanmeanuv,"norm")
meansd = 0.0613 #(*)
sdsd = 0.02 #(**)
meansdlv = 0.02 #(**)
meansduv = 0.1 #(**)
sdeu <- dist(meansd,sdsd,meansdlv,meansduv,"norm")
eulv = 0.15 #(*)
euuv = 0.3 #(*)
lsupeu <- 1 - plnormTruncAlt(euuv, mean = meaneu[1], cv = sdeu[1]/meaneu[1])
linfeu <- plnormTruncAlt(eulv, mean = meaneu[1], cv = sdeu[1]/meaneu[1])
#Generate samples
mat.fyfueu <- simulateMvMatrix(10,
distributions = c(fy = "lnormAlt",fu = "lnormAlt",eu = "lnormAlt"),
param.list = list(fy = list(mean=meanfy[1], cv=sdfy[1]/meanfy[1]),
fu = list(mean=meanfu[1], cv=sdfu[1]/meanfu[1]),
eu = list(mean=meaneu[1], cv=sdeu[1]/meaneu[1])),
left.tail.cutoff = list(fy = ifelse(linffy <= 0, 0, linffy),
fu = ifelse(linffu <= 0, 0, linffu),
eu = ifelse(linfeu <= 0, 0, linfeu)),
right.tail.cutoff = list(fy = ifelse(lsupfy <= 0, .Machine$double.eps, lsupfy),
fu = ifelse(lsupfu <= 0, .Machine$double.eps, lsupfu),
eu = ifelse(lsupeu <= 0, .Machine$double.eps, lsupeu)),
cor.mat = matrix(c(1, .75, -0.45, .75, 1, -0.6, -0.45, -0.6, 1), 3, 3),
sample.method = "LHS") #, seed = i
vfyfueu <- rbind2(vfyfueu, mat.fyfueu)
round(cor(mat.fyfueu, method = "spearman"), 2)
}
我在left.tail.cutoff
和right.tail.cutoff
规范中出现的问题。 R返回此错误消息:
Error in simulateMvMatrix(10, distributions = c(fy = "lnormAlt", fu = "lnormAlt", :
All values of 'left.tail.cutoff' and 'right.tail.cutoff' must be numeric scalars between 0 and 1, and all values of 'left.tail.cutoff' must be smaller than the corresponding values of 1-'right.tail.cutoff'
但是,上述参数中包含的所有值均遵守限制。如果我注释掉相关的行代码运行正常,但这不是我想要的。另外,如果我单独询问每个变量的值(不相关),它就可以工作(我使用 simulateVector 函数)。
哪里有错误来源?
编辑: 功能dist
dist <- function(meanv, sdv, lv, uv, dist) {
library(EnvStats)
lsup <- 1 - pnorm(uv, mean = meanv, sd = sdv)
linf <- pnorm(lv, mean = meanv, sd = sdv)
value <- simulateVector(2, distribution = dist,
param.list = list(mean = meanv, sd = sdv), #seed = i,
sort = FALSE, left.tail.cutoff = ifelse(linf == 0, .Machine$double.eps, linf),
right.tail.cutoff = ifelse(lsup == 0, .Machine$double.eps, lsup), sample.method = "LHS")
return(value)
}
感谢