Maximum Likelihood Estimation

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

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

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

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.

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