Hello everyone!
I've trying to write an code to show travel demanding forecast. My model is Multinomial Logit Model. I need some help on my coding.
My data frame as follows: I have 17 variables and 121 obs (rows) but I'm minimizing it into 7 variables and 5.obs
FModeFr Age Drlicense Work Income PosAuto CostCar
1 1 2 1 3 3 1 1000
2 5 2 1 5 2 4 1400
3 2 2 1 5 1 1 4900
4 1 2 1 2 2 1 5000
5 1 2 1 3 3 4 3000
`
OutPut <-data.frame(PCar,PBus,PTaxi,PSharedtaxi,PWalk,SCar,SBus,STaxi,SSharedtaxi,SWalk)
write.table(OutPut,"Output.csv",quote=F,col.names=T,append=T,sep=",")
LL <-colSums(SCar*log(PCar)+SBus*log(PBus)+STaxi*log(PTaxi)+SSharedtaxi*log(PSharedtaxi)+SWalk*log(PWalk))
}
b0 <-numeric(12)
res_BFGS <-optim(b0,fr, method="BFGS", hessian=TRUE, control=list(fnscale=-1))
#> Error in fn(par, ...): dims [product 121] do not match the length of object [0]
show <-function(res,b0){
b <-res$par
hhh <-res$hessian
tval <-b/sqrt(-diag(solve(hhh)))
L0 <-hh*log(1/5)
LL <-res$value
print(b)
print(tval)
print(hhh)
print(L0)
print(LL)
print((L0-LL)/L0)
print((L0-(LL-length(b)))/L0)
}
show(res_BFGS,b0)
#> Error in show(res_BFGS, b0): object 'res_BFGS' not found
I'm not using any packages and library.