1

我正在设置一个脚本来从单列文本文件中提取厚度和电压,并对其执行 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
4

1 回答 1

0

您正在传递data.frameto 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)
于 2015-01-31T08:31:39.830 回答