我正在设置一个脚本来从单个列文本文件中提取厚度和电压,并在其上执行Weibull分布。当我尝试使用fitdistr()
时,收到错误消息“'x' must be a non-empty numeric vector
”。 R应该将文本文件中的数字解释为数字,但似乎没有发生。有什么想法吗?
filename <- "SampleBreakdownSet.txt"
d <- read.table(filename, header = FALSE, sep = "")
#Extract thickness from the dataset; set to variable t
t = d[1,1]
#Extract the breakdown voltages and toss into dataset, BDV
BDV = tail(d,(nrow(d)-1))
#Calculates the breakdown field from the thickness and BDV
BDF = (BDV*10000) / t
#Calculates the Weibull parameters from the input breakdown voltages.
fitdistr(BDF, densfun ="weibull", lower = 0)
fitdistr(BDF,densfun =“weibull”,lower = 0) fitdistr出错(BDF,densfun =“weibull”,lower = 0): 'x'必须是非空数字向量
我正在使用的示例数据: 2
200
250
450
320
100
400
200
403
502
203
420
120
342
304
253
423
534
534
243
253
423
123
433
534
234
633
432
342
543
532
123
453
231
532
342
213
243
答案 0 :(得分:0)
您正在将data.frame
传递给fitdistr
,但您应该传递矢量本身。
试试这个:
d <- read.table(text='200
250
450
320
100
400
200
403
502
203
420
120
342
304
253
423
534
534
243
253
423
123
433
534
234
633
432
342
543
532
123
453
231
532
342
213
243', header=FALSE)
t <- d[1,1]
#Extract the breakdown voltages and toss into dataset, BDV
BDV <- d[-1, 1]
BDF <- (BDV*10000) / t
library(MASS)
fitdistr(BDF, densfun ="weibull", lower = 0)
您也可以在致电fitdistr
时参考相关列,例如:
fitdistr(BDF$V1, densfun ="weibull", lower = 0)
# shape scale
# 2.745485e+00 1.997509e+04
# (3.716797e-01) (1.283667e+03)