travel demand prediction

I'm writing a code to have a travel demand forecasting using the Multinomial Logit Model without using packages. However, I'm having an error in the BFGS optim part. I'd appreciate if you take a look at my code.

Part of the code is shown below.

OutPut <-data.frame(PCar,PBus,PTaxi,PSharedtaxi,PWalk,SCar,SBus,STaxi,SSharedtaxi,SWalk)

LL <-colSums(SCarlog(PCar)+SBuslog(PBus)+STaxilog(PTaxi)+SSharedtaxilog(PSharedtaxi)+SWalk*log(PWalk))

b0 <-numeric(12)

res_BFGS <-optim(b0,fr, method="BFGS", hessian=TRUE, control=list(fnscale=-1))

show <-function(res,b0){
b <-res$par
hhh <-res$hessian
tval <-b/sqrt(-diag(solve(hhh)))

L0 <-hh*log(1/5)
LL <-res$value



Error in colSums(SCar * log(PCar) + SBus * log(PBus) + STaxi * log(PTaxi) + :
'x' must be an array of at least two dimensions
In addition: Warning message:
In write.table(OutPut, "Output.csv", quote = F, col.names = T, append = T, :
appending column names to file
Called from: colSums(SCar * log(PCar) + SBus * log(PBus) + STaxi * log(PTaxi) +
SSharedtaxi * log(PSharedtaxi) + SWalk * log(PWalk))

Hi, and welcome!

Please see the FAQ: What's a reproducible example (`reprex`) and how do I create one? Using a reprex, complete with representative data will attract quicker and more answers.

What reprex does is to avoid the hurdle of having to reverse engineer a problem before offering solutions.

About the most I can offer without one is that the key seems

'x' must be an array of at least two dimensions

saying that somewhere along the line a function expected more than it got, a vector.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.