Hi,
I am trying to run a Julia code to fit a LinearMixedModel and facing an Argument error : invalid NLopt arguments: finite domain required for global algorithm.
Julia version I am working on is 1.8.5
Any help will be appreciated.
Thank you
Hi,
I am trying to run a Julia code to fit a LinearMixedModel and facing an Argument error : invalid NLopt arguments: finite domain required for global algorithm.
Julia version I am working on is 1.8.5
Any help will be appreciated.
Thank you
The error means exactly what it says: NLopt has both global and local optimization algorithms, but the former are only supported on a finite domain.
So, either specify upper and lower bounds to all your variables or switch to local optimization.
Can you provide more detail on how you got to this error? For example, MixedModels.jl version and whether you changed any of the default settings.
For the default settings, MixedModels.jl sets up the optimization problem with appropriate constraints and then uses the BOBYQA optimizer.
I am using julia version “1.8.5” and package MixedModels version “3.9.0”.
I am trying to fit a “LinearMixedModel” as below:
model = fit!(LinearMixedModel(formula, input_dataframe), REML=true)
And its very strange that till last month I was able to run this command successfully, but now I am facing an issue with NLopt.
Thank you for your response.
Could you please confirm how can I specify upper and lower bounds to all variables or switch to local optimization if I am trying to fit a “LinearMixedModel” ?
Unless you have a very good reason to be on the 3.x series, I would recommend upgrading to the 4.x series of MixedModels. The primary breaking change was to the internal storage and not to any user-facing API, so the fast majority of users would not experience any breakage on upgrade.
MixedModels.jl sets up the bounds to be as constrained as possible:
I am getting same NLopt error using MixedModels version “4.8.0”.
The same functionality was working fine till last month and I did not made any upgrades ? Even if any upgrade is necessary, it should not break backward compatibility of existing versions.
Without more information, it’s really hard to tell what’s going on. Can you share, even privately, the code + data that leads to this error?
PFA code which you can use to replicate the error.
using Pkg;
Pkg.add(Pkg.PackageSpec(name="MixedModels", version="4.30.0"));
Pkg.add(Pkg.PackageSpec(name="StatsModels", version="0.7.4"));
Pkg.add(Pkg.PackageSpec(name="DataFrames", version="1.7.0"));
Pkg.status();
using MixedModels
using StatsModels
using DataFrames
# Example data
df = DataFrame(
y = [3.1, 2.9, 3.5, 4.2, 3.0],
x1 = [1, 2, 1, 2, 1],
x2 = [0.5, 0.5, 0.5, 0.5, 0.5],
group = ["A", "A", "B", "B", "A"]
)
# Fit a linear mixed model with fixed effects for x1 and x2, and a random intercept for 'group'
model = fit(LinearMixedModel, @formula(y ~ x1 + x2 + (1|group)), df)
# Print the model results
println(model)
I don’t get an error from this call to fit(MixedModel,
but I do get a warning about a rank-deficient model matrix for the fixed effects.
┌ Warning: Fixed-effects matrix is rank deficient
└ @ MixedModels ~/.julia/packages/MixedModels/FUijl/src/Xymat.jl:41
Linear mixed model fit by maximum likelihood
y ~ 1 + x1 + x2 + (1 | group)
logLik -2 logLik AIC AICc BIC
-2.2089 4.4179 12.4179 Inf 10.8556
Variance components:
Column Variance Std.Dev.
group (Intercept) 0.134369 0.366564
Residual 0.070780 0.266046
Number of obs: 5; levels of grouping factors: 2
Fixed-effects parameters:
────────────────────────────────────────────────────
Coef. Std. Error z Pr(>|z|)
────────────────────────────────────────────────────
(Intercept) 3.07144 0.449942 6.83 <1e-11
x1 0.239281 0.24568 0.97 0.3301
x2 -0.0 NaN NaN NaN
────────────────────────────────────────────────────
This is with
julia> versioninfo()
Julia Version 1.11.3
Commit d63adeda50d (2025-01-21 19:42 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: macOS (arm64-apple-darwin24.0.0)
CPU: 8 × Apple M1 Pro
WORD_SIZE: 64
LLVM: libLLVM-16.0.6 (ORCJIT, apple-m1)
Threads: 1 default, 0 interactive, 1 GC (on 6 virtual cores)
Environment:
JULIA_EDITOR = code
JULIA_NUM_THREADS =
and version 4.30.0 of MixedModels
Same here, though the rank deficiency is expected given that x2
is constant.
Has the change in behavior (i.e. the recent failures) happened at the same time as a change in computer – hardware, operating system, etc.?
I got the solution. Upgrading StatsModels julia package from version 0.6.28 to 0.7.4 worked for me.
Thank you for your suggestions and help