palday / JellyMe4.jl

RCall support for MixedModels.jl and lme4
MIT License
12 stars 2 forks source link

Issues with @rput #68

Closed Reulguen closed 10 months ago

Reulguen commented 10 months ago

Hi,

I have been running my statistical model the first time in Julia and want to save my model in order to load it into R for further plotting etc. However, I have issues when it comes to use @rput.

This is my code:

fit_uV =  @formula uV ~ (saggitality + laterality + condition + mention + bepoch) +
                                    (1 + condition + mention | subj) +
                                    (1 + mention | Report / text);

model_lme4 = fit(MixedModel, fit_uV, data)

model_for_r = (model_lme4, data);
@rput model_for_r

and this is the error message that I receive:

julia> @rput model_for_r
ERROR: type InteractionTerm has no field sym
Stacktrace:
 [1] convert_julia_to_r(f::StatsModels.FormulaTerm{StatsModels.ContinuousTerm{Float64}, Tuple{StatsModels.MatrixTerm{Tuple{StatsModels.InterceptTerm{true}, StatsModels.CategoricalTerm{DummyCoding, Matrix{Float64}, 2}, StatsModels.CategoricalTerm{DummyCoding, Matrix{Float64}, 2}, StatsModels.CategoricalTerm{DummyCoding, Matrix{Float64}, 1}, StatsModels.CategoricalTerm{DummyCoding, Matrix{Float64}, 4}, StatsModels.ContinuousTerm{Float64}}}, RandomEffectsTerm, RandomEffectsTerm, RandomEffectsTerm}})
   @ JellyMe4 ~/.julia/packages/JellyMe4/PqjLf/src/formula.jl:0
 [2] sexp(#unused#::Type{RCall.RClass{:lmerMod}}, x::Tuple{LinearMixedModel{Float64}, DataFrame})
   @ JellyMe4 ~/.julia/packages/JellyMe4/PqjLf/src/lmerMod.jl:93
 [3] sexp
   @ ~/.julia/packages/RCall/gOwEW/src/convert/default.jl:0 [inlined]
 [4] setindex!(e::Ptr{EnvSxp}, v::Tuple{LinearMixedModel{Float64}, DataFrame}, s::Symbol)
   @ RCall ~/.julia/packages/RCall/gOwEW/src/methods.jl:553
 [5] setindex!(e::RObject{EnvSxp}, v::Tuple{LinearMixedModel{Float64}, DataFrame}, s::Symbol)
   @ RCall ~/.julia/packages/RCall/gOwEW/src/methods.jl:562
 [6] top-level scope
   @ REPL[62]:1

Would be very grateful for any tips :)

Reulguen commented 10 months ago

I figured that the expression ( Report / text) is the issue. Is there a way of avoiding the lack of field sym.?

palday commented 10 months ago

I think the #71 will fix this. Can you install that branch and test it out? You can install a branch with:

# right bracket to enter package mode
julia> ]

pkg> add JellyMe4#pa/nested_grouping

If it works, then you can go back to the main release series with


pkg> free JellyMe4

(I'll tag a release as soon as that PR is merged.)

palday commented 10 months ago

I've merged that PR. The release should be out within the hour.

Reulguen commented 10 months ago

Thank you very much for taking care and also for your support.