微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用新的预测替代方案修改 apollo_prediction() 和函数 apollo_probabilities() 的参数?

如何解决如何使用新的预测替代方案修改 apollo_prediction() 和函数 apollo_probabilities() 的参数?

我有从 apollo_estimate() 估计的基本模式选择模型

    model = apollo_estimate(apollo_beta,apollo_fixed,apollo_probabilities,apollo_inputs)

在预测步骤中,我想添加一个或多个备选方案并使用此估计模型进行预测。以下是我遵循的步骤。

  1. 使用替代数据更新数据库(数据集):
data.list <- lapply(1,function(x) {
 nrep <- 1;
 cost_bike <- c(replicate(nrep,(runif(1000,100,300))));
 time_bike <- c(replicate(nrep,0.5,17.4))));
 access_bike <- c(replicate(nrep,5,50))));
 data.frame(cost_bike,time_bike,bike_access);
});
database$time_bike <-  as.numeric(as.character(trunc(data.frame(data.list[[1]])[,1])))
database$cost_bike <-  as.numeric(as.character(trunc(data.frame(data.list[[1]])[,2])))
database$bike_access <- as.numeric(as.character(trunc(data.frame(data.list[[1]])[,3])))
  1. 更新 apollo_probabilities
apollo_probabilities=function(apollo_beta,apollo_inputs,functionality="prediction"){
  
  ### Attach inputs and detach after function exit
  apollo_attach(apollo_beta,apollo_inputs)
  on.exit(apollo_detach(apollo_beta,apollo_inputs))
  
  ### Create list of probabilities P
  P = list()
  
  ### List of utilities: these must use the same names as in mnl_settings,order is irrelevant
  V = list()
  V[['car']]  = asc_car  + b_tt_car  * time_car                           
  V[['bus']]  = asc_bus  + b_tt_bus  * time_bus  + b_access * access_bus  
  V[['air']]  = asc_air  + b_tt_air  * time_air  + b_access * access_air   
  V[['rail']] = asc_rail + b_tt_rail * time_rail + b_access * access_rail
  V[['bike']] = b_access * access_bike # newly added
 
  
  ### Define settings for MNL model component
  mnl_settings = list(
    alternatives  = c(car=1,bus=2,air=3,rail=4,bike=5),avail         = list(car=av_car,bus=av_bus,air=av_air,rail=av_rail),choiceVar     = choice,V             = V
  )
  
  ### Compute probabilities using MNL model
  P[['model2']] = apollo_mnl(mnl_settings,functionality)
  
  ### Take product across observation for same individual
  P = apollo_panelProd(P,functionality)
  
  ### Prepare and return outputs of function
  P = apollo_prepareProb(P,functionality)
  return(P)
}


apollo_inputs   = apollo_validateInputs()

# prediction on new alternatives
predictions_new = apollo_prediction(model,prediction_settings = "model2") 

此步骤因参数类型无效而失败。 追溯:

Error in !a : invalid argument type 
6.
apollo_setRows(v,!a,0) 
5.
(function (v,a) 
apollo_setRows(v,0))(dots[[1L]][[5L]],dots[[2L]][[5L]]) 
4.
mapply(function(v,a) apollo_setRows(v,0),V,avail,SIMPLIFY = FALSE) 
3.
apollo_mnl(mnl_settings,functionality) 
2.
apollo_probabilities(apollo_beta,functionality = "prediction") 
1.
apollo_prediction(model,prediction_settings = "model2") 

如何在 apollo 中添加新的替代方案并运行预测?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。