R's update(Update and Re-fit a Model) in Julia?

118 views
Skip to first unread message

Hongwei Liu

unread,
Nov 14, 2016, 5:36:43 PM11/14/16
to julia-users
Hi guys,

I am new to Julia and I have trouble in finding a similar function in Julia that has the ability of "update" in R.

For example, set formula = y ~ x1 + x2

In R, I can use update(formula, D  ~ . ) to change the formula from y ~ x1 + x2 to D ~ x1 + x2

In Julia, the formula's type is DataFrames.Formula and I have searched online and Dataframes document for a long time but still couldn't find the answer.

So my question is:

Is there are such a function in Julia? If not, is there a way to modify a formula directly?

Thanks a lot!!

Hongwei

Milan Bouchet-Valat

unread,
Nov 15, 2016, 1:32:36 PM11/15/16
to julia...@googlegroups.com
I don't think we provide such a function yet, but you can easily do
that manually.

Use dump() to see what the formula object consists in:
julia> dump(y ~ x1 + x2)
DataFrames.Formula
  lhs: Symbol y
  rhs: Expr
    head: Symbol call
    args: Array{Any}((3,))
      1: Symbol +
      2: Symbol x1
      3: Symbol x2
    typ: Any

Here, you can just change the rhs (right hand side) argument:
julia> f = y ~ x1 + x2
Formula: y ~ x1 + x2

julia> f.lhs = :D
:D

julia> f
Formula: D ~ x1 + x2


Regards

> Thanks a lot!!
>
> Hongwei

Hongwei

unread,
Nov 16, 2016, 11:11:17 PM11/16/16
to julia-users
Thanks a million, Milan!!!

Hongwei
Reply all
Reply to author
Forward
0 new messages