0

I hope you don't consider this question as meaningless as I have been struggling with the code and I don't understand why it is not convergent to the same value.

I wrote Newtow Raphson R code to estimate the a multinomial logistic model when it convergent I get different significant value from my logarithm and the build in R function multinom. This is output from my algorithm

> t(new$coefficients)
        X0          X1        X2         X3         X4
1 1.055977  0.08972323 0.7070484 -0.4951407  0.1878713
2 1.845272 -0.26688254 0.6945098 -0.2749830 -2.0379031 

and here is the output from the build-in function

fit <- multinom(fm, data=df, Hess=TRUE)
> coef(fit)
        X0          X1        X2         X3        X4
1 1.055960  0.08972217 0.7070560 -0.4951362  0.187872
2 1.845253 -0.26688462 0.6945132 -0.2749767 -2.037911

Anyone can help me understand why this significant is after 4/5 decimal. Please if you like to see my code I will share in with you privately because it is not ready for me to publish it.

Thanks

Falcon-StatGuy
  • 347
  • 2
  • 6
  • 15
  • to clarify: are you asking why your results differ in the 4th decimal place? This level of numeric fuzz is well within the expectation for using completely different algorithms to solve the same numeric problem. – Ben Bolker Oct 06 '17 at 02:32
  • also: if you're not willing to show your code publicly, it's probably not reasonable to expect people to debug it for you (for free ...) – Ben Bolker Oct 06 '17 at 02:33
  • @BenBolker, I didn't say I am not willing to show my code. I said it is not complete for me to publish it, there is big different between sharing it. I do want to publish it because I have not seen any one wrote NR alogrithum for multinomial but I want to make sure it is right first and it convergent to almost the same to build-in R function. My issue as well is the convergent is totally different when sample size is small. I hope you change this voting down so other can use this question for future – Falcon-StatGuy Oct 06 '17 at 08:42
  • I didn't downvote. I'm going to vote to close the question, though; it's unanswerable in its current form. You tell us in comments that in situations *other than the one you've show here* your code gives different answers to the built-in function (which uses neural nets, not N-R). (And I said show your code *publicly* ...) – Ben Bolker Oct 06 '17 at 11:50
  • @BenBolker I posted the code. I hope you can debug it and let me know what is the problem. Thank you. – Falcon-StatGuy Oct 06 '17 at 12:54
  • Thanks very much. Can you please give an example where the differences between your output and `nnet::multinom()` are much larger? – Ben Bolker Oct 06 '17 at 15:31
  • please run MN <- MN.df(r=11,p=4,c=3,s=50,printLevel = 1) Y <- MN$mdf[,1]; X <- MN$mdf[ ,grepl("X", colnames(MN$mdf))] new <- NRroot(resp=Y,desX=X,maxiter=65,printLevel = 1,ltol=1e-9, gtol=1e-8, lstol=1e-9) t(new$coefficients) sprintf("%0.20f",new$logLik) you will get > t(new$coefficients) X0 X1 X2 X3 X4 1 -44.75519 -10.91527 46.95579 21.83284 -10.91558 2 -78.87800 -22.54051 33.31634 45.08113 -22.54020 > sprintf("%0.20f",new$logLik) [1] "-0.00007620926066920219" – Falcon-StatGuy Oct 06 '17 at 15:41
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/156119/discussion-between-stat-and-ben-bolker). – Falcon-StatGuy Oct 06 '17 at 18:18
  • FWIW I wouldn't be terribly surprised if you were converging on a different local minimum? What happens if you use different starting values? (I'm sorry not to contribute more, but this is a relatively challenging question and I don't have a lot of time today ...) – Ben Bolker Oct 06 '17 at 20:18
  • It doesn't matter if i change the start point. I still get the same convergent. Please can upvote the questions so it can be open to others as well – Falcon-StatGuy Oct 06 '17 at 20:31

1 Answers1

1

The divergence between your function and R built-in function outputs is perfectly acceptable. It something to expect as two functions of this type, coded differently, will carry different minor errors, rounding etc.

Fer Arce
  • 149
  • 8
  • I would as well accept it that but when it comes to small sample size the convergent is totally different and I didn't know for what reason. I would like to share the code if they starting vote up – Falcon-StatGuy Oct 06 '17 at 08:47