# Maximum Likelihood Estimation

**URL:** <https://discourse.julialang.org/t/maximum-likelihood-estimation/77527>\
**Category:** New to Julia\
**Tags:** question, package\
**Created:** [March 7, 2022, 4:42pm UTC](https://discourse.julialang.org/t/maximum-likelihood-estimation/77527 "2022-03-07T16:42:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![maria96](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maria96/32/205557_2.png) [@maria96](https://discourse.julialang.org/u/maria96)\
**Post date:** [March 7, 2022, 4:42pm UTC](https://discourse.julialang.org/t/maximum-likelihood-estimation/77527/1 "2022-03-07T16:42:01Z")

</div>

Hi all,

I’ve been into Julia for a week now. I managed to transfer all my code from R to Julia and the results I obtain in Julia are what I expect.

However, when I try to obtain the maximum likelihood estimates from my function (which doesn’t have a closed form expression, it is constructed from numerical integration basically) using Optim.optimize, it immediately returns NaN, when I know it can’t be NA because I do get results in R.

I get this error

```julia
ERROR: LoadError: InexactError: Int64(NaN)
Stacktrace:
 [1] Int64(::Float64) at ./float.jl:710
 [2] x_of_nans(::Array{Int64,1}, ::Type{T} where T) at /home/andrel/.julia/packages/NLSolversBase/QPnui/src/NLSolversBase.jl:60 (repeats 2 times)
 [3] NonDifferentiable(::Function, ::Array{Int64,1}, ::Int64; inplace::Bool) at /home/andrel/.julia/packages/NLSolversBase/QPnui/src/objective_types/nondifferentiable.jl:11
 [4] NonDifferentiable(::Function, ::Array{Int64,1}, ::Int64) at /home/andrel/.julia/packages/NLSolversBase/QPnui/src/objective_types/nondifferentiable.jl:11
 [5] promote_objtype(::NelderMead{Optim.AffineSimplexer,Optim.AdaptiveParameters}, ::Array{Int64,1}, ::Symbol, ::Bool, ::Function) at /home/andrel/.julia/packages/Optim/onG5j/src/multivariate/optimize/interface.jl:63
 [6] optimize(::Function, ::Array{Int64,1}; inplace::Bool, autodiff::Symbol, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/andrel/.julia/packages/Optim/onG5j/src/multivariate/optimize/interface.jl:86
 [7] optimize(::Function, ::Array{Int64,1}) at /home/andrel/.julia/packages/Optim/onG5j/src/multivariate/optimize/interface.jl:84
 [8] top-level scope at /home/andrel/Desktop/PhD/1st Year/Julia/Functions_Attempt2.jl:114
in expression starting at /home/andrel/Desktop/PhD/1st Year/Julia/Functions_Attempt2.jl:114

```

Do you know what is happening or if there is any other package that I can use?

Many thanks

---

<div class="post-metadata">

**Author:** ![jacobusmmsmit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacobusmmsmit/32/217669_2.png) [@jacobusmmsmit](https://discourse.julialang.org/u/jacobusmmsmit)\
**Post date:** [March 7, 2022, 4:44pm UTC](https://discourse.julialang.org/t/maximum-likelihood-estimation/77527/2 "2022-03-07T16:44:03Z")

</div>

Hi Maria, please could you provide the code that produces this error? It would greatly help if we could reproduce it ourselves.

---

<div class="post-metadata">

**Author:** ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)\
**Post date:** [March 7, 2022, 4:48pm UTC](https://discourse.julialang.org/t/maximum-likelihood-estimation/77527/3 "2022-03-07T16:48:18Z")

</div>

This looks like you’re maybe using ints when you should use floats. In R, `1` is a float, not an int. In Julia, `1` is an int and `1.0` is a float.

---

<div class="post-metadata">

**Author:** ![maria96](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maria96/32/205557_2.png) [@maria96](https://discourse.julialang.org/u/maria96)\
**Post date:** [March 7, 2022, 4:58pm UTC](https://discourse.julialang.org/t/maximum-likelihood-estimation/77527/4 "2022-03-07T16:58:13Z")

</div>

Thanks! It seems to have worked now (I do have some errors but it’s in my other functions)
