基本上我有五个类型为“double”的向量。即wk_hoil,wk_gas,kwh_final17,p_hoil17和p_gas17。所有的长度都是10000.我创建了以下函数来计算节省:
fun<-function(wk1, wk2, kwh1, kwh2, p1, p2){savings<-((wk1+kwh1*p1)-(wk2+kwh2*0.7*p2))/1.05^0.5315}
我为参数设置了一个列表:
param_list17<-list("wk1"=wk_hoil, "wk2"=wk_gas, "kwh1"=kwh_final17, "kwh2"=kwh_final17, "p1"=p_hoil17, "p2"=p_gas17)
最终我想使用MonteCarlo软件包中的MonteCarlo函数运行Monte Carl Simulation:
MonteCarlo(func=fun, nrep=10000, param_list = param_list17)
我收到错误消息:
Error in MonteCarlo(func = fun, nrep = 10000, param_list = param_list17) :
func has to return a list with named components. each component has to be scalar.
知道问题是什么吗?我想将MC模拟的结果保存在矢量或矩阵中。
谢谢!