Get columns of DataFrames.jl ModelMatrix object

Is there a way to extract column names of an object created from ModelMatrix() so that I can use those columns as row names for coefficients?
Thanks.

This isn’t standard Julia. Is this part of some package?

Actually, I am writing a Julia function for a stat method in which I need to use ModelMatrix and would like to obtain the levels of the covariates from the ModelMatrix so I can use them to name the coefficients in the output.

Thanks.

Oh, you should’ve mentioned that this is a DataFrames.jl thing.

http://juliastats.github.io/DataFrames.jl/latest/man/formulas/#The-Formula,-ModelFrame-and-ModelMatrix-Types-1

Edited for clarity.

Oh sorry, yes I was referring to ModelMatrix in DataFrame.jl. I cannot obtain the column names from an object created from ModelMatrix(). Any idea?
Thanks.
So

You don’t have access to the names at the ModelMatrix stage. You’d need the ModelFrame for that.

Thanks. Would ModelFrame give me columns by creating dummy indicators of levels of factor variables? Thanks,

No that is what ModelMatrix does but from a mf::ModelFrame you can get the ModelMatrix with ModelMatrix(mf) and the column names with coefnames(mf).

@andreasnoack @ChrisRackauckas : Below is an example of the same problem addressed in R language. Notice how levels (1s) of factor variables are attached to the column variables am and vs. I would like to do the same in Julia so that I can access the names (columns) from design matrix. Thanks.

> table(df)
   vs
am  0 1
  0 2 5
  1 2 1

> model.matrix(~., df)
   (Intercept) am1 vs1
1            1   1   0
2            1   1   0
3            1   1   1
4            1   0   1
5            1   0   0
6            1   0   1
7            1   0   0
8            1   0   1
9            1   0   1
10           1   0   1
attr(,"assign")
[1] 0 1 2
attr(,"contrasts")
attr(,"contrasts")$am
[1] "contr.treatment"

attr(,"contrasts")$vs
[1] "contr.treatment"

@andreasnoack: Thanks a lot. That’s what I wanted.

@andreasnoack: Is there any way to boost the speed of Pkg.add() or using packages? These are too slow. Thanks.

Not really at this point but it might get better soon. See https://github.com/JuliaLang/Juleps/blob/master/Pkg3.md though it is not certain when it will arrive.

12 posts were split to a new topic: How to start writing a new Julia package?

Is that a 1.0 feature?

A post was merged into an existing topic: How to start writing a new Julia package?